|
|
|
|
(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 = '<a href="javascript:;" title="' + stopinfo + '">' + DepartFlightInfo.stopCityCode + '</a>';
|
|
|
|
|
$('#selected__stopinfo').html(stopinfoHtml);
|
|
|
|
|
}
|
|
|
|
|
$('#selected__content').removeClass('hidden');
|
|
|
|
|
}
|