var total_price = 0;
var total_no = 1;
var prod_Arr = [];
var category_id = getStorage("category_id");
var pro_cate_id = getStorage("pro_cate_id");
var pro_cate_name = "";
var run_date = after(getDateTime(0));
var back_run_date = after(getDateTime(0));
var go_year = getMonthAndDayByDate(run_date, 'year');
var go_month = getMonthAndDayByDate(run_date, 'month');
var go_day = getMonthAndDayByDate(run_date, 'day');
var back_year = getMonthAndDayByDate(back_run_date, 'year');
var back_month = getMonthAndDayByDate(back_run_date, 'month');
var back_day = getMonthAndDayByDate(back_run_date, 'day');
var car_id = "";
var back_car_id = "";
var go_back = "0";
var run_date_list = [];
var bus_stock = -1; //后台实时库存
var back_station_prod = [];
var back_prod_arr = [];
var back_date_list = [];
$(document).ready(function() {
ifLogin(function(flag) {
$('body').show();
httpLoadInfo();
});
});
function httpLoadInfo() {
get_data();
$("#go_run_date").text(go_month + "月" + go_day + "日");
// $("#back_run_date").text(back_month + "月" + back_day + "日");
$("#back_run_date").text('请选择');
$("#go_sel_date").text(go_month + "月" + go_day + "日");
$(".model").on("click", function() {
$('.model_box').addClass('fadeInDown animated');
setTimeout(function() {
$('.model').hide();
$('#body_mod').removeClass('mod_fil');
}, 400);
// $(".model_box").animate({
// height: "hide"
// }, 400, function() {
// $(".model").hide();
// $("#body_mod").removeClass("mod_fil");
// });
});
$(".model_car").on("click", function() {
$('.model_box_car').addClass('fadeInDown animated');
setTimeout(function() {
$('.model_car').hide();
$('#body_mod').removeClass('mod_fil');
}, 400);
// $(".model_box_car").animate({
// height: "hide"
// }, 400, function() {
// $(".model_car").hide();
// $("#body_mod").removeClass("mod_fil");
// });
});
$(".model_box").on("click", function(e) {
e.stopPropagation();
});
$(".model_box_car").on("click", function(e) {
e.stopPropagation();
});
}
function get_data() {
$.ajax({
url: base_api + "prod/prod/get-prod-detail", //请求地址
data: {
pro_cate_id: pro_cate_id,
category_id: category_id
},
type: "post",
dataType: "json",
async: false,
success: function(data) {
run_date_list = data.data.run_date;
ZZLog(data);
if(data.flag) {
list_html(data.data);
$("#bg_img").css("background-image", "url(" + data.data.show_img + ")");
$(".top_title").text(data.data.pro_cate_name);
pro_cate_name = data.data.pro_cate_name;
} else {
if(codeNotLogin == data['code']) {
alert(infoNotLogin);
var URL = '/web/fx/landmark_ticket.html';
URL = encodeURI(URL);
location.href = data['url'] + URL;
} else if(codeNotRegister == res_data['code']) {
location.href = 'register.html';
} else {
alert(data['msg']);
}
}
},
error: function(error) {
console.log(error);
}
});
}
function list_html(data) {
var temp = "";
for(var i = 0, j = data.prod_arr.length; i < j; i++) {
var img = 'images/jianhao.png';
var str = '0';
if(i == 0) {
img = 'images/jianhao_sel.png';
str = '1'
}
temp += '
' +
'
' + data.prod_arr[i].prod_name + '
' +
'
' +
'
' +
'
![](' + img + ')
' +
str +
// '
0' +
'
![](images/jiahao_sel.png)
' +
'
' +
'
' +
'
¥
' +
'
' + data.prod_arr[i].prod_price + '/张
' +
'
' +
'
' +
'
'
}
$("#tick_type").html(temp);
//订票须知
if(data.booking_notice) {
var booking_notice_arr = data.booking_notice.split('
');
var bnHTML = '';
for(var i = 0, m = booking_notice_arr.length; i < m; i++) {
// bnHTML += `${booking_notice_arr[i]}
`;
bnHTML += '' + booking_notice_arr[i] + '
';
}
$(".booking_notice").html(bnHTML);
}
//加
$(".add").on("touchstart", function() {
if(pro_cate_id == "3") {
// var tot_no = 0;
$(".aticket").each(function(index, domE) {
total_no += parseInt($(this).text());
});
if(total_no == 5) {
alert("迪士尼最多只能买五张票");
} else {
var current = $(this).parent().find(".aticket").text();
var now_count = parseInt(current) + 1;
$(this).parent().find(".aticket").text(now_count);
$(this).parent().find(".cut").attr("src", "images/jianhao_sel.png");
// countTotal();
}
} else {
var current = $(this).parent().find(".aticket").text();
var now_count = parseInt(current) + 1;
$(this).parent().find(".aticket").text(now_count);
$(this).parent().find(".cut").attr("src", "images/jianhao_sel.png");
// countTotal();
}
});
//减
$(".cut").on("touchstart", function() {
var current = $(this).parent().find(".aticket").text();
var now_count = parseInt(current) - 1;
if(now_count > 0) {
$(this).parent().find(".aticket").text(now_count);
} else {
$(this).parent().find(".aticket").text('0');
$(this).attr("src", "images/jianhao.png");
}
// countTotal();
})
}
//总价
function countTotal() {
total_price = 0;
prod_Arr = [];
prod_info = "";
total_no = 0;
var tick_no = '';
back_prod_arr = [];
$(".aticket").each(function(index, domE) {
tick_no = parseInt($(this).text());
var tick_price = parseFloat($(this).attr("one_price"));
var back_tick_price = 0;
var back_prod_id = 0;
var go_back = $("#if_back").attr("go_back");
if(go_back == 1) {
back_tick_price = back_station_prod[index]['prod_price'] - 0;
back_prod_id = back_station_prod[index]['prod_id'];
var obj = {
"prod_id": back_prod_id,
"prod_count": $(this).text(),
"prod_name": $(this).attr('prod_name')
}
back_prod_arr.push(obj);
}
total_price = (total_price * 100 + tick_no * tick_price * 100) / 100;
total_no += tick_no;
prod_info = {
"prod_id": $(this).attr("prod_id"),
"prod_count": $(this).text(),
"prod_name": $(this).attr("prod_name")
}
prod_Arr.push(prod_info);
});
// console.log(total_price);
// console.log(prod_Arr);
// console.log(total_no);
}
//选择去程日期
$("#go_date_select").on("click", function() {
$('.model_box').removeClass('fadeInUp');
$('.model_box').removeClass('animated');
$('.model_box').removeClass('fadeInDown');
$("#go_sel_date").text(go_month + "月" + go_day + "日");
var caType = window.calendar.init.showTypeEnum.show_customer;
window.calendar.init({
showType:caType,
startDate: getDateTime(0),
chooseDate: run_date,
showDays:run_date_list
}, function(year, month, day, ymdString) {
$('.model_box').addClass('fadeInDown animated');
setTimeout(function() {
$('.model').hide();
$('#body_mod').removeClass('mod_fil');
}, 400);
// $(".model_box").animate({
// height: "hide"
// }, 400, function() {
// $(".model").hide();
// $("#body_mod").removeClass("mod_fil");
// });
run_date = ymdString;
go_year = year;
go_month = month;
go_day = day;
if(run_date > back_run_date) {
back_run_date = ymdString;
back_year = year;
back_month = month;
back_day = day;
// $("#back_run_date").text(month + "月" + day + "日");
$("#back_run_date").text('请选择');
$("#back_show_class").text("请选择");
$("#back_show_class").removeAttr("back_time");
$("#back_show_class").removeAttr("back_run_id");
$("#back_show_class").removeAttr("back_cate_name");
back_car_id = "";
}
$("#go_run_date").text(month + "月" + day + "日");
$("#go_sel_date").text(month + "月" + day + "日");
console.log(year, month, day, ymdString);
// 2017 04 12 2017-04-12
//重新选择日期后班次要重新选
$("#go_show_class").text("请选择");
$("#go_show_class").removeAttr("go_time");
$("#go_show_class").removeAttr("go_run_id");
$("#go_show_class").removeAttr("go_cate_name");
car_id = "";
});
$(".model").show();
$('.model_box').show();
$("#body_mod").addClass("mod_fil");
$('.model_box').addClass('fadeInUp animated');
// $(".model_box").animate({
// height: "show"
// }, 400);
});
//选择去程班次
$("#go_classes").on("click", function() {
$('.model_box_car').removeClass('fadeInUp');
$('.model_box_car').removeClass('animated');
$('.model_box_car').removeClass('fadeInDown');
$('#back_run_date').html('请选择');
$.ajax({
url: base_api + "prod/prod/get-bus-stock", //请求地址
data: {
pro_cate_id: pro_cate_id,
date: run_date
},
type: "post",
dataType: "json",
async: false,
success: function(data) {
console.log(data)
if(data.flag) {
go_car_html(data.data);
$(".model_car").show();
$('.model_box_car').show();
$("#body_mod").addClass("mod_fil");
$('.model_box_car').addClass('fadeInUp animated');
// $(".model_car").show();
// $("#body_mod").addClass("mod_fil");
// $(".model_box_car").animate({
// height: "show"
// }, 400);
} else {
if(codeNotLogin == data['code']) {
alert(infoNotLogin);
var URL = 'landmark_ticket.html';
URL = encodeURI(URL);
location.href = data['url'] + URL;
} else {
alert(data['msg']);
}
}
},
error: function(error) {
console.log(error);
}
});
});
//替换去程班次信息
function go_car_html(data) {
var temp = "";
var run_status = "";
var run_count = "";
for(var key in data.prod_info) {
var prod_list = data.prod_info[key];
var p_obj = prod_list[0];
var may_sel = "";
var may_info = "";
var may_col = "";
var select_car = "";
run_status = p_obj.run_status;
run_count = p_obj.count;
if(run_status == 142) {
may_sel = "select_kong";
may_info = "已停运";
may_col = "text_c_cc";
select_car = "select_car_off";
} else if(run_status != "138") {
may_sel = "select_kong";
may_info = "已发车";
may_col = "text_c_cc";
select_car = "select_car_off";
} else {
if(run_count == "0") {
may_sel = "select_kong";
may_info = "已售罄";
may_col = "text_c_cc";
select_car = "select_car_off";
} else {
may_sel = "select_quan";
may_info = "余票充足";
may_col = "text_c_80";
select_car = "select_car_on";
}
}
temp += '' +
'
' + p_obj.start_time + '
' +
'
' + may_info + '
' +
'
' +
'
'
}
$("#sel_car").html(temp);
if($("#" + car_id).attr("run_status") == "138" && $("#" + car_id).attr("run_count") != "0") {
$("#" + car_id).find(".selected").removeClass("select_quan");
$("#" + car_id).find(".selected").addClass("select_gou");
}
$(".select_car_on").on("click", function() {
car_id = $(this).attr("id");
//获取库存
if(bus_stock==-1){
bus_stock = $(this).attr('run_count')-0;
}else{
var t_stock = $(this).attr('run_count')-0;
bus_stock = bus_stock>t_stock?t_stock:bus_stock;
}
var go_time = $(this).attr("go_time");
var go_run_id = $(this).attr("id");
var go_cate_name = $(this).attr("cate_name");
$("#sel_car").find(".selected").removeClass("select_gou");
$("#sel_car").find(".selected").addClass("select_quan");
$(this).find(".selected").removeClass("select_quan");
$(this).find(".selected").addClass("select_gou");
$('.model_box_car').addClass('fadeInDown animated');
setTimeout(function() {
$('.model_car').hide();
$('#body_mod').removeClass('mod_fil');
}, 400);
// $(".model_box_car").animate({
// height: "hide"
// }, 400, function() {
// $(".model_car").hide();
// $("#body_mod").removeClass("mod_fil");
// });
$("#go_show_class").text(go_time + "发车");
$("#go_show_class").attr("go_time", go_time);
$("#go_show_class").attr("go_run_id", go_run_id);
$("#go_show_class").attr("go_cate_name", go_cate_name);
});
}
//、、、、、、、、、、、、、、、、、、、、、去程结束、返程开始、、、、、、、、、、、、、、、、、、//
//选择返程日期
$("#back_date_select").on("click", function() {
if($('#go_show_class').html() == '请选择'){
alert('请选择去程班次');
return;
}
$.ajax({
url: base_api + "prod/prod/get-bus-sale-date", //请求地址
data: {
pro_cate_id: pro_cate_id,
if_back: '1'
},
type: "post",
dataType: "json",
async: false,
success: function(data) {
ZZLog(data);
if(data.flag) {
back_date_list = data.data.list;
} else {
alert('未获取到后台数据');
}
},
error: function(error) {
alert('未获取到后台数据');
}
});
$('.model_box').removeClass('fadeInUp');
$('.model_box').removeClass('animated');
$('.model_box').removeClass('fadeInDown');
$("#go_sel_date").text(back_month + "月" + back_day + "日");
var baType = window.calendar.init.showTypeEnum.show_customer;
window.calendar.init({
showType:baType,
startDate: run_date,
chooseDate: back_run_date,
showDays:back_date_list
}, function(year, month, day, ymdString) {
$('.model_box').addClass('fadeInDown animated');
setTimeout(function() {
$('.model').hide();
$('#body_mod').removeClass('mod_fil');
}, 400);
// $(".model_box").animate({
// height: "hide"
// }, 400, function() {
// $(".model").hide();
// $("#body_mod").removeClass("mod_fil");
// });
back_run_date = ymdString;
back_year = year;
back_month = month;
back_day = day;
if(run_date > back_run_date) {
back_run_date = ymdString;
$("#back_run_date").text(month + "月" + day + "日");
}
$("#back_run_date").text(month + "月" + day + "日");
$("#go_sel_date").text(month + "月" + day + "日");
$("#back_show_class").text("请选择");
$("#back_show_class").removeAttr("back_time");
$("#back_show_class").removeAttr("back_run_id");
$("#back_show_class").removeAttr("back_cate_name");
back_car_id = "";
});
$(".model").show();
$('.model_box').show();
$("#body_mod").addClass("mod_fil");
$('.model_box').addClass('fadeInUp animated');
// $(".model_box").animate({
// height: "show"
// }, 400);
});
//选择返程班次
$("#back_classes").on("click", function() {
if($('#go_show_class').html() == '请选择'){
alert('请选择去程班次');
return;
}
if($('#back_run_date').html() == '请选择'){
alert('请选择返程日期');
return;
}
$('.model_box_car').removeClass('fadeInUp');
$('.model_box_car').removeClass('animated');
$('.model_box_car').removeClass('fadeInDown');
$.ajax({
url: base_api + "prod/prod/get-bus-stock", //请求地址
data: {
pro_cate_id: pro_cate_id,
date: back_run_date,
if_back: "1"
},
type: "post",
dataType: "json",
async: false,
success: function(data) {
console.log(data)
if(data.flag) {
back_car_html(data.data);
$(".model_car").show();
$('.model_box_car').show();
$("#body_mod").addClass("mod_fil");
$('.model_box_car').addClass('fadeInUp animated');
// $(".model_car").show();
// $("#body_mod").addClass("mod_fil");
// $(".model_box_car").animate({
// height: "show"
// }, 400);
} else {
if(codeNotLogin == data['code']) {
alert(infoNotLogin);
var URL = 'landmark_ticket.html';
URL = encodeURI(URL);
location.href = data['url'] + URL;
} else {
alert(data['msg']);
}
}
},
error: function(error) {
console.log(error);
}
});
});
//替换返程班次信息
function back_car_html(data) {
var temp = "";
var run_status = "";
var run_count = "";
for(var key in data.prod_info) {
var prod_list = data.prod_info[key];
var p_obj = prod_list[0];
var may_sel = "";
var may_info = "";
var may_col = "";
var select_car = "";
run_status = p_obj.run_status;
run_count = p_obj.count;
if(run_status == 142) {
may_sel = "select_kong";
may_info = "已停运";
may_col = "text_c_cc";
select_car = "select_car_off";
} else if(run_status != "138") {
may_sel = "select_kong";
may_info = "已发车";
may_col = "text_c_cc";
select_car = "select_car_off";
} else {
if(run_count == "0") {
may_sel = "select_kong";
may_info = "已售罄";
may_col = "text_c_cc";
select_car = "select_car_off";
} else {
may_sel = "select_quan";
may_info = "余票充足";
may_col = "text_c_80";
select_car = "select_car_on";
}
}
var obj = prod_list;
obj.forEach(function(v, i) {
v['station_str'] = v['station_str'].replace(/ /g, '');
})
temp += '' +
'
' + p_obj.start_time + '
' +
'
' + may_info + '
' +
'
' +
'
'
}
$("#sel_car").html(temp);
if($("#" + back_car_id).attr("run_status") == "138" && $("#" + back_car_id).attr("run_count") != "0") {
$("#" + back_car_id).find(".selected").removeClass("select_quan");
$("#" + back_car_id).find(".selected").addClass("select_gou");
}
$(".select_car_on").on("click", function() {
back_car_id = $(this).attr("id");
//获取库存
if(bus_stock==-1){
bus_stock = $(this).attr('run_count')-0;
}else{
var t_stock = $(this).attr('run_count')-0;
bus_stock = bus_stock>t_stock?t_stock:bus_stock;
}
var back_time = $(this).attr("go_time");
var back_run_id = $(this).attr("id");
var back_cate_name = $(this).attr("cate_name");
//update 201705231337
back_station_prod = $(this).attr('dict');
back_station_prod = JSON.parse(back_station_prod);
back_pro_cate_id = data.pro_cate_id;
//选择班次的时候将返程的价格显示上去
$('.single_price').each(function(index, dom) {
var price = parseFloat($(this).attr('data-price')) - 0;
var price_2 = (parseFloat(price) + parseFloat(back_station_prod[index]['prod_price'])) - 0;
// $(this).attr('data-price', price_2); //false TODO选择返程的班次时更改票种的价格-现定义data-price为单程价格 注释后:始终存为去程的价格
$(this).html(price_2 + '/张');
})
$("#sel_car").find(".selected").removeClass("select_gou");
$("#sel_car").find(".selected").addClass("select_quan");
$(this).find(".selected").removeClass("select_quan");
$(this).find(".selected").addClass("select_gou");
$('.model_box_car').addClass('fadeInDown animated');
setTimeout(function() {
$('.model_car').hide();
$('#body_mod').removeClass('mod_fil');
}, 400);
// $(".model_box_car").animate({
// height: "hide"
// }, 400, function() {
// $(".model_car").hide();
// $("#body_mod").removeClass("mod_fil");
// });
$("#back_show_class").text(back_time + "发车");
$("#back_show_class").attr("back_time", back_time);
$("#back_show_class").attr("back_run_id", back_run_id);
$("#back_show_class").attr("back_cate_name", back_cate_name);
});
}
function reserve() {
countTotal();
var go_time = $("#go_show_class").attr("go_time");
var back_time = $("#back_show_class").attr("back_time");
var go_run_id = $("#go_show_class").attr("go_run_id");
var back_run_id = $("#back_show_class").attr("back_run_id");
var go_cate_name = $("#go_show_class").attr("go_cate_name");
var back_cate_name = $("#back_show_class").attr("back_cate_name");
var fill_order_20170307 = "";
go_back = $("#if_back").attr("go_back");
if(total_no == "0") {
alert("请选择票种数量");
} else {
if(bus_stock/张');
})
}
$("#back_date").animate({
height: "hide"
}, 200);
$(this).attr("go_back", "0");
$(this).text("添加返程");
$(this).removeClass("cancel_back_btn");
$(this).addClass("sel_back_btn");
$("#back_show_class").text("请选择");
$("#back_show_class").removeAttr("go_time");
back_car_id = "";
}
});