var order_status = '';
var order_id = '';
var goHTML = '';
var backHTML = '';
//记录是否是返程
var ifback = '';
var intDiff = '';//倒计时总秒数量
window.onload = function(){
goHTML = $('#go').html();
backHTML = $('#goback').html();
order_id = getPar('order_id');
httpData(order_id);
}
//请求数据
function httpData(order_id){
$.ajax({
url:'./zz_wxsct/Model/order/order_detail_info.php', //请求地址
type: "post", //请求方式
async:false,
data:{
order_id:order_id
},
dataType: "json",
success: function (data) {
console.log(data);
if(data.code == 0){
intDiff = data.time_left > 0? data.time_left : 0;
reloadData(data);
}else{
alert(data.info);
}
}
});
}
//加载数据
function reloadData(data){
ifback = data.is_back;
if (data.is_back == 0) {
$('#go').removeClass('ui_hide');
$('#goback').addClass('ui_hide');
//判断展示
var golist = data.go_list;
var status=golist.order_status;
var passenger = data.go_list.customer_info;
//去程
var tempHTML = goHTML;
tempHTML=tempHTML.replace('[185518]',data.order_id);
tempHTML=tempHTML.replace('[待支付]',golist.order_status_info);
// tempHTML=tempHTML.replace('[order_id]',golist.start_area_name);
tempHTML=tempHTML.replace('[出发地]',golist.start_area_name);
tempHTML=tempHTML.replace('[出发地站点]',golist.start_res_name);
tempHTML=tempHTML.replace('[去程时间]',golist.start_time);
tempHTML=tempHTML.replace('[去程日期]',golist.start_date);
tempHTML=tempHTML.replace('[目的地]',golist.end_area_name);
tempHTML=tempHTML.replace('[目的地站点]',golist.end_res_name);
tempHTML=tempHTML.replace('[去程人数]',golist.seat_num+'人');
tempHTML=tempHTML.replace('[去程座位]',golist.seat_type);
tempHTML=tempHTML.replace('[联系人]',golist.contact_name);
tempHTML=tempHTML.replace('[联系人手机号]',golist.contact_mobile);
tempHTML=tempHTML.replace('[50]',golist.total_price);
var passHTML = $('#passenger_go').html();
var passtemp = '';
if (passenger.length > 0) {
for (var i = 0; i < passenger.length; i++) {
var p_html=passHTML;
p_html = p_html.replace('[乘车人]',passenger[i].name);
p_html = p_html.replace('[身份证信息]',passenger[i].id_num_encrypt);
passtemp += p_html;
}
// $('#passenger').html(passtemp);
}
if (golist.order_status == "145") {
tempHTML=tempHTML.replace('[payred_color]','payred_color');
tempHTML=tempHTML.replace('
','去支付
');
tempHTML=tempHTML.replace('','去支付
');
}else if (golist.order_status == "146") {
tempHTML=tempHTML.replace('[payred_color]','yellow_color');
if (golist.can_do == '0') {
//不能退票
tempHTML=tempHTML.replace('class="ulev4 fontgreen_color" id="price"','class="ulev4 lightgray_color" id="price"');
tempHTML=tempHTML.replace('','退票
');
} else{
tempHTML=tempHTML.replace('','退票
');
}
// $('#title_div_go').addClass('ui_hide');
}else if(golist.order_status == "148"){
tempHTML=tempHTML.replace('[payred_color]','lightgray_color');
tempHTML=tempHTML.replace('','重新购票
');
// $('#title_content_go').html('订单超时已取消')
}else if(golist.order_status == "147"){
tempHTML=tempHTML.replace('[payred_color]','lightgray_color');
tempHTML=tempHTML.replace('','隐藏
');
}
$('#go').html(tempHTML);
$('#passenger_go').html(passtemp);
if(status=="146"){
$('#title_div_go').addClass('ui_hide');
}else if(status=="148"){
$('#title_content_go').html('订单已取消')
}else if(status == "145"){
timer(intDiff,'minute_show_go','second_show_go');
}
} else{
var golist = data.go_list;
var status=golist.order_status;
var backlist = data.back_list;
var passenger = data.go_list.customer_info;
$('#go').addClass('ui_hide');
$('#goback').removeClass('ui_hide');
//去程
var tempHTML = backHTML;
tempHTML=tempHTML.replace('[185518]',data.order_id);
tempHTML=tempHTML.replace('[待支付]',golist.order_status_info);
// tempHTML=tempHTML.replace('[order_id]',golist.start_area_name);
tempHTML=tempHTML.replace('[出发地]',golist.start_area_name);
tempHTML=tempHTML.replace('[出发地站点]',golist.start_res_name);
tempHTML=tempHTML.replace('[去程时间]',golist.start_time);
tempHTML=tempHTML.replace('[去程日期]',golist.start_date);
tempHTML=tempHTML.replace('[目的地]',golist.end_area_name);
tempHTML=tempHTML.replace('[目的地站点]',golist.end_res_name);
tempHTML=tempHTML.replace('[去程人数]',golist.seat_num);
tempHTML=tempHTML.replace('[去程座位]',golist.seat_type);
tempHTML=tempHTML.replace('[联系人]',golist.contact_name);
tempHTML=tempHTML.replace('[联系人手机号]',golist.contact_mobile);
//返程
tempHTML=tempHTML.replace('[返程出发地]',backlist.start_area_name);
tempHTML=tempHTML.replace('[返程出发地站点]',backlist.start_res_name);
tempHTML=tempHTML.replace('[返程时间]',backlist.start_time);
tempHTML=tempHTML.replace('[返程日期]',backlist.start_date);
tempHTML=tempHTML.replace('[返程目的地]',backlist.end_area_name);
tempHTML=tempHTML.replace('[返程目的地站点]',backlist.end_res_name);
tempHTML=tempHTML.replace('[返程人数]',backlist.seat_num+'人');
tempHTML=tempHTML.replace('[返程座位]',backlist.seat_type);
tempHTML=tempHTML.replace('[50]',data.total_price);
var passHTML = $('#passenger').html();
var passtemp = '';
if (passenger.length > 0) {
for (var i = 0; i < passenger.length; i++) {
var p_html=passHTML;
p_html = p_html.replace('[乘车人]',passenger[i].name);
p_html = p_html.replace('[身份证信息]',passenger[i].id_num_encrypt);
passtemp += p_html;
}
// $('#passenger').html(passtemp);
}
if (golist.order_status == "145") {
tempHTML=tempHTML.replace('','去支付
');
tempHTML=tempHTML.replace('[payred_color]','payred_color');
}else if (golist.order_status == "146") {
tempHTML=tempHTML.replace('[payred_color]','yellow_color');
if (golist.can_do == '0') {
//不能退票
tempHTML=tempHTML.replace('class="ulev4 fontgreen_color" id="price"','class="ulev4 lightgray_color" id="price"');
tempHTML=tempHTML.replace('','退票
');
} else{
tempHTML=tempHTML.replace('','退票
');
}
// $('#title_div_back').html('提示:往返订单只能合并退票');
}else if(golist.order_status == "148"){
tempHTML=tempHTML.replace('[payred_color]','lightgray_color');
tempHTML=tempHTML.replace('','重新购票
');
// $('#title_content_back').html('订单已取消')
}else if(golist.order_status == "147"){
tempHTML=tempHTML.replace('[payred_color]','lightgray_color');
tempHTML=tempHTML.replace('','隐藏
');
}
$('#goback').html(tempHTML);
$('#passenger').html(passtemp);
if(status=="146"){
$('#title_div_back').html('提示:往返订单只能合并退票');
}else if(status=="148"){
$('#title_content_back').html('订单已取消')
}else if(status == "145"){
timer(intDiff,'minute_show','second_show');
}
}
}
//重新购票
function buyAgain(){
window.location.href = "./travel_book.html";
}
//退票
function rufundTicket(order_id){
var r=confirm("确定要退票吗?");
if (r==true){
$.ajax({
url:'./zz_wxsct/control.php', //请求地址
type: "post",
data:{
type:"order_refund",
order_id:order_id
},//请求方式
async:false,
dataType: "json",
success: function (data) {
console.log(data);
if(data.code == 0){
alert('退票成功!');
window.location.href = "./order_list.html";
}else{
alert(data.info);
}
}
});
}
else{
return;
}
}
//支付
function goToPay(order_id){
var minute = '';
var second = '';
if (ifback == 0) {
minute = $('#minute_show_go').html();
second = $('#second_show_go').html();
} else{
minute = $('#minute_show').html();
second = $('#second_show').html();
}
if (minute == '00分' && second == '00秒') {
alert('支付已超时,请重新购票!');
return false;
}else{
window.location.href = 'http://xmwx.zhizhuchuxing.cn/wechat/WxPay/realpay/onlinePay.php?orderid='+order_id+'&fx=11&code2=wxsc';
}
}
//倒计时
function timer(intDiff,minstr,secstr){
window.setInterval(function(){
var day=0,
hour=0,
minute=0,
second=0;//时间默认值
if(intDiff > 0){
day = Math.floor(intDiff / (60 * 60 * 24));
hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
}
if (minute <= 9) minute = '0' + minute;
if (second <= 9) second = '0' + second;
$('#'+minstr).html(minute+'分');
$('#'+secstr).html(second+'秒');
intDiff--;
}, 1000);
}