diff --git a/Web12306/Web12306.csproj b/Web12306/Web12306.csproj index ba2f0df..2affff8 100644 --- a/Web12306/Web12306.csproj +++ b/Web12306/Web12306.csproj @@ -176,6 +176,7 @@ + diff --git a/Web12306/index.html b/Web12306/index.html index 4a569f1..067fe6b 100644 --- a/Web12306/index.html +++ b/Web12306/index.html @@ -88,7 +88,7 @@
  • - +
  • @@ -409,7 +409,7 @@
    提交订单
    -

    +

    换一张 diff --git a/Web12306/js/otn/orderprocess.js b/Web12306/js/otn/orderprocess.js new file mode 100644 index 0000000..5f8a3d9 --- /dev/null +++ b/Web12306/js/otn/orderprocess.js @@ -0,0 +1,38 @@ +define(function (require, exports, module) { + var ajax = require("../platform/webRequest.js"); + var parser = require("../platform/parser.js"); + + var submitToken; + + exports.prepareOrder = function (train, profile) { + var purposeCode = profile.studentTicket ? "0X00" : "ADULT"; + var data = "secretStr" + "=" + train.secureStr + "&train_date=" + train.date + "&back_train_date" + "=" + (profile.resign ? profile.resignDate : train.date) + "&tour_flag" + "=" + (profile.resign ? "gc" : "dc") + "&" + + "purpose_codes" + "=" + purposeCode + "&" + + "query_from_station_name" + "=" + train.from.code + "&" + + "query_to_station_name" + "=" + train.to.code + "&" + (ajax.userAtts ? "_json_att=" + ajax.userAtts : "undefined"); + + var def = new $.Deferred(); + ajax.sendPost("leftTicket/submitOrderRequest", "leftTicket/init", data, "json", function (data) { + if (!data.status) { + def.reject({ msg: parser.getError(data).message }); + } else { + ajax.sendPost(profile.resign ? "confirmPassenger/initGc" : "confirmPassenger/initDc", "leftTicket/init", null, "text", function (html) { + var token = /var\s*globalRepeatSubmitToken\s*=\s*['"]([^'"]+)["']/i.exec(html) && RegExp.$1; + if (token) { + submitToken = token; + def.resolve({ token: token }); + } else { + submitToken = null; + def.reject({ msg: "12306返回的信息无法识别,请重试..." }); + } + }, function () { + def.reject({ msg: "12306不给力唷,请尽快重试..." }); + }, true); + } + }, function () { + def.reject({ msg: "12306不给力唷,请尽快重试..." }); + }); + + return def; + }; +}); diff --git a/Web12306/js/otn/queryticket.js b/Web12306/js/otn/queryticket.js index f2864b3..7390f23 100644 --- a/Web12306/js/otn/queryticket.js +++ b/Web12306/js/otn/queryticket.js @@ -79,7 +79,8 @@ supportCard: t.queryLeftNewDTO.is_support_card, saleTime: t.queryLeftNewDTO.sale_time, secureStr: t.secretStr, - selltime: null + selltime: null, + date: t.queryLeftNewDTO.start_train_date.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3") }; var kp = getTicketInfo(t.queryLeftNewDTO.yp_info); train.tickets = kp; diff --git a/Web12306/js/platform/extensionPort.js b/Web12306/js/platform/extensionPort.js index 7a169ac..aa31b07 100644 --- a/Web12306/js/platform/extensionPort.js +++ b/Web12306/js/platform/extensionPort.js @@ -7,4 +7,4 @@ chrome.runtime.sendMessage(exports.targetId, m, response || function () { }); }; -}); +}); \ No newline at end of file diff --git a/Web12306/js/platform/webRequest.js b/Web12306/js/platform/webRequest.js index a4495e8..625fe3a 100644 --- a/Web12306/js/platform/webRequest.js +++ b/Web12306/js/platform/webRequest.js @@ -16,17 +16,17 @@ define(function (require, exports, module) { if (url[4] === ":" || url[5] === ":") return url; return config.baseUri + url; }; - this.send = function (method, url, refer, data, responseType, done, failed, ignoreGlobalAtt) { - if (!ignoreGlobalAtt && jsonAtt) { + this.send = function (method, url, refer, data, responseType, done, failed, appendatt) { + if (appendatt) { data = $.extend({ - _json_att: jsonAtt + _json_att: jsonAtt || "" }, data); } var xhrData = { url: that.getFullUri(url), data: data, timeout: 120000, - type: "GET", + type: method, dataType: responseType, refer: that.getFullUri(refer) }; @@ -54,7 +54,7 @@ define(function (require, exports, module) { document.dispatchEvent(new CustomEvent("requestSupportError")); } }; - this.sendGet = function (url, refer, data, responseType, done, failed) { + this.sendGet = function (url, refer, data, responseType, done, failed, appendatt) { ///

    以GET模式发送AJAX请求 /// 要请求的地址 /// 请求的引用地址 @@ -62,10 +62,10 @@ define(function (require, exports, module) { /// 要请求的地址 /// 完成请求的回调 /// 请求失败的回调 - that.send("GET", url, refer, data, responseType, done, failed); + that.send("GET", url, refer, data, responseType, done, failed, appendatt); }; - this.sendPost = function (url, refer, data, responseType, done, failed) { - that.send("POST", url, refer, data, responseType, done, failed); + this.sendPost = function (url, refer, data, responseType, done, failed, appendatt) { + that.send("POST", url, refer, data, responseType, done, failed, appendatt); }; document.addEventListener("ajaxproxyfinished", function (e) { @@ -75,7 +75,7 @@ define(function (require, exports, module) { var param = requestMap[data.index]; delete requestMap[data.index]; - data.success ? param.done.call(data) : param.fail.call(data); + data.success ? param.done.call(data, data.model) : param.fail.call(data, data.model); }); Object.defineProperties(this, { diff --git a/Web12306/js/ui/index.js b/Web12306/js/ui/index.js index 82650b2..1562c59 100644 --- a/Web12306/js/ui/index.js +++ b/Web12306/js/ui/index.js @@ -50,7 +50,7 @@ //订票列表交互 (function () { ui_result.on("requireSubmitOrder", function (e, d) { - uiOrderProcess.start(d.train, d.seat, sessMgr.currentProfile.studentTicket, null); + uiOrderProcess.start(d.train, d.seat, sessMgr.currentProfile, null); }); })(); @@ -152,7 +152,7 @@ sessMgr.save(); }); $("#btnQuery").click(function () { - ui_result.load($("#from_city").attr("data-code"), $("#to_city").attr("data-code"), $("#dep_date").val()); + ui_result.load($("#from_city").attr("data-code"), $("#to_city").attr("data-code"), $("#dep_date").val(), sessMgr.currentProfile.studentTicket); }); diff --git a/Web12306/js/ui/ui-order-submit-process.js b/Web12306/js/ui/ui-order-submit-process.js index 135308b..42f65b9 100644 --- a/Web12306/js/ui/ui-order-submit-process.js +++ b/Web12306/js/ui/ui-order-submit-process.js @@ -4,9 +4,13 @@ var param = require("../data.js"); var ui_login = require("./ui-login.js"); var sessMgr = require("../account/sessionMgr.js"); + var mp = require("./widget_message_popup.js"); + var op = require("../otn/orderprocess.js"); + + //标记位 //提交参数 - var pTrain, pSeat, pStu, pPassengers; + var pTrain, pSeat, pStu, pPassengers, pProfile; exports.init = function () { ps.init(); @@ -18,11 +22,12 @@ }); }; - exports.start = function (train, seat, stu, passengers) { + exports.start = function (train, seat, profile, passengers) { if (train) { pTrain = train; pSeat = seat; - pStu = stu; + pProfile = profile; + pStu = profile.studentTicket; pPassengers = passengers; } if (!pTrain) @@ -34,11 +39,21 @@ return; } - if (!pPassengers || !pPassengers.length) - exports.showPassengerSelectUi(); - else { - exports.showConfirmOrderUi(); - } + var tip = new mp.MessagePopup("loading", "正在准备提交订单,请稍等..."); + tip.show(); + var def = op.prepareOrder(train, pProfile); + + def.done(function () { + if (!pPassengers || !pPassengers.length) + exports.showPassengerSelectUi(); + else { + exports.showConfirmOrderUi(); + } + tip.close(); + }).fail(function (data) { + tip.setState("error", data.msg); + tip.delayClose(); + }); }; @@ -52,7 +67,7 @@ }; exports.showConfirmOrderUi = function () { - so.showOrderUi(pTrain, pSeat, pStu, pPassengers); + so.showOrderUi(pTrain, pSeat, pProfile, pPassengers); }; exports.showSuccessUi = function () { diff --git a/Web12306/js/ui/ui-submit-order.js b/Web12306/js/ui/ui-submit-order.js index 11ed0af..d81bdc7 100644 --- a/Web12306/js/ui/ui-submit-order.js +++ b/Web12306/js/ui/ui-submit-order.js @@ -1,16 +1,45 @@ define(function(require, exports, module) { var EventObject = require("../platform/EventObject.js"); var widget = require("./widget.js"); + var vc_inited = false; + var mp = require("./widget_message_popup.js"); + var op = require("../otn/orderprocess.js"); + var vc = require("./widget_verifycode.js"); + //提交参数 + var pTrain, pSeat, pStu, pPassengers, pProfile; var SubmitOrderUi = function() { var that = this; EventObject.apply(this); this.init = function() { - + $("#ticket-submit-info .ticket-submit-vc input:text").click(function() { + if (this.value.length === 4) + that.submitOrder(); + }); + $("#ticket-submit-info button.button-primary").click(that.submitOrder); }; - this.showOrderUi = function(train, passenger) { + this.showOrderUi = function (train, seat, profile, passengers) { + if (train) { + pTrain = train; + pSeat = seat; + pProfile = profile; + pStu = profile.studentTicket; + pPassengers = passengers; + } + if (!pTrain) + return; + widget.showFloatDialog($("#ticket-submit-container")); + if (!vc_inited) { + vc_inited = true; + vc.load($("#ticket-submit-info .ticket-submit-vc")); + } else { + $("#ticket-submit-info .ticket-submit-vc img").click(); + } + }; + this.submitOrder = function() { + }; return this; diff --git a/Web12306/js/ui/widget_message_popup.js b/Web12306/js/ui/widget_message_popup.js index 332a287..6d88314 100644 --- a/Web12306/js/ui/widget_message_popup.js +++ b/Web12306/js/ui/widget_message_popup.js @@ -39,10 +39,11 @@ }); }; this.delayClose = function (timeout) { + timeout = timeout || options.closeAfter || 1500; if (that.shown) - setTimeout(that.close, timeout || options.closeAfter); + setTimeout(that.close, timeout); else { - options.closeAfter = timeout || options.closeAfter || 1000; + options.closeAfter = timeout; } }; that.setState = function (type, content) { diff --git a/Web12306/js/ui/widget_verifycode.js b/Web12306/js/ui/widget_verifycode.js index 900ded8..a47d1e8 100644 --- a/Web12306/js/ui/widget_verifycode.js +++ b/Web12306/js/ui/widget_verifycode.js @@ -7,8 +7,8 @@ refer: "login/init" }, order: { - url: "", - refer: "" + url: "passcodeNew/getPassCodeNew?module=passenger&rand=randp&_="+Math.random(), + refer: "confirmPassenger/initDc" } }; exports.autoLoad = function(target) {