var NoComplete = { token: '', bankId: '', payLoading: null, curNo: '', loading:null, init: function() { if ($('#no_complete_page').length == 0) { return false; } $('#menu_btn').on('click', function() { $('#user_menu').toggle(); $('#user_menu').height(document.documentElement.clientHeight-45); }); $('#user_menu').on('click', function(e) { if ($(e.target).attr('id') == 'user_menu') { $('#user_menu').hide(); } }); $('#remind_btn').on('click',function(e){ var url = 'remind.html?', from = $('#startStationCode').val(), to = $('#endStationCode').val(), date = $('#start_date_val').val(); // url += 'date='+date; if(!!from){ url += '&from='+from; } if(!!to){ url += '&to='+to; } location.href = url; }); NoComplete.loading = Public.showLoading('正在获取订单信息'); Public.checkLogin(NoComplete.getToken,NoComplete.noLogin,NoComplete.noLogin); $('[data-no]').live('click', function() { NoComplete.curNo = $(this).attr('data-no'); NoComplete.selectBank(); }); $('[data-fn="close_bank"]').live('click', function() { Public.hideInnerPage(); }); $('#banks [data-bank]').live('click', function() { NoComplete.bankId = $(this).attr('data-bank'); NoComplete.payLoading = Public.showLoading('正在加载'); NoComplete.pay(); }); }, noLogin : function(){ Public.hideLoading(); Public.alert('请先登录', function() { location.href = "login.html?no_commplete"; }); }, getOrder: function() { // Referer: https://dynamic.12306.cn/otsweb/loginAction.do?method=init bootStrap.get("queryOrder/queryMyOrderNoComplete", "json", null, "queryOrder/initNoComplete").done(function(json) { Public.hideLoading(); if (!!json['status'] && !!json['data']) { if(!!json['data']['orderDBList'] && json['data']['orderDBList'].length > 0){ NoComplete.setHtml(json['data']['orderDBList']); }else if(json['data']['orderCacheDTO']){ // $('#orders').html('
'+ json['data']['orderCacheDTO']['message']['message'] +'
'); var html = ''; // html += '
 
'; // html += '
'; // html += '
'; // html += '

 

'; // html += '

哎呀,出票失败了!

'; // html += '

 

'; // html += '

'+ json['data']['orderCacheDTO']['message']['message'] +'

'; // html += '
'; // html += '
'; // html += ''; html += ''; $('#orders').html(html); } }else{ if ($('#no_complete_page').length > 0) { Public.alert('暂无订单,请到我的订单查看已完成订单',function(){ location.href = 'order_list.html'; }); } } }).fail(function(xhr, type) { if ($('#no_complete_page').length > 0) { Public.hideLoading(); Public.alert('查询失败,请重试。',function(){ location.href = location.href; }); } }); }, getToken: function() { bootStrap.post('queryOrder/initNoComplete', 'html', null, "payOrder/init").done(function(json) { var token = json.match(/\S+\s+globalRepeatSubmitToken\s+=\s+\S+/)[0]; eval(json.match(/\S+\s+globalRepeatSubmitToken\s+=\s+\S+/)[0]); if (globalRepeatSubmitToken) { NoComplete.token = globalRepeatSubmitToken; } NoComplete.getOrder(); }).fail(function() { Public.hideLoading(); Public.alert("12306不给力啊,唉。出现网络错误了,请重试.."); }); }, setHtml: function(list) { var html = "", payLimitTime = 0; for (var i = 0, len = list.length; i < len; i++) { html += '
订单号:' + list[i]['sequence_no'] + '
'; html += '
'; payLimitTime = new Date(list[i]['tickets'][0]['pay_limit_time'].replace(/\-/gi,'/')).getTime(); if(!isNaN(payLimitTime)){ payLimitTime = new Date(list[i]['order_date'].replace(/\-/gi,'/')).getTime() + 2700000; } for (var j = 0; j < list[i]['tickets'].length; j++) { html += '
'; html += '
K2341' + (new Date(list[i]['start_train_date_page'].replace(/\-/gi, '/'))).format('yyyy-M-d') + ' ' + (new Date(list[i]['start_train_date_page'].replace(/\-/gi, '/'))).day(3) + '
'; html += '
'; html += '
' + list[i]['from_station_name_page'][0] + '' + list[i]['start_time_page'] + '
'; html += '
' + list[i]['to_station_name_page'][0] + '' + list[i]['arrive_time_page'] + '
'; html += '
'; html += '
'; html += '' + list[i]['tickets'][j]['passengerDTO']['passenger_name'] + ''; html += '' + list[i]['tickets'][j]['passengerDTO']['passenger_id_no'] + ''; html += '
'; html += '
' + list[i]['tickets'][j]['str_ticket_price_page'] + '元'; html += list[i]['tickets'][j]['ticket_type_name']; html += ' ' + list[i]['tickets'][j]['seat_type_name']; html += ' ' + list[i]['tickets'][j]['coach_name'] + '车'; html += list[i]['tickets'][j]['seat_name']; html += '
'; html += '
'; // html += '

' + list[i]['tickets'][j]['passengerDTO']['passenger_name'] + // ' ' + list[i]['tickets'][j]['ticket_type_name'] + // ' ' + list[i]['tickets'][j]['seat_type_name'] + // ' ' + list[i]['tickets'][j]['seat_name'] + // ' ' + list[i]['tickets'][j]['str_ticket_price_page'] + '

'; // html += '

支付

' }; html += '
'; html += '
'; html += '

席位已成功锁定,请您在内进行网上支付,否则席位将自动释放给其他旅客。

'; html += '
立即支付' + list[i]['ticket_total_price_page'] + '元
' html += '
'; // html += '

订单日期:' + list[i]['order_date'] + '

'; // html += '

发车时间:' + list[i]['start_train_date_page'] + '

'; // html += '

车次:' + list[i]['train_code_page'] + '

'; // html += '

发到站:' + list[i]['from_station_name_page'][0] + ' dao ' + list[i]['to_station_name_page'][0] + '

'; // html += '

金额:' + list[i]['ticket_total_price_page'] + '

'; // for (var j = 0; j < list[i]['tickets'].length; j++) { // html += '

' + list[i]['tickets'][j]['passengerDTO']['passenger_name'] + // ' ' + list[i]['tickets'][j]['ticket_type_name'] + // ' ' + list[i]['tickets'][j]['seat_type_name'] + // ' ' + list[i]['tickets'][j]['seat_name'] + // ' ' + list[i]['tickets'][j]['str_ticket_price_page'] + '

'; // html += '

支付

' // }; }; $('#orders').html(html); NoComplete.countdown(); }, countdown: function() { $('[data-limittime]').each(function(idx, el) { var $this = $(el), order = $this.attr('data-orderno'), time = (new Date(parseInt($this.attr('data-limittime')))).getTime() - (new Date()).getTime(); if (time <= 0) { $this.closest('p').html('订单已过期'); $('[data-no="' + order + '"').html('订单已过期').addClass('btn_gray'); } else { $this.html(NoComplete.gm(time)); $('.pay_tip_info .text_warning').html(NoComplete.gm(time)); } }); setTimeout(NoComplete.countdown, 1000); }, gm: function(n) { var m = parseInt(n / 60000), s = parseInt(n % 60000 / 1000); if (m < 10) { m = '0' + m; } if (s < 10) { s = '0' + s; } return m + ':' + s; }, selectBank: function() { // $('#banks').show(); Public.showInnerPage('banks'); }, pay: function(no, type) { var data = { "sequence_no": NoComplete.curNo, "pay_flag": 'pay', "_json_att": "", "REPEAT_SUBMIT_TOKEN": NoComplete.token } $('span', NoComplete.payLoading).html('正在获取支付信息'); bootStrap.post('queryOrder/continuePayNoCompleteMyOrder', 'json', data, "queryOrder/initNoComplete").done(function(response) { if (response.status) { if (response.data.existError == "Y") { Public.alert(response.data.errorMsg); } else { bootStrap.post('payOrder/paycheck', 'json', { "_json_att": "" }, "payOrder/init").done(function(json) { NoComplete.submitPay(json['data']['payForm']); }).fail(function() { Public.alert("12306不给力啊,唉。出现网络错误了,请重试.."); }); } } }).fail(function() { Public.alert("12306不给力啊,唉。出现网络错误了,请重试.."); }); }, analyzeFormData: function(text) { var data = {}; var reg = //g; var m = null; while ((m = reg.exec(text)) != null) { if (m[1] == "name") data[m[2]] = m[4]; else data[m[4]] = m[2]; } return data; }, submitPay: function(formdata) { var data = { "_json_att": '', "interfaceName": formdata['interfaceName'], "interfaceVersion": formdata['interfaceVersion'], "tranData": formdata["tranData"], "merSignMsg": formdata["merSignMsg"], "appId": formdata['appId'], "transType": formdata['transType'] } $('span', NoComplete.payLoading).html('正在提交支付请求'); bootStrap.post('https://epay.12306.cn/pay/payGateway', 'html', data, "payOrder/init").done(function(html) { var data = NoComplete.analyzeFormData(html); data.bankId = NoComplete.bankId; bootStrap.post('https://epay.12306.cn/pay/webBusiness', 'html', data, "https://epay.12306.cn/pay/payGateway").done(function(result) { var formdata = NoComplete.analyzeFormData(result); var htmlbank = result.replace(/[\n\t\r]/gi, '').replace(/>\s+<').match(//gi); if (htmlbank.length > 0) { $('span', NoComplete.payLoading).html('正在向银行提交支付请求'); $('#hideHtml').html(htmlbank[0]); // if(NoComplete.bankId == "03080000"){ // $('form[name="myform"]').attr('action','https://netpay.cmbchina.com/netpayment/BaseHttp.dll?MB_Pay_FromPC'); // } setTimeout(function() { Public.hideLoading(NoComplete.payLoading); $('form[name="myform"]').submit(); }, 1000); } }).fail(function() { }); }).fail(function() { Public.alert("12306不给力啊,唉。出现网络错误了,请重试.."); }); }, cancelOrder:function(order,success,error){ var cancel_loading = Public.showLoading('正在取消订单...'), data = { 'sequence_no':order, 'cancel_flag':'cancel_order', '_json_att':'' }; bootStrap.post('queryOrder/cancelNoCompleteMyOrder', 'json', data, "queryOrder/initNoComplete").done(function(json) { Public.hideLoading(cancel_loading); if(json['status'] && json['data']['existError'] == "N"){ Public.alert('取消订单成功!',function(){ if(typeof success == "function"){ success(); } }); }else{ var text = ''; if(json['messages'].length > 0){ text = json['messages'][0]; } if(!text){ text = '取消订单失败,请重试!'; } Public.alert(text,function(){ if(typeof error == "function"){ error(); } }); } }).fail(function() { Public.hideLoading(cancel_loading); Public.alert('网络连接失败,请重试!',function(){ if(typeof error == "function"){ error(); } }); }); } }