'+this.opt.steps[i]+''+this.opt.description[i]+'
').addClass('')}else{var _s=$(stepDisc).html(''+this.opt.steps[i]+''+this.opt.description[i]+'
')}
stepsHtml.append(_s);}
stepsHtml.find('li').css('width','40px').css('marginRight',w_li*2-40)
stepContainer.append(stepsHtml).append(stepP);stepContainer.css('left',(w_con-stepP.width()-this.opt.imgWidth-10-this.opt.stepContainerMar*2)/2)
stepContainer.css('height',stepsHtml.height()-25);this.content.css('overflow','hidden')
this.setProgress(this.stepContainer,this.opt.curStep,this.opt.stepCounts)
if(this.opt.showBtn){this.content.append(stepButtonHtml)
this.prevBtn=this.content.find(this.opt.prevBtn)
this.nextBtn=this.content.find(this.opt.nextBtn)
this.prevBtn.on('click',function(){if($(_that).attr('disabled')||_that.opt.animating){return false;}else{_that.opt.animating=true;_that.opt.curStep--;_that.setProgress(_that.stepContainer,_that.opt.curStep,_that.opt.stepCounts)}})
this.nextBtn.on('click',function(){if($(_that).attr('disabled')||_that.opt.animating){return false;}else{_that.opt.animating=true;_that.opt.curStep++;_that.setProgress(_that.stepContainer,_that.opt.curStep,_that.opt.stepCounts)}})}
if(this.opt.clickAble){stepsHtml.find('li').on('click',function(){_that.opt.curStep=$(this).index()+1;_that.setProgress(_that.stepContainer,_that.opt.curStep,_that.opt.stepCounts)})}
$(window).resize(function(){var w_con=$(_that.content).width();var w_li=w_con/_that.opt.stepCounts/2;stepP.css('width',w_li*2*(_that.opt.stepCounts-1));stepP.find('.ystep-progress-bar').css('width',w_li*2*(_that.opt.stepCounts-1))
stepsHtml.find('li').css('width','40px').css('marginRight',w_li*2-40)
stepContainer.css('left',(w_con-stepP.width()-_that.opt.imgWidth-10-_that.opt.stepContainerMar*2)/2)})}
SetStep.prototype.initY=function(arg){var _that=this;extend(this.opt,arg);this.opt.stepCounts=this.opt.steps.length;this.content=$(this.opt.content);this.pageCont=this.content.find(this.opt.pageCont);var w_con=$(this.content).width();var h_con=$(this.content).height();console.log(h_con,w_con)
var w_li=(w_con-this.opt.stepContainerMar*2)/this.opt.stepCounts/2-60;var h_li=(h_con-this.opt.stepContainerMar*2)/this.opt.stepCounts/2;var stepContainer=this.content.find('.ystep-container');this.stepContainer=stepContainer;var stepsHtml=$("");var stepDisc="";var stepP=$("");var stepButtonHtml=$(""+
"
");stepP.css('height',w_li*2*(this.opt.stepCounts-1));stepP.find('.ystep-progress-bar').css('height',w_li*2*(this.opt.stepCounts-1))
for(var i=0;i'+this.opt.steps[i]+''+this.opt.description[i]+'
').addClass('')}else{var _s=$(stepDisc).html(''+this.opt.steps[i]+''+this.opt.description[i]+'
')}
stepsHtml.append(_s);}
stepsHtml.find('li').css('height','40px').css('marginBottom',w_li*2-40)
stepContainer.append(stepsHtml).append(stepP);stepContainer.css('height',stepsHtml.height()-25);this.setProgressY(this.stepContainer,this.opt.curStep,this.opt.stepCounts)
if(this.opt.showBtn){this.content.append(stepButtonHtml)
this.prevBtn=this.content.find(this.opt.prevBtn)
this.nextBtn=this.content.find(this.opt.nextBtn)
this.prevBtn.on('click',function(){if($(_that).attr('disabled')||_that.opt.animating){return false;}else{_that.opt.animating=true;_that.opt.curStep--;_that.setProgressY(_that.stepContainer,_that.opt.curStep,_that.opt.stepCounts)}})
this.nextBtn.on('click',function(){if($(_that).attr('disabled')||_that.opt.animating){return false;}else{_that.opt.animating=true;_that.opt.curStep++;_that.setProgressY(_that.stepContainer,_that.opt.curStep,_that.opt.stepCounts)}})}
if(this.opt.clickAble){stepsHtml.find('li').on('click',function(){_that.opt.curStep=$(this).index()+1;_that.setProgressY(_that.stepContainer,_that.opt.curStep,_that.opt.stepCounts)})}}
SetStep.prototype.setProgressY=function(n,curIndex,stepsLen){var _that=this;var $steps=$(n).find("li");var $progress=$(n).find(".ystep-progress-highlight");if(1<=curIndex&&curIndex<=$steps.length){var scale="%";scale=Math.round((curIndex-1)*100/($steps.length-1))+scale;$progress.animate({height:scale},{speed:1000,done:function(){$steps.each(function(j,m){var _$m=$(m);var _j=j+1;if(_jcurIndex){_$m.attr("class","ystep-step-undone");}})
if(_that.opt.showBtn){if(curIndex==1){_that.prevBtn.attr('disabled','true')
_that.nextBtn.removeAttr('disabled')}else if(curIndex==stepsLen){_that.prevBtn.removeAttr('disabled')
_that.nextBtn.attr('disabled','true')}else if(1curIndex){_$m.attr("class","ystep-step-undone");}})
if(_that.opt.showBtn){if(curIndex==1){_that.prevBtn.attr('disabled','true')
_that.nextBtn.removeAttr('disabled')}else if(curIndex==stepsLen){_that.prevBtn.removeAttr('disabled')
_that.nextBtn.attr('disabled','true')}else if(1 0)
itemsAmount = $.map(this.BuyedItems, o => o.SubTotal).reduce((pre, cur) => pre + cur);
var extrasAmount = 0;
var extras = this.BuyedExtras.filter((idx, el) => el.IsInClude === false);
if (extras.length > 0)
extrasAmount = $.map(extras, o => o.SubTotal).reduce((pre, cur) => pre + cur);
var total = itemsAmount + extrasAmount;
this.Result.Group.TotalAmount = total;
return total;
},
// 產品title的div內容 團名+全程說明
ProductTitleHtml: function () {
return this.Result.Group.Name + '' + (this.Result.Group.JoinAllExplain ? ('[' + this.Result.Group.JoinAllExplain + ']') : "" )+'';
},
// 大人數量
AdultCount: function () {
return this.AdultTotal;
},
// 小孩數量
ChildCount: function () {
return this.ChildTotal;
},
// 嬰兒數量
BabyCount: function () {
return this.BabyTotal;
},
// 總人數
TotalCount: function () {
return this.AdultCount + this.ChildCount + this.BabyCount;
},
// 總人數(Y艙)
YTotalCount: function () {
return this.TotalCount - this.EDTotalCount - this.CTotalCount - this.FTotalCount;
},
hasEDClass: function () {
return (this.Result.Group.Extras.find(extra => extra.ClassType === "ED") != null);
},
hasCClass: function () {
return (this.Result.Group.Extras.find(extra => extra.ClassType === "C") != null);
},
hasFClass: function () {
return (this.Result.Group.Extras.find(extra => extra.ClassType === "F") != null);
},
// 總人數(ED艙)
EDTotalCount: function () {
return this.hasEDClass ? this.Result.Group.Extras.find(extra => extra.ClassType === "ED").Count : 0;
},
// 總人數(C艙)
CTotalCount: function () {
return this.hasCClass ? this.Result.Group.Extras.find(extra => extra.ClassType === "C").Count : 0;
},
// 總人數(F艙)
FTotalCount: function () {
return this.hasFClass ? this.Result.Group.Extras.find(extra => extra.ClassType === "F").Count : 0;
},
// ED艙加價
EDUnit: function () {
return this.hasEDClass ? this.Result.Group.Extras.find(extra => extra.ClassType === "ED").Unit : 0;
},
// C艙加價
CUnit: function () {
return this.hasCClass ? this.Result.Group.Extras.find(extra => extra.ClassType === "C").Unit : 0;
},
// F艙加價
FUnit: function () {
return this.hasFClass ? this.Result.Group.Extras.find(extra => extra.ClassType === "F").Unit : 0;
},
// 不包含嬰兒的人數
SeatCount: function () {
return this.AdultCount + this.ChildCount;
},
//可售人數(Y艙)
YAvailableCount: function () {
return this.Result.Group.YClassAvailableCount;
},
//可售人數(ED艙)
EDAvailableCount: function () {
return this.Result.Group.EDClassAvailableCount;
},
//可售人數(C艙)
CAvailableCount: function () {
return this.Result.Group.CClassAvailableCount;
},
//可售人數(F艙)
FAvailableCount: function () {
return this.Result.Group.FClassAvailableCount;
},
//報名狀態(2:候補/3:可報名)
SignUpStatus: function () {
if (this.Result.Group.SignUpStatus == 2 || (this.Result.Group.SignUpStatus == 3 && this.Result.Group.IsGroupConfirm == true))
return 2;
return this.Result.Group.SignUpStatus;
},
//顯示在畫面上的額外購買項目列表
ExtraList: function () {
var extraList = this.Result.Group.Extras.filter((extra) => (extra.Unit !== 0 && extra.Name !== "") || extra.IsPayFirst || extra.IsInClude || extra.IsMustBuy);
if (this.EDAvailableCount <= 0)
extraList = extraList.filter((extra) => extra.ClassType != "ED");
if (this.CAvailableCount <= 0)
extraList = extraList.filter((extra) => extra.ClassType != "C");
if (this.FAvailableCount <= 0)
extraList = extraList.filter((extra) => extra.ClassType != "F");
return extraList;
},
// 購買的項目
BuyedItems: function () {
return $(this.Result.Group.Items).filter((index, element) => Number(element.Count) > 0);
},
// 購買的額外項目
BuyedExtras: function () {
return $(this.Result.Group.Extras).filter((index, element) => Number(element.Count) > 0);
},
////國內/國外旅遊契約書URL
//TravelContractUrl: function () {
// return this.Result.Group.IsForeign ? this.Result.ForeignTravelContractUrl : this.Result.InternalTravelContractUrl;
//},
//國內/國外旅遊契約書
TravelContract: function () {
return this.Result.Group.IsForeign ? this.Result.ForeignTravelContract : this.Result.InternalTravelContract;
},
//更新訂購人資訊
UpdateOrderer: function () {
this.Result.Orderer.Mobile = $('.subscriber_info_content [data-rel="mobile"]').val();
this.Result.Orderer.Email = $('.subscriber_info_content [data-rel="email"]').val();
this.Result.Orderer.Name = $('.subscriber_info_content [data-rel="name"]').val();
this.CutName;
},
//分割名字
CutName: function () {
var eventName = this.Result.Orderer.Name;
if (eventName.indexOf(' ') >= 0) {
this.Result.Orderer.LastName = eventName.substring(0, eventName.indexOf(' '));
this.Result.Orderer.FirstName = eventName.substring(eventName.indexOf(' '));
} else {
this.Result.Orderer.LastName = eventName.substring(0, 1);
this.Result.Orderer.FirstName = eventName.substring(1);
}
},
//能否從step1 to step2
CanNextStep: function () {
return this.CanNext;
}
},
//監控項目, 重新判斷是否能到下一步
watch: {
checkCanNextStep: function () {
if (!this.checkCanNextStep == false) {
this.ExeCheckCanNextStep();
}
},
IsAgreeContract: function () {
this.ExeCheckCanNextStep();
},
AdultCount: function () {
this.ExeCheckCanNextStep();
}
},
mounted: function () {
let self = this;
window.mobile_checker.addEventListener(window.mobile_checker.Events.MobileVerify, function (event) {
self.CheckValidate();
});
window.mobile_checker.addEventListener(window.mobile_checker.Events.NameChange, function (event) {
var eventName = $.trim(event.detail.value);
self.Result.Orderer.Name = eventName;
//2022-02-23: [Jacky][PMK103306] - 點"同訂購人"才會帶入
self.CutName;
self.CheckValidate();
});
window.mobile_checker.addEventListener(window.mobile_checker.Events.EmailChange, function (event) {
self.Result.Orderer.Email = event.detail.value;
self.CheckValidate();
});
window.mobile_checker.addEventListener(window.mobile_checker.Events.MobileChange, function (event) {
self.Result.Orderer.Mobile = event.detail.value;
self.CheckValidate();
});
},
methods: {
// 訂購人欄位驗證
CheckValidate: function () {
this.CheckName();
this.CheckEmail();
this.CheckMobile();
this.IsValidate = (window.mobile_checker.isVerified());
},
CheckName: function () {
if (!this.Result.Orderer.Name)
this.NameValidate = false;
else
this.NameValidate = true;
},
CheckEmail: function () {
if (!this.Result.Orderer.Email)
this.EmailValidate = false;
else
this.EmailValidate = true;
},
CheckMobile: function () {
if (!this.Result.Orderer.Mobile)
this.MobileValidate = false;
else
this.MobileValidate = true;
},
// 金額格式化
CurrentStr: function (value) {
return this.Result.ShowPriceFormat.replace('{Price}', Number(value.toFixed(1)).toLocaleString());
},
// 計算主項目的小計
CalcItemSubTotal: function (index) {
this.Result.Group.Items[index].SubTotal = this.Result.Group.Items[index].Unit * GetListCount(index);
},
// 計算額外項目的小計
CalcExtraSubTotal: function (index) {
this.ExtraList[index].SubTotal = this.ExtraList[index].Unit * this.ExtraList[index].Count;
},
// 當變更參團人數時,必買和包含在團費裡的附加項目數量也須更改
ChangeItemCount: function () {
for (var extra of this.ExtraList) {
if (extra.IsMustBuy || extra.IsInClude) {
if (extra.Type === "1") {
extra.Count = this.AdultCount;
} else if (extra.Type === "2") {
extra.Count = this.ChildCount;
} else {
extra.Count = this.TotalCount;
}
}
//數量異常修正(選購數量大於對應類型數量)
if (extra.Type === "1" && extra.Count > this.AdultCount) {
extra.Count = this.AdultCount;
} else if (extra.Type === "2" && extra.Count > this.ChildCount) {
extra.Count = this.ChildCount;
} else if (extra.Count > this.TotalCount){
extra.Count = this.TotalCount;
}
this.CalcExtraSubTotal(this.ExtraList.indexOf(extra));
}
},
//檢查是否能夠到下一步驟, 切換按鈕圖示
ExeCheckCanNextStep: function () {
//使用者狀態異常(審核中、被關閉等等)
if (this.Result.UserStatusError)
return false;
//訂購狀態確認
if (!this.Result.Group.AllowSignUp)
return false;
var checkResult = this.IsAgreeContract && (window.mobile_checker.isVerified()) && this.BuyedItems.length > 0 && this.AdultCount >= 1;
if (checkResult) {
$("#nextButton").removeClass("l_benNoopen");
$("#nextButton").addClass("l_benPrimary");
this.CanNext = true;
} else {
$("#nextButton").removeClass("l_benPrimary");
$("#nextButton").addClass("l_benNoopen");
this.CanNext = false;
}
this.checkCanNextStep = false;
},
// 第一步送出至第二步
Check: function () {
if (!this.Result.Group.AllowSignUp) {
return false;
}
window.mobile_checker.setSubmitFlag(); // 點了確認訂購 [jacky]
this.CheckValidate();
if (!this.CanNextStep) {
if (!this.IsValidate) {
$(window).scrollTop(0);
} else if (!this.IsAgreeContract) {
alert('請閱讀並同意「訂購須知」、「旅遊契約書」、及「隱私權政策」。');
} else {
$(window).scrollTop(0);
}
return false;
}
else {
// 團控核准或引用團(不跳訊息)
/*if (this.Result.Group.SignUpStatus === 3 && (this.Result.Group.IsGroupConfirm || this.Result.Group.SAcctNo)) {
alert('此團將由專人為您再次確認機位狀態,請按[確定]進行報名流程。');
} else if (this.Result.Group.SignUpStatus === 2 || this.Result.Group.WaitingCount) {
alert('您好,本產品尚有候補訂單未確認,您的訂單將成為候補訂單,暫不需付款!\n確認訂單後,客服人員將盡快與您聯繫!');
} else if (this.YTotalCount > this.YAvailableCount || this.EDTotalCount > this.EDAvailableCount || this.CTotalCount > this.CAvailableCount || this.FTotalCount > this.FAvailableCount) {
alert('您好,訂購人數超過可售機位,您的訂單將成為候補訂單,暫不需付款!\n確認訂單後,客服人員將盡快與您聯繫!');
}*/
CreatBuyedItems(this);
this.UpdateOrderer;
SumbitForm(this.Result);
}
},
// 更改步驟
ClickStepButton: function (obj) {
var newStep = $(obj).index() + 1;
// 只能往前更改步驟,若已完成訂單則不可更改
if (newStep < this.step.opt.curStep && this.step.opt.curStep !== this.step.opt.stepCounts) {
this.ChangeStep(newStep);
}
},
// 變更步驟
ChangeStep: function (newStep) {
this.step.opt.animating = true;
this.step.opt.curStep = newStep;
this.step.setProgress(this.step.stepContainer, this.step.opt.curStep, this.step.opt.stepCounts);
},
// 立即付款
PayNow: function () {
this.Result.IsPayFirst = true;
this.Submit();
},
// 送出訂單
Submit: function () {
var vm = this;
var data = this.Result;
delete data.PrivacyPolicy;
delete data.OrderNotice;
delete data.ForeignTravelContract;
delete data.InternalTravelContract;
$.post($(this.$el).data('submitUrl'), data, function (data) {
vm.Redirect(data);
});
},
// 完成後導頁
Redirect: function (data) {
var redirectUrl = "";
if (data.Success) {
redirectUrl = $(this.$el).data('finishUrl') + '/' + data.Order.ID;
if (data.PayUrl) {
redirectUrl = data.PayUrl;
}
if (this.Result.IsVender && this.Result.IsSyncVender) {
window.location.href = $(this.$el).data('redirectUrl') + '?redirect_url=' + redirectUrl;
}
else {
window.location.href = redirectUrl;
}
}
else {
window.location.href = $(this.$el).data('failUrl') + '?errorcode=' + data.Type;
}
}
},
updated: function () {
if (this.YTotalCount === 0) return;
}
});
next(app);
}
//檢查這團會不會是候補團,會的話alert訊息
function CheckStandBy(vm) {
if (vm.Result.AlertSubstituteMsg) // 是否要提示為候補團
{
alert('此團將由專人為您再次確認機位狀態,請按[確定]進行報名流程。');
vm.IsAlerted = true;
}
}
//當使用者驗證或登入時觸發
function BindUserStatusChange(vm) {
//驗證/登入時觸發事件
$('input[id$="IsMobileVerification"]').change(function (e) {
$('[data-rel="travel_contract"]').trigger('setContract');
});
}
function BindChangeCount(vm) {
$('.select-num .select-btn').click(function (e) {
/* Act on the event */
e.preventDefault();
// 未完成驗證不可更改訂購數量
//vm.CheckValidate();//如果vm.isVerified 需要執行過vm.CheckValidate()
//if (!vm.isVerified) return;
var isItem = $(this).parents('[data-rel="group-item"]').length > 0;
var index = isItem ?
$('[data-rel="group-item"]').index($(this).parents('[data-rel="group-item"]'))
: $('[data-rel="group-extra"] .select-num').index($(this).parents('.select-num'));
var total = 0;
var allTotalCount = 0;
var count = $(this).data('count');
var classTp = $(this).data('ctype');
total = parseInt($(this).parents('.select-num').find('.num').html());
if (count === 'minus') {
total === 0 ? total = total : total--;
} else {
total++;
allTotalCount = vm.YTotalCount + 1;
}
if (isItem) {
//做人數上限判斷
if (count === 'add') {
if (!CheckClassCount(vm, total, classTp)) {
total--;
}
}
//填入各艙等數量
AddClassCont(vm, total, classTp, index);
//人數統計
CountEveryTotal(vm);
vm.ChangeItemCount();
vm.CalcItemSubTotal(index);
} else {
// 額外項目數量上限限制
switch (vm.ExtraList[index].Type) {
//大人
case "1":
total = total > vm.AdultCount ? vm.AdultCount : total;
break;
//小孩
case "2":
total = total > vm.ChildCount ? vm.ChildCount : total;
break;
//不限
default:
total = total > vm.TotalCount ? vm.TotalCount : total;
break;
}
vm.ExtraList[index].Count = total;
vm.CalcExtraSubTotal(index);
}
CheckAllAddBtnStatus(vm);
});
}
//重計各類人數
function CountEveryTotal(vm) {
var childTotal = 0;
var babyTotal = 0;
var adultTotal = 0;
for (var Item of vm.Result.Group.Items) {
if (Item.Type == "2" || Item.Type == "3")
childTotal += GetListCount(vm.Result.Group.Items.indexOf(Item));
else if (Item.Type == "5")
babyTotal += GetListCount(vm.Result.Group.Items.indexOf(Item));
else
adultTotal += GetListCount(vm.Result.Group.Items.indexOf(Item));
}
vm.BabyTotal = babyTotal;
vm.ChildTotal = childTotal;
vm.AdultTotal = adultTotal;
}
//取得該列數量
function GetListCount(index) {
var total = 0;
$('[data-rel="group-item"]:eq(' + index + ') .num').each(function () {
total += parseInt($(this).html());
});
return total;
}
//填入各艙等數量
function AddClassCont(vm, num, tp, index) {
$('[data-rel="group-item"]:eq(' + index + ') div[name="' + tp + 'Count"]').html(num);
vm.Result.Group.Items[index].Count = GetListCount(index);
if (tp != "Y") {
var total = 0;
$('div[name="' + tp + 'Count"]').each(function () {
total += parseInt($(this).html());
});
vm.Result.Group.Extras.find(extra => extra.ClassType == tp).Count = total;
}
}
//檢查各艙等數量
function CheckClassCount(vm, num, tp) {
var returnValue = true;
var classTotalCount = 1;
var classAvailableCount = 0;
switch (tp) {
case "Y":
classTotalCount += vm.YTotalCount;
classAvailableCount = vm.YAvailableCount;
break;
case "ED":
classTotalCount += vm.EDTotalCount;
classAvailableCount = vm.EDAvailableCount;
break;
case "C":
classTotalCount += vm.CTotalCount;
classAvailableCount = vm.CAvailableCount;
break;
case "F":
classTotalCount += vm.FTotalCount;
classAvailableCount = vm.FAvailableCount;
break;
}
//每項人數最多可以超過可售+10人
if (num > (classAvailableCount + 10)) {
returnValue = false;
} else if (!vm.IsAlerted && classTotalCount > classAvailableCount) {
alert("注意!!訂購人數超過可售機位,您的訂單將成為候補訂單。")
vm.IsAlerted = true;
}
//單筆訂單超過99人的話中台就會錯誤
if (vm.TotalCount+1 > 99) {
returnValue = false;
alert("請勿超過單筆訂單最高上限人數99位。")
}
return returnValue;
}
//檢查所有的+按鈕狀態
function CheckAllAddBtnStatus(vm) {
//訂購內容"+"按鈕狀態確認
$('[data-rel="group-item"] [data-count="add"]').each(function () {
var idx = $('[data-rel="group-item"]').index($(this).parents('[data-rel="group-item"]'));
var classTp = $(this).data('ctype');
var classCount = 0;
var classAvailableCount = 0;
if (classTp === "Y") {
classCount = vm.Result.Group.Items[idx].Count;
} else {
classCount = parseInt($(this).parents('.select-num').find('.num').html());
}
switch (classTp) {
case "Y":
classAvailableCount = vm.YAvailableCount;
break;
case "ED":
classAvailableCount = vm.EDAvailableCount;
break;
case "C":
classAvailableCount = vm.CAvailableCount;
break;
case "F":
classAvailableCount = vm.FAvailableCount;
break;
}
if (classCount >= classAvailableCount + 10 || vm.TotalCount >= 99)
$(this).addClass('select-btn-full');
else
$(this).removeClass('select-btn-full');
});
//加購項目"+"按鈕狀態確認
$('[data-rel="group-extra"] [data-count="add"]').each(function () {
// 額外項目數量上限限制
var idx = $('[data-rel="group-extra"] .select-num').index($(this).parents('.select-num'));
switch (vm.ExtraList[idx].Type) {
//大人
case "1":
if (vm.ExtraList[idx].Count >= vm.AdultCount)
$(this).addClass('select-btn-full');
else
$(this).removeClass('select-btn-full');
break;
//小孩
case "2":
if (vm.ExtraList[idx].Count >= vm.ChildCount)
$(this).addClass('select-btn-full');
else
$(this).removeClass('select-btn-full');
break;
//不限
default:
if (vm.ExtraList[idx].Count >= vm.TotalCount)
$(this).addClass('select-btn-full');
else
$(this).removeClass('select-btn-full');
break;
}
});
}
//由Items建立BuyedItems
function CreatBuyedItems(vm) {
var index = 0;
var newCount = 0;
for (var item of vm.Result.Group.Items) {
if (item.Count > 0) {
newCount = $('[data-rel="group-item"]:eq(' + vm.Result.Group.Items.indexOf(item) + ') div[name="YCount"]').html();
if (newCount > 0) {
vm.Result.Group.BuyedItems[index] = {
Count: newCount,
JoinType: item.JoinType,
Name: item.Name,
PriceLevel: item.PriceLevel,
SubTotal: newCount * item.Unit,
Type: item.Type,
Unit: item.Unit,
ClassType: "Y"
};
index++;
}
var extrasObj = vm.Result.Group.Extras.filter(extra => extra.ClassType === "ED" || extra.ClassType === "C" || extra.ClassType === "F");
var availableCount = 0;
for (var extra of extrasObj) {
switch (extra.ClassType) {
case "ED":
availableCount = vm.Result.Group.EDClassAvailableCount;
break;
case "C":
availableCount = vm.Result.Group.CClassAvailableCount;
break;
case "F":
availableCount = vm.Result.Group.FClassAvailableCount;
break;
}
if (availableCount > 0) {
newCount = $('[data-rel="group-item"]:eq(' + vm.Result.Group.Items.indexOf(item) + ') div[name="' + extra.ClassType + 'Count"]').html();
if (newCount > 0) {
vm.Result.Group.BuyedItems[index] = {
Count: newCount,
JoinType: item.JoinType,
Name: item.Name,
PriceLevel: item.PriceLevel,
SubTotal: newCount * (item.Unit + extra.Unit),
Type: item.Type,
Unit: item.Unit + extra.Unit,
ClassType: extra.ClassType
};
index++;
}
}
}
}
}
}
function SumbitForm(data) {
delete data.PrivacyPolicy;
delete data.OrderNotice;
delete data.ForeignTravelContract;
delete data.InternalTravelContract;
$('#frm').html('');
$('#frm').append(GetSubmitInput(data, []));
$('#frm').submit();
}
function GetSubmitInput(obj, res, prefix, isarray) {
Object.keys(obj).forEach(function (k) {
var name = prefix ? prefix + '.' + k : k;
if (isarray) {
name = prefix ? prefix + '[' + k + ']' : k;
}
if (typeof obj[k] == 'object') {
obj[k] && GetSubmitInput(obj[k], res, name, $.isArray(obj[k]));
}
else {
res.push('');
}
});
return res;
}
//取出內容不包含最外層html標籤
function getTextWithoutHtmlTag(str) {
return $('').html(str).text();
};
//<
//data-rel="travel_contract"
//data-action="url"
//data-name-id="#ContractName"
//data-contract-pdf-iframe-id="#ContractPDFIframe"
//data-contract-pdf-download-link-id="#ContractPDFDownloadName"
//>
$(document).ready(function () {
$(document).on("setContract", '[data-rel="travel_contract"]', function () {
var _data = $(this).data();
$.get(_data.action, function (data) {
if (!data.Error) {
$(_data.nameId).html(data.ContractName);
$(_data.contractPdfIframeId).prop('src', data.ContractPDFUrl);
$(_data.contractPdfDownloadLinkId).prop('href', data.ContractPDFUrl + '&download=true');
}
})
});
});;