diff --git a/css/images/flight/airArrowDirect.png b/css/images/flight/airArrowDirect.png new file mode 100644 index 0000000..ce408e3 Binary files /dev/null and b/css/images/flight/airArrowDirect.png differ diff --git a/css/images/flight/airArrowStop.png b/css/images/flight/airArrowStop.png new file mode 100644 index 0000000..9a588e6 Binary files /dev/null and b/css/images/flight/airArrowStop.png differ diff --git a/js/bootstrap3-typeahead.min.js b/js/bootstrap3-typeahead.min.js new file mode 100644 index 0000000..f184d08 --- /dev/null +++ b/js/bootstrap3-typeahead.min.js @@ -0,0 +1 @@ +!function(t,e){"use strict";"undefined"!=typeof module&&module.exports?module.exports=e(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],function(t){return e(t)}):e(t.jQuery)}(this,function(t){"use strict";var e=function(s,i){this.$element=t(s),this.options=t.extend({},e.defaults,i),this.matcher=this.options.matcher||this.matcher,this.sorter=this.options.sorter||this.sorter,this.select=this.options.select||this.select,this.autoSelect="boolean"!=typeof this.options.autoSelect||this.options.autoSelect,this.highlighter=this.options.highlighter||this.highlighter,this.render=this.options.render||this.render,this.updater=this.options.updater||this.updater,this.displayText=this.options.displayText||this.displayText,this.itemLink=this.options.itemLink||this.itemLink,this.itemTitle=this.options.itemTitle||this.itemTitle,this.followLinkOnSelect=this.options.followLinkOnSelect||this.followLinkOnSelect,this.source=this.options.source,this.delay=this.options.delay,this.theme=this.options.theme&&this.options.themes&&this.options.themes[this.options.theme]||e.defaults.themes[e.defaults.theme],this.$menu=t(this.options.menu||this.theme.menu),this.$appendTo=this.options.appendTo?t(this.options.appendTo):null,this.fitToElement="boolean"==typeof this.options.fitToElement&&this.options.fitToElement,this.shown=!1,this.listen(),this.showHintOnFocus=("boolean"==typeof this.options.showHintOnFocus||"all"===this.options.showHintOnFocus)&&this.options.showHintOnFocus,this.afterSelect=this.options.afterSelect,this.afterEmptySelect=this.options.afterEmptySelect,this.addItem=!1,this.value=this.$element.val()||this.$element.text(),this.keyPressed=!1,this.focused=this.$element.is(":focus"),this.changeInputOnSelect=this.options.changeInputOnSelect||this.changeInputOnSelect,this.changeInputOnMove=this.options.changeInputOnMove||this.changeInputOnMove,this.openLinkInNewTab=this.options.openLinkInNewTab||this.openLinkInNewTab,this.selectOnBlur=this.options.selectOnBlur||this.selectOnBlur,this.showCategoryHeader=this.options.showCategoryHeader||this.showCategoryHeader};e.prototype={constructor:e,setDefault:function(t){if(this.$element.data("active",t),this.autoSelect||t){var e=this.updater(t);e||(e=""),this.$element.val(this.displayText(e)||e).text(this.displayText(e)||e).change(),this.afterSelect(e)}return this.hide()},select:function(){var t=this.$menu.find(".active").data("value");if(this.$element.data("active",t),this.autoSelect||t){var e=this.updater(t);e||(e=""),this.changeInputOnSelect&&this.$element.val(this.displayText(e)||e).text(this.displayText(e)||e).change(),this.followLinkOnSelect&&this.itemLink(t)?(this.openLinkInNewTab?window.open(this.itemLink(t),"_blank"):document.location=this.itemLink(t),this.afterSelect(e)):this.followLinkOnSelect&&!this.itemLink(t)?this.afterEmptySelect(e):this.afterSelect(e)}else this.afterEmptySelect();return this.hide()},updater:function(t){return t},setSource:function(t){this.source=t},show:function(){var e,s=t.extend({},this.$element.position(),{height:this.$element[0].offsetHeight}),i="function"==typeof this.options.scrollHeight?this.options.scrollHeight.call():this.options.scrollHeight;if(this.shown?e=this.$menu:this.$appendTo?(e=this.$menu.appendTo(this.$appendTo),this.hasSameParent=this.$appendTo.is(this.$element.parent())):(e=this.$menu.insertAfter(this.$element),this.hasSameParent=!0),!this.hasSameParent){e.css("position","fixed");var o=this.$element.offset();s.top=o.top,s.left=o.left}var n=t(e).parent().hasClass("dropup")?"auto":s.top+s.height+i,h=t(e).hasClass("dropdown-menu-right")?"auto":s.left;return e.css({top:n,left:h}).show(),!0===this.options.fitToElement&&e.css("width",this.$element.outerWidth()+"px"),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},lookup:function(e){if(this.query=null!=e?e:this.$element.val(),this.query.length0?this.$element.data("active",e[0]):this.$element.data("active",null),"all"!=this.options.items&&(e=e.slice(0,this.options.items)),this.options.addItem&&e.push(this.options.addItem),this.render(e).show()):this.shown?this.hide():this},matcher:function(t){return~this.displayText(t).toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(t){for(var e,s=[],i=[],o=[];e=t.shift();){var n=this.displayText(e);n.toLowerCase().indexOf(this.query.toLowerCase())?~n.indexOf(this.query)?i.push(e):o.push(e):s.push(e)}return s.concat(i,o)},highlighter:function(t){var e=this.query;if(""===e)return t;var s,i=t.match(/(>)([^<]*)(<)/g),o=[],n=[];if(i&&i.length)for(s=0;s2&&o.push(i[s]);else(o=[]).push(t);e=e.replace(/[\(\)\/\.\*\+\?\[\]]/g,function(t){return"\\"+t});var h,a=new RegExp(e,"g");for(s=0;s0&&n.push(o[s]);for(s=0;s$&"));return t},render:function(e){var s=this,i=this,o=!1,n=[],h=s.options.separator;return t.each(e,function(t,s){t>0&&s[h]!==e[t-1][h]&&n.push({__type:"divider"}),this.showCategoryHeader&&(!s[h]||0!==t&&s[h]===e[t-1][h]||n.push({__type:"category",name:s[h]})),n.push(s)}),e=t(n).map(function(e,n){if("category"==(n.__type||!1))return t(s.options.headerHtml||s.theme.headerHtml).text(n.name)[0];if("divider"==(n.__type||!1))return t(s.options.headerDivider||s.theme.headerDivider)[0];var h=i.displayText(n);return(e=t(s.options.item||s.theme.item).data("value",n)).find(s.options.itemContentSelector||s.theme.itemContentSelector).addBack(s.options.itemContentSelector||s.theme.itemContentSelector).html(s.highlighter(h,n)),s.options.followLinkOnSelect&&e.find("a").attr("href",i.itemLink(n)),e.find("a").attr("title",i.itemTitle(n)),h==i.$element.val()&&(e.addClass("active"),i.$element.data("active",n),o=!0),e[0]}),this.autoSelect&&!o&&(e.filter(":not(.dropdown-header)").first().addClass("active"),this.$element.data("active",e.first().data("value"))),this.$menu.html(e),this},displayText:function(t){return void 0!==t&&void 0!==t.name?t.name:t},itemLink:function(t){return null},itemTitle:function(t){return null},next:function(e){var s=this.$menu.find(".active").removeClass("active").next();for(s.length||(s=t(this.$menu.find(t(this.options.item||this.theme.item).prop("tagName"))[0]));s.hasClass("divider")||s.hasClass("dropdown-header");)s=s.next();s.addClass("active");var i=this.updater(s.data("value"));this.changeInputOnMove&&this.$element.val(this.displayText(i)||i)},prev:function(e){var s=this.$menu.find(".active").removeClass("active").prev();for(s.length||(s=this.$menu.find(t(this.options.item||this.theme.item).prop("tagName")).last());s.hasClass("divider")||s.hasClass("dropdown-header");)s=s.prev();s.addClass("active");var i=this.updater(s.data("value"));this.changeInputOnMove&&this.$element.val(this.displayText(i)||i)},listen:function(){this.$element.on("focus.bootstrap3Typeahead",t.proxy(this.focus,this)).on("blur.bootstrap3Typeahead",t.proxy(this.blur,this)).on("keypress.bootstrap3Typeahead",t.proxy(this.keypress,this)).on("propertychange.bootstrap3Typeahead input.bootstrap3Typeahead",t.proxy(this.input,this)).on("keyup.bootstrap3Typeahead",t.proxy(this.keyup,this)),this.eventSupported("keydown")&&this.$element.on("keydown.bootstrap3Typeahead",t.proxy(this.keydown,this));var e=t(this.options.item||this.theme.item).prop("tagName");"ontouchstart"in document.documentElement?this.$menu.on("touchstart",e,t.proxy(this.touchstart,this)).on("touchend",e,t.proxy(this.click,this)):this.$menu.on("click",t.proxy(this.click,this)).on("mouseenter",e,t.proxy(this.mouseenter,this)).on("mouseleave",e,t.proxy(this.mouseleave,this)).on("mousedown",t.proxy(this.mousedown,this))},destroy:function(){this.$element.data("typeahead",null),this.$element.data("active",null),this.$element.unbind("focus.bootstrap3Typeahead").unbind("blur.bootstrap3Typeahead").unbind("keypress.bootstrap3Typeahead").unbind("propertychange.bootstrap3Typeahead input.bootstrap3Typeahead").unbind("keyup.bootstrap3Typeahead"),this.eventSupported("keydown")&&this.$element.unbind("keydown.bootstrap3-typeahead"),this.$menu.remove(),this.destroyed=!0},eventSupported:function(t){var e=t in this.$element;return e||(this.$element.setAttribute(t,"return;"),e="function"==typeof this.$element[t]),e},move:function(t){if(this.shown)switch(t.keyCode){case 9:case 13:case 27:t.preventDefault();break;case 38:if(t.shiftKey)return;t.preventDefault(),this.prev();break;case 40:if(t.shiftKey)return;t.preventDefault(),this.next()}},keydown:function(e){17!==e.keyCode&&(this.keyPressed=!0,this.suppressKeyPressRepeat=~t.inArray(e.keyCode,[40,38,9,13,27]),this.shown||40!=e.keyCode?this.move(e):this.lookup())},keypress:function(t){this.suppressKeyPressRepeat||this.move(t)},input:function(t){var e=this.$element.val()||this.$element.text();this.value!==e&&(this.value=e,this.lookup())},keyup:function(t){if(!this.destroyed)switch(t.keyCode){case 40:case 38:case 16:case 17:case 18:break;case 9:if(!this.shown||this.showHintOnFocus&&!this.keyPressed)return;this.select();break;case 13:if(!this.shown)return;this.select();break;case 27:if(!this.shown)return;this.hide()}},focus:function(t){this.focused||(this.focused=!0,this.keyPressed=!1,this.options.showHintOnFocus&&!0!==this.skipShowHintOnFocus&&("all"===this.options.showHintOnFocus?this.lookup(""):this.lookup())),this.skipShowHintOnFocus&&(this.skipShowHintOnFocus=!1)},blur:function(t){this.mousedover||this.mouseddown||!this.shown?this.mouseddown&&(this.skipShowHintOnFocus=!0,this.$element.focus(),this.mouseddown=!1):(this.selectOnBlur&&this.select(),this.hide(),this.focused=!1,this.keyPressed=!1)},click:function(t){t.preventDefault(),this.skipShowHintOnFocus=!0,this.select(),this.$element.focus(),this.hide()},mouseenter:function(e){this.mousedover=!0,this.$menu.find(".active").removeClass("active"),t(e.currentTarget).addClass("active")},mouseleave:function(t){this.mousedover=!1,!this.focused&&this.shown&&this.hide()},mousedown:function(t){this.mouseddown=!0,this.$menu.one("mouseup",function(t){this.mouseddown=!1}.bind(this))},touchstart:function(e){e.preventDefault(),this.$menu.find(".active").removeClass("active"),t(e.currentTarget).addClass("active")},touchend:function(t){t.preventDefault(),this.select(),this.$element.focus()}};var s=t.fn.typeahead;t.fn.typeahead=function(s){var i=arguments;return"string"==typeof s&&"getActive"==s?this.data("active"):this.each(function(){var o=t(this),n=o.data("typeahead"),h="object"==typeof s&&s;n||o.data("typeahead",n=new e(this,h)),"string"==typeof s&&n[s]&&(i.length>1?n[s].apply(n,Array.prototype.slice.call(i,1)):n[s]())})},e.defaults={source:[],items:8,minLength:1,scrollHeight:0,autoSelect:!0,afterSelect:t.noop,afterEmptySelect:t.noop,addItem:!1,followLinkOnSelect:!1,delay:0,separator:"category",changeInputOnSelect:!0,changeInputOnMove:!0,openLinkInNewTab:!1,selectOnBlur:!0,showCategoryHeader:!0,theme:"bootstrap3",themes:{bootstrap3:{menu:'',item:'
  • ',itemContentSelector:"a",headerHtml:'',headerDivider:''},bootstrap4:{menu:'',item:'',itemContentSelector:".dropdown-item",headerHtml:'',headerDivider:''}}},t.fn.typeahead.Constructor=e,t.fn.typeahead.noConflict=function(){return t.fn.typeahead=s,this},t(document).on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(e){var s=t(this);s.data("typeahead")||s.typeahead(s.data())})}); \ No newline at end of file diff --git a/js/flight/flight.book.js b/js/flight/flight.book.js new file mode 100644 index 0000000..fac714e --- /dev/null +++ b/js/flight/flight.book.js @@ -0,0 +1,293 @@ + +/** loader */ +function loaderOn() { + document.getElementById("loader").style.display = "block"; +} + +function loaderOff() { + document.getElementById("loader").style.display = "none"; +} +function readData() { + window.roundTrip = sessionStorage.getItem('roundTrip'); + window.isReturn = sessionStorage.getItem('isReturn'); + window.DepartFlightStr = sessionStorage.getItem('DepartFlightStr'); + window.DepartCabinStr = sessionStorage.getItem('DepartCabinStr'); + window.ArriveFlightStr = sessionStorage.getItem('ArriveFlightStr'); + window.ArriveCabinStr = sessionStorage.getItem('ArriveCabinStr'); + $('#roundTrip').val(roundTrip); + $('#isReturn').val(isReturn); + $('#DepartFlightStr').val(DepartFlightStr); + $('#DepartCabinStr').val(DepartCabinStr); + $('#ArriveFlightStr').val(ArriveFlightStr); + $('#ArriveCabinStr').val(ArriveCabinStr); + window.DepartFlightInfo = sessionStorage.getItem('DepartFlightInfo'); + window.DepartCabinInfo = sessionStorage.getItem('DepartCabinInfo'); + window.ArriveFlightInfo = sessionStorage.getItem('ArriveFlightInfo'); + window.ArriveCabinInfo = sessionStorage.getItem('ArriveCabinInfo'); + if (!DepartFlightInfo && !ArriveFlightInfo) { + return false; + } + if (DepartFlightInfo) { + DepartFlightInfo = JSON.parse(DepartFlightInfo); + DepartCabinInfo = JSON.parse(DepartCabinInfo); + let citys = DepartFlightInfo.departCityIataNameEn + " - " + DepartFlightInfo.arriveCityIataNameEn; + let iconSrc = "/china-flights/images/icon/" + DepartFlightInfo.airLineIcon + ".gif"; + $('#selected__one_airlineicon').attr('src', iconSrc); + $('#selected__one_airlineicon').attr('alt', DepartFlightInfo.showAirLineCompany); + $('#selected__one_airline').html(DepartFlightInfo.showAirLineCompany); + $('#selected__one_city').html(citys); + $('#selected__one_date').html(DepartFlightInfo.departDate); + $('#selected__one_arrdate').html(DepartFlightInfo.arriveDate); + $('#selected__one_cabinname').html(DepartCabinInfo.cabinClassNameEn.replace('Class', '')); + $('#selected__one_airline').html(DepartFlightInfo.showAirLineCompany); + $('#selected__one_flightinfo').html(DepartFlightInfo.flightNo + '/' + DepartFlightInfo.craftType); + $('#selected__one_detime').html(DepartFlightInfo.departTime); + $('#selected__one_arrtime').html(DepartFlightInfo.arriveTime); + $('#selected__one_fromairport').html(DepartFlightInfo.departAirportNameEn + '(' + DepartFlightInfo.departAirportTerminal + ')'); + $('#selected__one_toairport').html(DepartFlightInfo.arriveAirportNameEn + '(' + DepartFlightInfo.arriveAirportTerminal + ')'); + $('#selected__one_duration').html(DepartFlightInfo.duration); + let stopPic = '/images/airArrowDirect.png'; + if (parseInt(DepartFlightInfo.stopNum) > 0) { + stopPic = '/images/airArrowStop.png'; + let stopinfo = DepartFlightInfo.showStopCityName + "," + DepartFlightInfo.stoparrivalTime + "-" + DepartFlightInfo.stopdepartrueTime; + let stopinfoHtml = '' + DepartFlightInfo.stopCityCode + ''; + $('#selected__one_stopinfo').html(stopinfoHtml); + } + $('#selected__one_stoppic').attr('src', 'https://www.trainspread.com'+stopPic); + } + if (ArriveFlightInfo && roundTrip == 'true') { + ArriveFlightInfo = JSON.parse(ArriveFlightInfo); + ArriveCabinInfo = JSON.parse(ArriveCabinInfo); + let citys = ArriveFlightInfo.departCityIataNameEn + " - " + ArriveFlightInfo.arriveCityIataNameEn; + let iconSrc = "/china-flights/images/icon/" + ArriveFlightInfo.airLineIcon + ".gif"; + $('#selected__two_airlineicon').attr('src', iconSrc); + $('#selected__two_airlineicon').attr('alt', ArriveFlightInfo.showAirLineCompany); + $('#selected__two_airline').html(ArriveFlightInfo.showAirLineCompany); + $('#selected__two_city').html(citys); + $('#selected__two_date').html(ArriveFlightInfo.departDate); + $('#selected__two_arrdate').html(ArriveFlightInfo.arriveDate); + $('#selected__two_cabinname').html(ArriveCabinInfo.cabinClassNameEn.replace('Class', '')); + $('#selected__two_airline').html(ArriveFlightInfo.showAirLineCompany); + $('#selected__two_flightinfo').html(ArriveFlightInfo.flightNo + '/' + ArriveFlightInfo.craftType); + $('#selected__two_detime').html(ArriveFlightInfo.departTime); + $('#selected__two_arrtime').html(ArriveFlightInfo.arriveTime); + $('#selected__two_fromairport').html(ArriveFlightInfo.departAirportNameEn + '(' + ArriveFlightInfo.departAirportTerminal + ')'); + $('#selected__two_toairport').html(ArriveFlightInfo.arriveAirportNameEn + '(' + ArriveFlightInfo.arriveAirportTerminal + ')'); + $('#selected__two_duration').html(ArriveFlightInfo.duration); + let stopPic = '/images/airArrowDirect.png'; + if (parseInt(ArriveFlightInfo.stopNum) > 0) { + stopPic = '/images/airArrowStop.png'; + let stopinfo = ArriveFlightInfo.showStopCityName + "," + ArriveFlightInfo.stoparrivalTime + "-" + ArriveFlightInfo.stopdepartrueTime; + let stopinfoHtml = '' + ArriveFlightInfo.stopCityCode + ''; + $('#selected__two_stopinfo').html(stopinfoHtml); + } + $('#selected__two_stoppic').attr('src', 'https://www.trainspread.com'+stopPic); + $('#selected__two').removeClass('hidden'); + } +} + +function changePassenger(e) { + an = parseInt($("#adultNum").val()); + cn = parseInt($("#childNum").val() || 0); + bn = parseInt($("#babyNum").val() || 0); + + //票数 + var d_seats = a_seats = 99; + var d_seatStatus = DepartCabinInfo.seatStatus;//DepartCabinInfo.split('|')[7]; + if (d_seatStatus != ">9") { + d_seats = parseInt(d_seatStatus.replace(/>/, "")); + } + + if (roundTrip == "true") { + var a_seatStatus = ArriveCabinInfo.seatStatus; //ArriveCabinInfo.split('|')[7]; + if (a_seatStatus != ">9") { + a_seats = parseInt(a_seatStatus.replace(/>/, "")); + } + } + + var isLimit = false; + if ((an + cn) > d_seats) { + isLimit = true; + } else if (roundTrip == "true") { + if (an + cn > a_seatStatus) { + isLimit = true; + } + } + + if (isLimit) { + alert('There aren\'t enough ticket in the flight!'); + $(e).addClass("errSelect"); + return false; + } else { + $(e).removeClass("errSelect"); + } + + //------------- + for (var i = 1; i <= 15; i++) { + if (i <= an) { + if ($("#adultItem" + i).length < 1) { + $("#adultItem1").clone().attr("id", "adultItem" + i).appendTo($("#AdultTb")); + $("#adultItem" + i).find("input[name='guestName[]']").attr("id", "guestName" + i).val(""); + $("#adultItem" + i).find("input[name='guestpassport[]']").attr("id", "guestpassport" + i).val(""); + $("#adultItem" + i).find("input[name='birthday[]']").attr("id", "birthday" + i).val("") + $("#adultItem" + i).find("label.passengertype").html("Adult " + i); + $("#birthday" + i).flatpickr({ + dateFormat: "Y-m-d", + minDate: "1919-1-1", + maxDate: "today" + }); + } + } else { + $("#adultItem" + i).remove(); + } + + if (i <= cn) { + if ($("#childItem" + i).length < 1) { + $("#adultItem1").clone().attr("id", "childItem" + i).appendTo($("#ChildTb")); + $("#childItem" + i).find("input[name='guestName[]']").attr({ "id": "guestNameCHD" + i }).val(""); + $("#childItem" + i).find("input[name='guestpassport[]']").attr({ "id": "guestpassportCHD" + i }).val(""); + $("#childItem" + i).find("input[name='birthday[]']").attr({ "id": "birthdayCHD" + i }).val(""); + $("#childItem" + i).find("label.passengertype").html("Child " + i); + $("#birthdayCHD" + i).flatpickr({ + dateFormat: "Y-m-d", + minDate: "1919-1-1", + maxDate: "today" + }); + } + } else { + $("#childItem" + i).remove(); + } + + if (i <= bn) { + if ($("#babyItem" + i).length < 1) { + $("#adultItem1").clone().attr("id", "babyItem" + i).appendTo($("#BabyTb")); + $("#babyItem" + i).find("input[name='guestName[]']").attr({ "id": "guestNameBAB" + i }).val(""); + $("#babyItem" + i).find("input[name='guestpassport[]']").attr({ "id": "guestpassportBAB" + i }).val(""); + $("#babyItem" + i).find("input[name='birthday[]']").attr({ "id": "birthdayBAB" + i }).val(""); + $("#babyItem" + i).find("label.passengertype").html("Baby " + i); + $("#birthdayBAB" + i).flatpickr({ + dateFormat: "Y-m-d", + minDate: "1919-1-1", + maxDate: "today" + }); + + } + } else { + $("#babyItem" + i).remove(); + } + } + calPrice(); +} +function calPrice() { + let an = parseInt($("#adultNum").val()); + let cn = parseInt($("#childNum").val() || 0); + let bn = parseInt($("#babyNum").val() || 0); + var d_CarFree = parseFloat($("#cardfee").val()); + + var total_tiket = DepartCabinInfo.adultPrice * an + DepartCabinInfo.childPrice * cn + DepartCabinInfo.babyPrice * bn; + var total_tiket_usd = DepartCabinInfo.adultPrice_usd * an + DepartCabinInfo.childPrice_usd * cn + DepartCabinInfo.babyPrice_usd * bn; + var total_tax = DepartCabinInfo.adultTax * an + DepartCabinInfo.adultTax * cn; + var total_tax_usd = DepartCabinInfo.adultTax_usd * an + DepartCabinInfo.adultTax_usd * cn; + var total_sfree = DepartCabinInfo.serviceFeeAdult * an + DepartCabinInfo.serviceFeeAdult * cn + DepartCabinInfo.serviceFeeBaby * bn; + var total_sfree_usd = DepartCabinInfo.serviceFeeAdult_usd * an + DepartCabinInfo.serviceFeeAdult_usd * cn + DepartCabinInfo.serviceFeeBaby_usd * bn; + + var depart_totalprice = Math.ceil((total_tiket + total_tax + total_sfree) * (1 + d_CarFree)); + var depart_totalprice_usd = Math.ceil((total_tiket_usd + total_tax_usd + total_sfree_usd) * (1 + d_CarFree)); + + if (roundTrip == "true") { + var r_total_tiket = ArriveCabinInfo.adultPrice * an + ArriveCabinInfo.childPrice * cn + ArriveCabinInfo.babyPrice * bn; + var r_total_tiket_usd = ArriveCabinInfo.adultPrice_usd * an + ArriveCabinInfo.childPrice_usd * cn + ArriveCabinInfo.babyPrice_usd * bn; + var r_total_tax = ArriveCabinInfo.adultTax * an + ArriveCabinInfo.adultTax * cn; + var r_total_tax_usd = ArriveCabinInfo.adultTax_usd * an + ArriveCabinInfo.adultTax_usd * cn; + var r_total_sfree = ArriveCabinInfo.serviceFeeAdult * an + ArriveCabinInfo.serviceFeeAdult * cn + ArriveCabinInfo.serviceFeeBaby * bn; + var r_total_sfree_usd = ArriveCabinInfo.serviceFeeAdult_usd * an + ArriveCabinInfo.serviceFeeAdult_usd * cn + ArriveCabinInfo.serviceFeeBaby_usd * bn; + + total_tiket += r_total_tiket; + total_tiket_usd += r_total_tiket_usd; + total_tax += r_total_tax; + total_tax_usd += r_total_tax_usd; + total_sfree += r_total_sfree; + total_sfree_usd += r_total_sfree_usd; + + r_totalprice = Math.ceil((r_total_tiket + r_total_tax + r_total_sfree) * (1 + d_CarFree)); + r_totalprice_usd = Math.ceil((r_total_tiket_usd + r_total_tax_usd + r_total_sfree_usd) * (1 + d_CarFree)); + } + + var total_bankfree = Math.ceil((total_tiket + total_tax + total_sfree) * d_CarFree); + var total_bankfree_usd = Math.ceil((total_tiket_usd + total_tax_usd + total_sfree_usd) * d_CarFree); + var total_allprice = total_tiket + total_tax + total_sfree + total_bankfree; + var total_allprice_usd = total_tiket_usd + total_tax_usd + total_sfree_usd + total_bankfree_usd; + + if (cn > 0) { + $(".js_childbox").show(); + } else { + $(".js_childbox").hide(); + } + if (bn > 0) { + $(".js_babybox").show(); + } else { + $(".js_babybox").hide(); + } + + $("#js_audltprice").html(DepartCabinInfo.adultPrice_usd); + $("span.js_audltNum").html(an); + $("#js_childprice").html(DepartCabinInfo.childPrice_usd); + $("span.js_childNum").html(cn); + $("#js_audltTax").html(DepartCabinInfo.adultTax_usd); + $("#js_audltSFee").html(DepartCabinInfo.serviceFeeAdult_usd); + $("#js_childTax").html(DepartCabinInfo.adultTax_usd); + $("#js_ChildSFee").html(DepartCabinInfo.serviceFeeAdult_usd); + + $("span.js_babyNum").html(bn); + $("#js_babyprice").html(DepartCabinInfo.babyPrice_usd); + $("#js_BabySFee").html(DepartCabinInfo.serviceFreeBaby_usd); + //返程 + if (roundTrip == "true") { + $("#js_return").show(); + $("#js2_audltprice").html(ArriveCabinInfo.adultPrice_usd); + $("span.js2_audltNum").html(an); + $("#js2_childprice").html(ArriveCabinInfo.childPrice_usd); + $("span.js2_childNum").html(cn); + $("#js2_audltTax").html(ArriveCabinInfo.adultTax_usd); + $("#js2_audltSFee").html(ArriveCabinInfo.serviceFreeAdult_usd); + $("#js2_childTax").html(ArriveCabinInfo.adultTax_usd); + $("#js2_ChildSFee").html(ArriveCabinInfo.serviceFreeAdult_usd); + + $("span.js2_babyNum").html(bn); + $("#js2_babyprice").html(ArriveCabinInfo.babyPrice_usd); + $("#js2_BabySFee").html(ArriveCabinInfo.serviceFreeBaby_usd); + } else { + $("#js_return").hide(); + } + + $("#js_bankfree").html(total_bankfree_usd); + $("#js_allprice").html(total_allprice_usd); +} +function submitflight(e) { + e.preventDefault(); + loaderOn(); + let formData = new FormData(document.forms['reserveflight']); + console.log(Object.fromEntries(formData.entries())); + sessionStorage.removeItem('DepartFlightStr'); + sessionStorage.removeItem('DepartFlightInfo'); + sessionStorage.removeItem('DepartCabinStr'); + sessionStorage.removeItem('DepartCabinInfo'); + sessionStorage.removeItem('ArriveFlightStr'); + sessionStorage.removeItem('ArriveFlightInfo'); + sessionStorage.removeItem('ArriveCabinStr'); + sessionStorage.removeItem('ArriveCabinInfo'); + sessionStorage.removeItem('roundTrip'); + sessionStorage.removeItem('isReturn'); + return document.forms['reserveflight'].submit(); +} +(function ($) { + readData(); + $("#birthday1").flatpickr({ + dateFormat: "Y-m-d", + minDate: "1919-1-1", + maxDate: "today" + }); + changePassenger(); + document.forms['reserveflight'].addEventListener("submit", submitflight, true); + +})(window.jQuery) diff --git a/js/flight/flight.search.js b/js/flight/flight.search.js new file mode 100644 index 0000000..3a76e9e --- /dev/null +++ b/js/flight/flight.search.js @@ -0,0 +1,406 @@ +(function($) { + flatpickr("#takeoffDate1", { + dateFormat: "Y-m-d", + altInput: true, + altFormat: 'M j,Y', + minDate: new Date().fp_incr(0), + maxDate: new Date().fp_incr(360) + }) + flatpickr("#takeoffDate2", { + dateFormat: "Y-m-d", + altInput: true, + altFormat: 'M j,Y', + minDate: new Date().fp_incr(0), + maxDate: new Date().fp_incr(360) + }) + //调换城市 + $('.exchange').click(function() { + var flightfrom = $('#startName1').val(); + var flighto = $('#destinationName1').val(); + $('#startName1').val(flighto); + $('#destinationName1').val(flightfrom); + var flightfromCode = $('#startCode1').val(); + var flightoCode = $('#destinationCode1').val(); + $('#startCode1').val(flightoCode); + $('#destinationCode1').val(flightfromCode); + }); + //往返选择 + $("input[name=triptype]").click(function() { + switch ($(this).val()) { + case "1": //单程 + $(this).parents("form").find("#endDate").hide(); + break; + case "2": //往返 + $(this).parents("form").find("#endDate").show(); + break; + } + }); + //出发城市/到达城市搜索 自动补全 + window.cityName = []; + window.cityCode = []; + window.FlightUrl = "/guide-use.php/china_flights/allcity"; //网前 + //var FlightUrl = "http://202.103.68.156:9032/flight/ajaxGetCodeAndName/"; //本地 + $.getJSON(FlightUrl, function(json) { + for (key in json) { + let key_r = (json[key].city_english_name).replace(/\s+/g, "") + cityName[key] = key_r; + cityCode[key_r] = json[key].city_threeChar; + } + $('#startName1').typeahead({ + source: cityName, + autoSelect: true, + afterSelect: function() { + $('#startCode1').val(cityCode[$('#startName1').val()]); + } + }); + + $('#destinationName1').typeahead({ + source: cityName, + autoSelect: true, + afterSelect: function() { + $('#destinationCode1').val(cityCode[$('#destinationName1').val()]); + } + }); + }); + + var nav_id = $('#header'); + var html_body = $('html,body'); + var new_nav_name = 'getFixed'; + if (nav_id.length > 0) { + $(window).on('scroll', function() { + var scrollTop = html_body.scrollTop(); + if (scrollTop > 100) { + nav_id.addClass(new_nav_name); + } else { + nav_id.removeClass(new_nav_name); + } + }); + } + + $(".js_flightdetails").click(function(params) { + var fDetails = $(this).closest("div.airlineContent").find("div.airlineDetail"); + if (fDetails.is(":visible")) { + fDetails.hide(); + $(this).find("i").removeClass("fa-angle-up").addClass("fa-angle-down"); + } else { + fDetails.show(); + $(this).find("i").removeClass("fa-angle-down").addClass("fa-angle-up"); + } + }); + + $("#searchBtn").click(function() { + //搜索按钮点击都算重新搜索 + $("#isReturn").val("0"); + }); + //filter + $("input[class='jsfilter']").click(function() { + + //alert($(this).val()); + //获取每个选中条件 + var filterArr = new Array(); + var c_filterArr = new Array(); + var c_ItemName = c_ItemVaule = ""; + $("input[class='jsfilter']").each(function(index, element) { + if ($(this).is(":checked")) { + //先把选中的项数据放入数组待处理 + c_ItemName = $(this).attr("name"); + c_ItemVaule = $(this).val(); + //放入数组 + var c_filterItem = new Array(); + c_filterItem[0] = c_ItemName; + c_filterItem[1] = c_ItemVaule; + c_filterArr.push(c_filterItem); //所有过滤条件 + filterArr.push(c_filterItem[0]); //类别 + + $(this).closest("li.fitem").removeClass("f-checked").addClass("f-checked"); + } else { + $(this).closest("li.fitem").removeClass("f-checked"); + } + + }); + + //根据选中条件的数组去重复 + filterArr = unique(filterArr); + + if (filterArr.length > 0) { + $("#js_flightInfo>div.airlineContent").each(function(index, element) { + var flightData = $(this).attr("data"); + var Stops_Show = airline_Show = dtimes_Show = atimes_Show = dAirPort_Show = aAirPort_Show = true; //默认显示 + + //如果有勾选条件,就需要判断 + if (filterArr.indexOf("Stops") > -1) { + var stopVaule = flightData.split("|")[9]; + if (CheckInArr(c_filterArr, "Stops", stopVaule)) { + Stops_Show = true; + } else { + Stops_Show = false; + } + } + + if (filterArr.indexOf("airline") > -1) { + var airlineVaule = flightData.split("|")[0]; + if (CheckInArr(c_filterArr, "airline", airlineVaule)) { + airline_Show = true; + } else { + airline_Show = false; + } + } + + if (filterArr.indexOf("dtimes") > -1) { + var timeVaule = TimesPart(flightData.split("|")[4]); + if (CheckInArr(c_filterArr, "dtimes", timeVaule)) { + dtimes_Show = true; + } else { + dtimes_Show = false; + } + } + if (filterArr.indexOf("atimes") > -1) { + var timeVaule = TimesPart(flightData.split("|")[6]); + if (CheckInArr(c_filterArr, "atimes", timeVaule)) { + atimes_Show = true; + } else { + atimes_Show = false; + } + } + + if (filterArr.indexOf("DepartAirport") > -1) { + var dAirPortVaule = flightData.split("|")[12]; + if (CheckInArr(c_filterArr, "DepartAirport", dAirPortVaule)) { + dAirPort_Show = true; + } else { + dAirPort_Show = false; + } + } + if (filterArr.indexOf("ArriveAirport") > -1) { + var aAirPortVaule = flightData.split("|")[16]; + if (CheckInArr(c_filterArr, "ArriveAirport", aAirPortVaule)) { + aAirPort_Show = true; + } else { + aAirPort_Show = false; + } + } + + //几个过滤条件是并的关系 + if (Stops_Show && airline_Show && dtimes_Show && atimes_Show && dAirPort_Show && aAirPort_Show) { + $(this).show(); + } else { + $(this).hide(); + } + }); + } else { + $("#js_flightInfo>div.airlineContent").show(); + } + + function CheckInArr(arr, key, value) { + var ciResult = false; + for (var ci = 0; ci < arr.length; ci++) { + ciName = arr[ci][0]; + ciValue = arr[ci][1]; + if (key == ciName && value == ciValue) { + ciResult = true; + break; + } + } + return ciResult; + } + + }); + + readData(); + +})(window.jQuery); + +/** loader */ +function loaderOn() { + document.getElementById("loader").style.display = "block"; +} + +function loaderOff() { + document.getElementById("loader").style.display = "none"; +} + +function showAllClick(e) { + var cshow = $(e).closest("div.cabinlist").find("div.airlineCabin"); + if ($(e).find("span").html() == "Show Less") { + cshow.filter(":gt(0)").hide(); + $(e).find("span").html("Show More"); + $(e).find("i").removeClass("fa-angle-down").addClass("fa-angle-up"); + + + } else { + cshow.filter(":gt(0)").show(); + $(e).find("span").html("Show Less"); + $(e).find("i").removeClass("fa-angle-up").addClass("fa-angle-down"); + } + +} + +//sort +function sortFligt(e) { + var sortName = $(e).html(); + var sortItemIndex = 0; //对比项所在数组中的位置 + if (sortName == "Departure") { + sortItemIndex = 4; + } else if (sortName == "Arrival") { + sortItemIndex = 6; + } else if (sortName == "Duration") { + sortItemIndex = 7; + } else if (sortName == "Price") { + sortItemIndex = 8; + } + + var sortItem = function(a, b) { + var aItemData = $(a).attr("data"); + var bItemData = $(b).attr("data") + var aItem = aItemData.split("|")[sortItemIndex]; + var bItem = bItemData.split("|")[sortItemIndex]; + var arrResult = new Array(2); + if (sortItemIndex == 4 || sortItemIndex == 6 || sortItemIndex == 7) { + //departruetiime + var arrAItem = aItem.split(":"); + var arrBItem = bItem.split(":"); + arrResult[0] = parseInt(arrAItem[0]) * 12 + parseInt(arrAItem[1]); + arrResult[1] = parseInt(arrBItem[0]) * 12 + parseInt(arrBItem[1]); + } else if (sortItemIndex == 8) { + arrResult[0] = parseInt(aItem); + arrResult[1] = parseInt(bItem); + } + + return arrResult; + } + + var asc = function(a, b) { + var ascSortItem = sortItem(a, b); + return ascSortItem[0] > ascSortItem[1] ? 1 : -1; + } + + var desc = function(a, b) { + var descSortItem = sortItem(a, b); + return descSortItem[0] > descSortItem[1] ? -1 : 1; + } + + var sortByItem = function(sortBy) { + var sortEle = $('#js_flightInfo>div.airlineContent').sort(sortBy); + $('#js_flightInfo').empty().append(sortEle); + } + + var ascI = $(e).closest("div.orderItem").find("span.sortArrow").find("i"); + if (ascI.eq(0).hasClass("f-checked")) { + ascI.eq(0).removeClass("f-checked"); + ascI.eq(1).removeClass("f-checked").addClass("f-checked"); + sortByItem(desc); + } else { + ascI.eq(1).removeClass("f-checked"); + ascI.eq(0).removeClass("f-checked").addClass("f-checked"); + sortByItem(asc); + } + +} + +///根据时间字符串分区,1,2,3,4 六小时一区 +function TimesPart(strTime) { + var H_Times = parseInt(strTime.split(":")[0]); + var PartResult; + if (H_Times > 0 && H_Times < 6) { + PartResult = 1; + } else if (H_Times >= 6 && H_Times < 12) { + PartResult = 2; + } else if (H_Times >= 12 && H_Times < 18) { + PartResult = 3; + } else if (H_Times >= 18 && H_Times < 24) { + PartResult = 4; + } + return PartResult; +} + +//数组去重复 +function unique(arr) { + for (var i = 0; i < arr.length; i++) { + for (var j = i + 1; j < arr.length; j++) { + if (arr[i] == arr[j]) { //第一个等同于第二个,splice方法删除第二个 + arr.splice(j, 1); + j--; + } + } + } + return arr; +} + +function parseFlightData(flightStr) { + let flightKey = ['airlineIataCode', 'showAirLineCompany', 'airlineCompany', 'departDate', 'departTime', 'arriveDate', 'arriveTime', 'duration', 'lowPrice', 'stopNum', 'departCityIataCode', 'departAirportNameEn', 'departAirportCode', 'departAirportTerminal', 'arriveCityIataCode', 'arriveAirportNameEn', 'arriveAirportCode', 'arriveAirportTerminal', 'flightNo', 'craftType', 'stopNum', 'stopCityCode', 'showStopCityName', 'airPortCode', 'airPortName', 'stoparrivalTime', 'stopdepartrueTime', 'departAirportName', 'arriveAirportName','departCityIataNameEn','arriveCityIataNameEn', 'airLineIcon']; + let flightValue = flightStr.split('|'); + let ret = flightValue.reduce(function(ret, field, index) { + ret[flightKey[index]] = field; + return ret; + }, {}); + return JSON.stringify(ret); +} + +function parseCabinData(longStr) { + let arrKey = ['cabinClassName', 'cabinClassNameEn', 'adultPrice', 'adultPrice_usd', 'childPrice', 'childPrice_usd', 'cabinClass', 'seatStatus', 'freeLuggage', 'freeLuggageUnit', 'adultTax', 'adultTax_usd', 'cabinClassFullPrice', 'cabinClassFullPrice_usd', 'babyPrice', 'babyPrice_usd', 'serviceFeeAdult', 'serviceFeeAdult_usd', 'serviceFeeBaby', 'serviceFeeBaby_usd']; + let strValue = longStr.split('|'); + let ret = strValue.reduce(function(ret, field, index) { + ret[arrKey[index]] = field; + return ret; + }, {}); + return JSON.stringify(ret); +} +/** + * 选座预订按钮,主要注意往返程 + */ +function chooseSeat(e) { + loaderOn(); + var FlightInfo = $(e).closest("div.airlineContent").attr("data"); + var CabinInfo = $(e).attr("data-cabin"); + var c_roundTrip = $("#roundTrip").val(); + var c_isReturn = $("#isReturn").val(); + sessionStorage.setItem('roundTrip', c_roundTrip); + sessionStorage.setItem('isReturn', c_isReturn); + if (c_roundTrip.toUpperCase() === "TRUE" && Number(c_isReturn) !== 0) { + sessionStorage.setItem('ArriveFlightInfo', (parseFlightData(FlightInfo))); + sessionStorage.setItem('ArriveCabinInfo', parseCabinData(CabinInfo)); + sessionStorage.setItem('ArriveFlightStr', ((FlightInfo))); + sessionStorage.setItem('ArriveCabinStr', (CabinInfo)); + window.location.href = '/china-flights/book'; + } else { + sessionStorage.setItem('DepartFlightInfo', (parseFlightData(FlightInfo))); + sessionStorage.setItem('DepartCabinInfo', parseCabinData(CabinInfo)); + sessionStorage.setItem('DepartFlightStr', ((FlightInfo))); + sessionStorage.setItem('DepartCabinStr', (CabinInfo)); + if (c_roundTrip.toUpperCase() !== "TRUE") { + window.location.href = '/china-flights/book'; + } else { + $("#isReturn").val("1"); + $("#searchform").get(0).submit(); + } + } + return false; +} +function readData() { + let DepartFlightInfo = sessionStorage.getItem('DepartFlightInfo'); + let DepartCabinInfo = sessionStorage.getItem('DepartCabinInfo'); + if (!DepartFlightInfo) { + return false; + } + DepartFlightInfo = JSON.parse(DepartFlightInfo) ; + DepartCabinInfo = JSON.parse(DepartCabinInfo) ; + let iconSrc = "/china-flights/images/icon/" + DepartFlightInfo.airLineIcon + ".gif"; + $('#selected__airicon').attr('src',iconSrc); + $('#selected__airicon').attr('alt',DepartFlightInfo.showAirLineCompany); + $('#selected__deaprtdate').html(DepartFlightInfo.departDate); + $('#selected__cabinname').html(DepartCabinInfo.cabinClassNameEn); + $('#selected__airline').html(DepartFlightInfo.showAirLineCompany); + $('#selected__flihgtinfo').html(DepartFlightInfo.flightNo + '/' + DepartFlightInfo.craftType); + $('#selected__departtime').html(DepartFlightInfo.departTime); + $('#selected__arrivetime').html(DepartFlightInfo.arriveTime); + $('#selected__departairport').html(DepartFlightInfo.departAirportNameEn + '(' + DepartFlightInfo.departAirportTerminal + ')'); + $('#selected__arriveairport').html(DepartFlightInfo.arriveAirportNameEn + '(' + DepartFlightInfo.arriveAirportTerminal + ')'); + $('#selected__duration').html(DepartFlightInfo.duration); + $('#selected__adultusd').html(DepartCabinInfo.adultPrice_usd); + if (parseInt(DepartFlightInfo.stopNum) > 0) { + let stopinfo = DepartFlightInfo.showStopCityName + "," + DepartFlightInfo.stoparrivalTime + "-" + DepartFlightInfo.stopdepartrueTime; + let stopinfoHtml = '' + DepartFlightInfo.stopCityCode + ''; + $('#selected__stopinfo').html(stopinfoHtml); + } + $('#selected__content').removeClass('hidden'); +}