2014-06-20 20:55:14 +08:00
|
|
|
|
define(function (require) {
|
2014-05-05 19:34:47 +08:00
|
|
|
|
var param = require("../data.js");
|
|
|
|
|
var ajax = require("../platform/webRequest.js");
|
|
|
|
|
var storage = require('../platform/storage.js');
|
|
|
|
|
var widget = require("./widget.js");
|
2014-05-29 19:41:38 +08:00
|
|
|
|
var sessMgr = require("../account/sessionMgr.js");
|
2014-06-12 21:36:05 +08:00
|
|
|
|
var mp = require("./widget_message_popup.js");
|
2014-07-04 20:57:57 +08:00
|
|
|
|
var datebar = require("./widget_datebar.js");
|
|
|
|
|
var parser = require("../platform/parser.js");
|
2014-05-05 19:34:47 +08:00
|
|
|
|
|
2014-06-26 22:24:54 +08:00
|
|
|
|
//会话管理器事件
|
|
|
|
|
sessMgr.on("notValidPassengerFound", function () {
|
|
|
|
|
mp.showMessagePopup("warn", "您的账户中有未经验证的联系人,将不可为他们订票。");
|
|
|
|
|
});
|
|
|
|
|
|
2014-05-05 19:34:47 +08:00
|
|
|
|
//初始化日期
|
|
|
|
|
require("./widget_datedropdown.js").init("input.ui-date");
|
2014-06-26 22:24:54 +08:00
|
|
|
|
//地区选择
|
2014-07-08 20:11:31 +08:00
|
|
|
|
var citySelector = require("./widget_cityselector.js");
|
|
|
|
|
citySelector.init("input.ui-cityselector");
|
2014-06-26 22:24:54 +08:00
|
|
|
|
//验证码
|
2014-06-12 21:36:05 +08:00
|
|
|
|
require("./widget_verifycode.js").init();
|
2014-05-05 19:34:47 +08:00
|
|
|
|
|
2014-06-26 22:24:54 +08:00
|
|
|
|
//登录
|
2014-05-16 20:10:45 +08:00
|
|
|
|
var ui_login = require("./ui-login.js");
|
2014-06-26 22:24:54 +08:00
|
|
|
|
ui_login.init();
|
|
|
|
|
//结果列表
|
|
|
|
|
var ui_result = require("./ui-trainlist.js");
|
|
|
|
|
ui_result.init();
|
|
|
|
|
|
|
|
|
|
//提交订单
|
|
|
|
|
var uiOrderProcess = require("./ui-order-submit-process.js");
|
|
|
|
|
uiOrderProcess.init();
|
|
|
|
|
|
2014-07-08 20:11:31 +08:00
|
|
|
|
//查询参数
|
|
|
|
|
var uiAutoSubmitForm = require("./ui-autosubmitform.js");
|
|
|
|
|
uiAutoSubmitForm.init();
|
|
|
|
|
|
2014-07-04 20:57:57 +08:00
|
|
|
|
//模式管理
|
|
|
|
|
var uiThemeManager = require("./ui-theme-manager.js");
|
|
|
|
|
uiThemeManager.init();
|
|
|
|
|
|
2014-06-26 22:24:54 +08:00
|
|
|
|
|
|
|
|
|
//订票列表交互
|
|
|
|
|
(function () {
|
|
|
|
|
ui_result.on("requireSubmitOrder", function (e, d) {
|
2014-06-27 22:25:42 +08:00
|
|
|
|
uiOrderProcess.start(d.train, d.seat, sessMgr.currentProfile, null);
|
2014-06-26 22:24:54 +08:00
|
|
|
|
});
|
|
|
|
|
})();
|
|
|
|
|
|
2014-05-16 20:10:45 +08:00
|
|
|
|
|
2014-06-12 21:36:05 +08:00
|
|
|
|
//界面交互初始化
|
2014-06-20 20:55:14 +08:00
|
|
|
|
(function () {
|
|
|
|
|
var resetInterfaceByProfile = function () {
|
|
|
|
|
var user = sessMgr.current;
|
2014-06-26 22:24:54 +08:00
|
|
|
|
if (!user) {
|
2014-06-20 20:55:14 +08:00
|
|
|
|
return;
|
2014-06-26 22:24:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 20:55:14 +08:00
|
|
|
|
if (user.options.showMoreOpt !== undefined) {
|
|
|
|
|
var div = $("div.options-param");
|
2014-07-02 18:43:28 +08:00
|
|
|
|
if (user.options.showMoreOpt ^ div.is(":visible"))
|
2014-07-01 20:07:44 +08:00
|
|
|
|
!user.options.showMoreOpt ? (div.hide(), $(".search-more-option").html("显示更多选项")) : (div.show(), $(".search-more-option").html("隐藏更多选项"));
|
2014-06-20 20:55:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var p = user.currentProfile;
|
|
|
|
|
$("#from_city").val(p.fromText).attr("data-code", p.fromCode);
|
|
|
|
|
$("#to_city").val(p.toText).attr("data-code", p.toCode);
|
2014-07-02 18:43:28 +08:00
|
|
|
|
document.querySelector("input[name='ticket_type'][value='" + (p.studentTicket ? "1" : "0") + "']").checked = true;
|
2014-06-20 20:55:14 +08:00
|
|
|
|
|
|
|
|
|
$("input[data-profile-key],select[data-profile-key]").each(function () {
|
|
|
|
|
var type = this.type;
|
|
|
|
|
var value = this.value;
|
|
|
|
|
var svalue = p[this.dataset.profileKey];
|
|
|
|
|
|
2014-06-26 22:24:54 +08:00
|
|
|
|
if (typeof (svalue) === "undefined") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 20:55:14 +08:00
|
|
|
|
if (type === "checkbox")
|
2014-07-02 18:43:28 +08:00
|
|
|
|
this.checked = svalue == value;
|
2014-06-20 20:55:14 +08:00
|
|
|
|
else if (type === "radio") {
|
|
|
|
|
this.checked = svalue == value;
|
|
|
|
|
} else {
|
|
|
|
|
$(this).val(svalue);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-07-04 20:57:57 +08:00
|
|
|
|
|
|
|
|
|
//当前日期
|
|
|
|
|
if (p.depDate) {
|
|
|
|
|
var d = parser.addDays(parser.toDate(p.depDate), 0);
|
|
|
|
|
var today = parser.addDays(new Date(), 0);
|
|
|
|
|
d = d < today ? today : d;
|
|
|
|
|
|
|
|
|
|
var datestr = parser.formatDate(d, "yyyy-MM-dd");
|
|
|
|
|
datebar.go(d, d);
|
|
|
|
|
$("#dep_date").val(datestr);
|
|
|
|
|
}
|
2014-06-20 20:55:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$("#index-tip-body").click(function () {
|
2014-06-12 21:36:05 +08:00
|
|
|
|
$(this).next().fadeIn();
|
|
|
|
|
});
|
2014-06-20 20:55:14 +08:00
|
|
|
|
$("section.search-tips-container i.fa-times").click(function () {
|
2014-06-12 21:36:05 +08:00
|
|
|
|
$(this).closest("section.search-tips-container").fadeOut();
|
|
|
|
|
});
|
|
|
|
|
//登录失效
|
2014-06-20 20:55:14 +08:00
|
|
|
|
sessMgr.on("userForcedOut", function () {
|
2014-06-12 21:36:05 +08:00
|
|
|
|
mp.showMessagePopup("error", "您的登录出现了问题,请重新登录");
|
|
|
|
|
});
|
2014-06-20 20:55:14 +08:00
|
|
|
|
$(".search-more-option").click(function () {
|
2014-06-13 19:52:22 +08:00
|
|
|
|
var div = $("div.options-param");
|
|
|
|
|
div.is(":visible") ? (div.hide(), $(this).html("显示更多选项")) : (div.show(), $(this).html("隐藏更多选项"));
|
2014-06-20 20:55:14 +08:00
|
|
|
|
sessMgr.current.options.showMoreOpt = div.is(":visible");
|
|
|
|
|
sessMgr.save();
|
|
|
|
|
});
|
|
|
|
|
$("#from_city").change(function () {
|
|
|
|
|
var u = sessMgr.current;
|
|
|
|
|
var p = u.currentProfile;
|
|
|
|
|
p.fromText = this.value;
|
|
|
|
|
p.fromCode = this.dataset.code;
|
|
|
|
|
sessMgr.save();
|
|
|
|
|
});
|
|
|
|
|
$("#to_city").change(function () {
|
|
|
|
|
var u = sessMgr.current;
|
|
|
|
|
var p = u.currentProfile;
|
|
|
|
|
p.toText = this.value;
|
|
|
|
|
p.toCode = this.dataset.code;
|
|
|
|
|
sessMgr.save();
|
2014-06-13 19:52:22 +08:00
|
|
|
|
});
|
2014-07-04 20:57:57 +08:00
|
|
|
|
$("input[name='ticket_type']").click(function () {
|
2014-07-02 18:43:28 +08:00
|
|
|
|
sessMgr.currentProfile.studentTicket = this.value === "1";
|
|
|
|
|
sessMgr.save();
|
|
|
|
|
});
|
2014-06-20 20:55:14 +08:00
|
|
|
|
$(document).on("change", "input[data-profile-key],select[data-profile-key]", function () {
|
|
|
|
|
var u = sessMgr.current;
|
|
|
|
|
var p = u.currentProfile;
|
|
|
|
|
var type = this.type;
|
|
|
|
|
var key = this.dataset.profileKey;
|
|
|
|
|
|
|
|
|
|
if (type === "radio") {
|
|
|
|
|
var checked = $("input:radio[name=" + this.getAttribute("name") + "]:checked").val();
|
|
|
|
|
switch (typeof (p[key])) {
|
|
|
|
|
case "number":
|
|
|
|
|
p[key] = parseInt(checked);
|
|
|
|
|
break;
|
|
|
|
|
case "boolean":
|
|
|
|
|
p[key] = checked == 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
p[key] = checked;
|
|
|
|
|
}
|
|
|
|
|
} else if (type === "checkbox") {
|
2014-07-02 18:43:28 +08:00
|
|
|
|
p[key] = this.checked ? this.value : null;
|
2014-06-20 20:55:14 +08:00
|
|
|
|
} else {
|
|
|
|
|
p[key] = $(this).val();
|
|
|
|
|
}
|
|
|
|
|
sessMgr.save();
|
|
|
|
|
});
|
|
|
|
|
$("#btnQuery").click(function () {
|
2014-07-08 20:11:31 +08:00
|
|
|
|
//记录
|
|
|
|
|
citySelector.cityui.addCityToRecent(sessMgr.currentProfile.fromCode);
|
|
|
|
|
citySelector.cityui.addCityToRecent(sessMgr.currentProfile.toCode);
|
2014-07-02 18:43:28 +08:00
|
|
|
|
ui_result.load();
|
2014-06-20 20:55:14 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sessMgr.on("sessionChanged", resetInterfaceByProfile);
|
2014-07-04 20:57:57 +08:00
|
|
|
|
sessMgr.on("currentProfileChanged", resetInterfaceByProfile);
|
2014-06-20 20:55:14 +08:00
|
|
|
|
//初始化状态
|
|
|
|
|
resetInterfaceByProfile();
|
2014-06-12 21:36:05 +08:00
|
|
|
|
})();
|
|
|
|
|
|
2014-07-01 20:07:44 +08:00
|
|
|
|
//系统级别错误捕捉
|
2014-07-02 18:43:28 +08:00
|
|
|
|
(function () {
|
2014-07-01 20:07:44 +08:00
|
|
|
|
document.addEventListener("networkOrCertificationError", function () {
|
|
|
|
|
//TODO UI
|
|
|
|
|
alert("无法访问12306,可能是网络错误或证书错误,请直接访问12306试试!如果正常的话请回来刷新本页!");
|
|
|
|
|
});
|
|
|
|
|
})();
|
|
|
|
|
|
2014-05-27 19:40:21 +08:00
|
|
|
|
//初始化
|
2014-06-20 20:55:14 +08:00
|
|
|
|
$("#J-search-form").submit(function () {
|
2014-05-27 19:40:21 +08:00
|
|
|
|
return false;
|
|
|
|
|
});
|
2014-05-05 19:34:47 +08:00
|
|
|
|
});
|