Light12306/Web12306/js/ui/ui-trainlist.js

96 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-06-26 22:24:54 +08:00
define(function (require, exports, module) {
var queryResult = null;
var param = require("../data.js");
var tpl = $("#train_table").doT();
var sessMgr = require("../account/sessionMgr.js");
var ticketQuery = require("./../otn/queryticket.js");
var EventObject = require("../platform/EventObject.js");
2014-07-01 20:07:44 +08:00
var mp = require("./widget_message_popup.js");
var tsquery = require("./ui-train-stop.js");
var datebar = require("./widget_datebar.js");
2014-07-04 20:57:57 +08:00
var parser = require("../platform/parser.js");
var autorefresh = require("./ui-autorefresh.js");
2014-06-26 22:24:54 +08:00
var TrainListObj = function () {
var __ = this;
EventObject.apply(this);
this.renderResultList = function (data) {
data = data || queryResult;
$("#result").html(tpl(data, {
2014-07-04 20:57:57 +08:00
param: param,
parser: parser
2014-06-26 22:24:54 +08:00
}));
};
this.load = function (ui, from, to, date, stu) {
ui = ui === undefined ? true : ui;
2014-07-11 18:34:59 +08:00
from = from || sessMgr.currentProfile.fromCode;
to = to || sessMgr.currentProfile.toCode;
date = date || sessMgr.currentProfile.depDate;
stu = stu || sessMgr.currentProfile.studentTicket;
var extArg = Array.prototype.slice.call(arguments);
__.fireEvent("onload", extArg);
datebar.go(date, date);
2014-07-01 20:07:44 +08:00
var tip = null;
if (ui) {
tip = new mp.MessagePopup("loading", "正在查询中...");
tip.show();
}
2014-06-26 22:24:54 +08:00
ticketQuery
.queryTicket(from, to, date, stu)
.done(function () {
2014-07-01 20:07:44 +08:00
if (tip) {
tip.setState("ok", "完成...");
tip.close();
}
2014-06-26 22:24:54 +08:00
queryResult = this;
__.renderResultList();
__.fireEvent("onloadsuccess", extArg);
2014-06-26 22:24:54 +08:00
}).fail(function () {
2014-07-01 20:07:44 +08:00
tip.setState("error", "查票失败...");
tip.delayClose();
__.fireEvent("onloadfailed", extArg);
2014-06-26 22:24:54 +08:00
});
};
this.init = function () {
2014-07-01 20:07:44 +08:00
tsquery.init();
datebar.init();
2014-07-04 20:57:57 +08:00
datebar.on("requireChangeDate", function (e, d) {
autorefresh.stop();
//请求切换时间
2014-07-04 20:57:57 +08:00
$("#dep_date").val(d).change();
sessMgr.save();
__.load();
});
2014-06-26 22:24:54 +08:00
};
//监听订票请求
2014-07-01 20:07:44 +08:00
$(document).on("click", "a.ticket-block", function () {
2014-06-26 22:24:54 +08:00
var id = this.dataset.traincode;
var seatcode = this.dataset.seatcode;
var train = _.findWhere(queryResult.original, { id: id });
if (!train)
return;
__.dispatchEvent("requireSubmitOrder", {
train: train,
seat: seatcode
});
});
return this;
};
TrainListObj.prototype = Object.create(EventObject);
TrainListObj.constructor = TrainListObj;
module.exports = new TrainListObj();
});