diff --git a/Web12306/Web12306.csproj b/Web12306/Web12306.csproj index e206c39..1bcf713 100644 --- a/Web12306/Web12306.csproj +++ b/Web12306/Web12306.csproj @@ -190,6 +190,7 @@ + diff --git a/Web12306/css/ui/city-selector.css b/Web12306/css/ui/city-selector.css index f8ff92c..d06c8b3 100644 --- a/Web12306/css/ui/city-selector.css +++ b/Web12306/css/ui/city-selector.css @@ -61,6 +61,8 @@ background-color: #f9f8f3; text-align: center; cursor: pointer; + margin-right: 5px; + margin-top: 3px; } #city_selector .recent-city-list dd:hover { @@ -68,10 +70,6 @@ color: #ffffff; } - #city_selector .recent-city-list dd + dd { - margin-left: 7px; - } - #city_selector .city-list-container { margin: 0 auto 50px auto; overflow: hidden; diff --git a/Web12306/css/ui/options-param.css b/Web12306/css/ui/options-param.css index 863a270..d5eb2d2 100644 --- a/Web12306/css/ui/options-param.css +++ b/Web12306/css/ui/options-param.css @@ -1,75 +1,139 @@ -/*其他筛选条件*/ -.options-param { - padding: 0 10px; - border: 1px solid #e1e1e1; - border-radius: 4px; - font-size: 14px; - color: #000000; - position: relative; -} - - .options-param dt { - height: 36px; - line-height: 36px; - float: left; - } - - .options-param dd { - width: 825px; - } - - .options-param .split { - height: 1px; - overflow: hidden; - border-bottom: 1px dotted #d6d6d6; - } - - .options-param dt { - margin-left: 36px; - } - - .options-param .options-input { - width: 156px; - height: 36px; - padding: 0 30px 0 10px; - -webkit-appearance: none; - border: none; - background: url(../../images/css-sprite.png) no-repeat transparent; - background-position: -24px -32px; - } - - .options-param .options-input:focus, - .options-param .options-input.focused { - background-position: -227px -32px; - } - - .options-param .optional-block { - background: #fff; - height: 34px; - line-height: 34px; - border: 1px solid #d3d3d3; - border-radius: 2px; - display: inline-block; - position: relative; - padding: 0 34px 0 14px; - margin-bottom: 10px; - } - .options-param .optional-block:hover { - background: #f9f9f9; - cursor: pointer; - } - .options-param .optional-block .close { - font-size: 13px; - font-family: arial; - position: absolute; - top: -1px; - right: 10px; - cursor: pointer; - padding: 0 4px; - } - .options-param .optional-block .close:hover { - color: #ff6a00; - } - .options-param .options-seat-type { - line-height: 34px; - } +/*其他筛选条件*/ +.options-param { + padding: 0 10px; + border: 1px solid #e1e1e1; + border-radius: 4px; + font-size: 14px; + color: #000000; + position: relative; +} + + .options-param dt { + height: 36px; + line-height: 36px; + float: left; + } + + .options-param dd { + } + + .options-param .split { + height: 1px; + overflow: hidden; + border-bottom: 1px dotted #d6d6d6; + } + + .options-param dt { + margin-left: 36px; + } + + .options-param .options-input { + width: 156px; + height: 36px; + padding: 0 30px 0 10px; + -webkit-appearance: none; + border: none; + background: url(../../images/css-sprite.png) no-repeat transparent; + background-position: -24px -32px; + } + + .options-param .options-input:focus, + .options-param .options-input.focused { + background-position: -227px -32px; + } + + .options-param .optional-block { + background: #fff; + height: 34px; + line-height: 34px; + border: 1px solid #d3d3d3; + border-radius: 2px; + display: inline-block; + position: relative; + padding: 0 34px 0 14px; + margin-right: 5px; + } + + .options-param .optional-block:hover { + background: #f9f9f9; + cursor: pointer; + } + + .options-param .optional-block .close { + font-size: 13px; + font-family: arial; + position: absolute; + top: -1px; + right: 10px; + cursor: pointer; + padding: 0 4px; + } + + .options-param .optional-block .close:hover { + color: #ff6a00; + } + + .options-param .options-seat-type { + line-height: 34px; + } + + .options-param .options-seat-type ul { + position: absolute; + z-index: 10; + background-color: #fff; + width: 300px; + border-radius: 0 5px 5px 5px; + border: 1px solid #ccc; + box-shadow: 5px 5px 10px rgba(150,150,150,0.3); + left: 107px; + display: none; + } + + .options-param .options-seat-type ul li { + float: left; + width: 100px; + } + .options-param .options-seat-type ul li.recommand { + font-weight: bold; + color: #ff6a00; + } + + .options-param .options-train-selectorwarp { + position: relative; + } + + .options-param .options-train-selectorwarp div { + border: 1px solid #d1d1d1; + position: absolute; + left: 65px; + top: 35px; + z-index: 10; + background: #ffffff; + border-radius: 0 5px 5px 5px; + box-shadow: 5px 5px 10px rgba(150, 150, 150, 0.5); + color: #7a7a7a; + display: none; + max-height: 300px; + overflow-y: auto; + overflow-x: visible; + width: 520px; + } + + .options-param .options-train-selectorwarp table { + width: 500px; + } + + .options-param .options-train-selectorwarp table th { + line-height: 40px; + } + + .options-param .options-train-selectorwarp table tr td { + line-height: 40px; + border-top: 1px solid #d1d1d1; + padding: 0 10px 0 10px; + cursor: pointer; + } + + .options-param .options-train-selectorwarp table tr:hover td { + background-color: #fff0d9; + } diff --git a/Web12306/css/ui/passenger-selector.css b/Web12306/css/ui/passenger-selector.css index 0990954..34d0d08 100644 --- a/Web12306/css/ui/passenger-selector.css +++ b/Web12306/css/ui/passenger-selector.css @@ -1,177 +1,183 @@ -/*联系人搜索*/ - -.passenger-selector-wrap { - position: relative; - overflow: visible; - display: inline-block; -} - - .passenger-selector-wrap.hover .passenger-selector { - display: block; - } - -.passenger-selector { - position: absolute; - z-index: 100; - left: 0; - top: 35px; - box-shadow: 3px 3px 10px rgba(110, 110, 110, 0.5); - border-radius: 0 5px 5px 5px; - border: 1px solid #c7c7c7; - background-color: #ffffff; - padding: 12px; - display: none; -} - - .passenger-selector:hover { - display: block; - } - - .passenger-selector .passenger-search { - /* - TODO 这里要搜索何用? - */ - display: none; - } - - .passenger-selector .passenger-selector-add { - color: #616161; - width: 26px; - height: 26px; - background: linear-gradient(180deg, #f4f4f4, #e9e8e9); - border: 1px solid #d1d1d1; - border-radius: 2px; - cursor: pointer; - } - - .passenger-selector .passenger-selector-add:hover { - background: linear-gradient(180deg, #fefefe, #f3f3f3); - border: 1px solid #e1e1e1; - } - - .passenger-selector .passenger-selector-add:active { - background: linear-gradient(180deg, #e9e8e9, #f4f4f4); - border: 1px solid #d1d1d1; - } - - .passenger-selector .passenger-selector-add:before { - left: 7px; - top: 7px; - position: relative; - color: #616161; - } - - .passenger-selector .passenger-search div.fr:before { - position: absolute; - right: 6px; - top: 6px; - color: #6c6f83; - } - - .passenger-selector .passenger-search-key { - line-height: 16px; - padding: 4px 24px 4px 6px; - border: 1px solid #c7c7c7; - margin: 0; - width: 180px; - border-radius: 2px; - } - - .passenger-selector ul { - width: 300px; - margin-top: 12px; - border-left: 1px solid #e1e1e1; - border-top: 1px solid #e1e1e1; - } - - .passenger-selector ul li { - width: 300px; - float: left; - width: 98px; - line-height: 35px; - border-right: 1px solid #e1e1e1; - border-bottom: 1px solid #e1e1e1; - text-align: center; - color: #676767; - cursor: pointer; - position: relative; - } - - .passenger-selector ul li.selected { - border-right-color: #ebd0b3; - border-bottom-color: #ebd0b3; - background-color: #fff5e6; - color: #f2983a; - } - -#passenger-selector ul li.selected:after { - border-top: 1px solid #ebd0b3; - width: 100%; - height: 0; - position: absolute; - top: -1px; - left: 0; - content: ''; -} - -.passenger-selector ul li.selected:before { - border-left: 1px solid #ebd0b3; - height: 100%; - width: 0; - position: absolute; - top: 0; - left: -1px; - content: ''; -} - -.passenger-selector ul li:hover { - border-right-color: #e19b23; - border-bottom-color: #e19b23; - background: linear-gradient(to top, #f78c21, #fca818); - color: #fef3ea; -} - - .passenger-selector ul li:hover:after { - border-top: 1px solid #e19b23; - width: 100%; - height: 0; - position: absolute; - top: -1px; - left: 0; - content: ''; - } - - .passenger-selector ul li:hover:before { - border-left: 1px solid #e19b23; - height: 100%; - width: 0; - position: absolute; - top: 0; - left: -1px; - content: ''; - } - -.passenger-selector .passenger-pager { - margin-top: 12px; - text-align: center; - width: 100%; -} - - .passenger-selector .passenger-pager button { - line-height: 24px; - background: linear-gradient(to top, #e6e6e6, #f9f9f9); - color: #7d848d; - border: 1px solid #bdbcbc; - border-radius: 4px; - cursor: pointer; - } - - .passenger-selector .passenger-pager button:hover { - background: linear-gradient(to top, #efefef, #ffffff); - } - - .passenger-selector .passenger-pager button:disabled { - border: 1px solid transparent; - background: none transparent; - color: #9da2a8; - } +/*联系人搜索*/ + +.passenger-selector-wrap { + position: relative; + overflow: visible; + display: inline-block; +} + .passenger-selector-wrap section div.loading-indicator { + display: none; + } + + .passenger-selector-wrap section.loading ul, + .passenger-selector-wrap section.loading .passenger-pager { + display: none; + } + .passenger-selector-wrap section.loading div.loading-indicator{ + display: block; + } +.passenger-selector { + position: absolute; + z-index: 100; + left: 0; + top: 35px; + box-shadow: 3px 3px 10px rgba(110, 110, 110, 0.5); + border-radius: 0 5px 5px 5px; + border: 1px solid #c7c7c7; + background-color: #ffffff; + padding: 12px; + display: none; +} + + .passenger-selector:hover { + display: block; + } + + .passenger-selector .passenger-search { + /* + TODO 这里要搜索何用? + */ + display: none; + } + + .passenger-selector .passenger-selector-add { + color: #616161; + width: 26px; + height: 26px; + background: linear-gradient(180deg, #f4f4f4, #e9e8e9); + border: 1px solid #d1d1d1; + border-radius: 2px; + cursor: pointer; + } + + .passenger-selector .passenger-selector-add:hover { + background: linear-gradient(180deg, #fefefe, #f3f3f3); + border: 1px solid #e1e1e1; + } + + .passenger-selector .passenger-selector-add:active { + background: linear-gradient(180deg, #e9e8e9, #f4f4f4); + border: 1px solid #d1d1d1; + } + + .passenger-selector .passenger-selector-add:before { + left: 7px; + top: 7px; + position: relative; + color: #616161; + } + + .passenger-selector .passenger-search div.fr:before { + position: absolute; + right: 6px; + top: 6px; + color: #6c6f83; + } + + .passenger-selector .passenger-search-key { + line-height: 16px; + padding: 4px 24px 4px 6px; + border: 1px solid #c7c7c7; + margin: 0; + width: 180px; + border-radius: 2px; + } + + .passenger-selector ul { + width: 300px; + margin-top: 12px; + border-left: 1px solid #e1e1e1; + border-top: 1px solid #e1e1e1; + } + + .passenger-selector ul li { + width: 300px; + float: left; + width: 98px; + line-height: 35px; + border-right: 1px solid #e1e1e1; + border-bottom: 1px solid #e1e1e1; + text-align: center; + color: #676767; + cursor: pointer; + position: relative; + } + + .passenger-selector ul li.selected { + border-right-color: #ebd0b3; + border-bottom-color: #ebd0b3; + background-color: #fff5e6; + color: #f2983a; + } + +#passenger-selector ul li.selected:after { + border-top: 1px solid #ebd0b3; + width: 100%; + height: 0; + position: absolute; + top: -1px; + left: 0; + content: ''; +} + +.passenger-selector ul li.selected:before { + border-left: 1px solid #ebd0b3; + height: 100%; + width: 0; + position: absolute; + top: 0; + left: -1px; + content: ''; +} + +.passenger-selector ul li:hover { + border-right-color: #e19b23; + border-bottom-color: #e19b23; + background: linear-gradient(to top, #f78c21, #fca818); + color: #fef3ea; +} + + .passenger-selector ul li:hover:after { + border-top: 1px solid #e19b23; + width: 100%; + height: 0; + position: absolute; + top: -1px; + left: 0; + content: ''; + } + + .passenger-selector ul li:hover:before { + border-left: 1px solid #e19b23; + height: 100%; + width: 0; + position: absolute; + top: 0; + left: -1px; + content: ''; + } + +.passenger-selector .passenger-pager { + margin-top: 12px; + text-align: center; + width: 100%; +} + + .passenger-selector .passenger-pager button { + line-height: 24px; + background: linear-gradient(to top, #e6e6e6, #f9f9f9); + color: #7d848d; + border: 1px solid #bdbcbc; + border-radius: 4px; + cursor: pointer; + } + + .passenger-selector .passenger-pager button:hover { + background: linear-gradient(to top, #efefef, #ffffff); + } + + .passenger-selector .passenger-pager button:disabled { + border: 1px solid transparent; + background: none transparent; + color: #9da2a8; + } diff --git a/Web12306/index.html b/Web12306/index.html index 601a7f6..b9f5437 100644 --- a/Web12306/index.html +++ b/Web12306/index.html @@ -104,30 +104,79 @@
-
+
指定坐席:
- + + +
备选日期:
-
- - - 10月1号x - 10月1号x - 10月1号x +
+ +
添加车次:
-
- - - T12x - T2x - T3x +
+ + + +
+ + + + + + + + + + + + + + + + + + +
车次发站发时到站到时历时
+ + 正在查询中,请稍等... +
+ + 请先设置站点和日期信息,再重新查询。 +
+ + 车次查询失败,或没有查到任何车次。 +
+
@@ -144,39 +193,35 @@
-
    -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
  • 张三
  • -
+
+ + 联系人正在加载中... +
+
+ + 没有可选择的联系人。是否没有登录? +
+ +
    - - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x - 木鱼x +
    @@ -272,18 +317,18 @@ {{~}} {{?t.available==0||t.available==-1}} - {{?t.selltime}} - {{=ext.parser.formatSellDate(t.selltime)}} 起售 - {{??}} - 本车次票已售完 - {{?}} + {{?t.selltime}} + {{=ext.parser.formatSellDate(t.selltime)}} 起售 + {{??}} + 本车次票已售完 + {{?}} {{?? t.available==-2}} - 本车次不在您的选择列表中 + 本车次不在您的选择列表中 {{?}} - - {{~}} - {{?!it.original}} + + {{~}} + {{?!it.original}} 没有查询到车次,请更换条件或时间试试.. diff --git a/Web12306/js/data.js b/Web12306/js/data.js index b59722d..6837c5d 100644 --- a/Web12306/js/data.js +++ b/Web12306/js/data.js @@ -2,7 +2,7 @@ var citydata = require("./station/station_data.js"); exports.citydata = citydata; - exports.cities = _(_.flatten(_.map(_.values(data.data), function (e) { return _.values(e); }))).mapObject(function (e) { return e.c; });; + exports.cities = _(_.flatten(_.map(_.values(citydata.data), function (e) { return _.values(e); }))).mapObject(function (e) { return e.c; });; exports.identityCardTypes = { }; diff --git a/Web12306/js/ui/index.js b/Web12306/js/ui/index.js index 122c9fa..2ba7a60 100644 --- a/Web12306/js/ui/index.js +++ b/Web12306/js/ui/index.js @@ -8,15 +8,6 @@ var datebar = require("./widget_datebar.js"); var parser = require("../platform/parser.js"); - //初始化UI - (function () { - $("#passenger-selector-id").focus(function () { - $(this).parent().parent().addClass("hover"); - }).blur(function () { - $(this).parent().parent().removeClass("hover"); - }); - })(); - //会话管理器事件 sessMgr.on("notValidPassengerFound", function () { mp.showMessagePopup("warn", "您的账户中有未经验证的联系人,将不可为他们订票。"); @@ -25,7 +16,8 @@ //初始化日期 require("./widget_datedropdown.js").init("input.ui-date"); //地区选择 - require("./widget_cityselector.js").init("input.ui-cityselector"); + var citySelector = require("./widget_cityselector.js"); + citySelector.init("input.ui-cityselector"); //验证码 require("./widget_verifycode.js").init(); @@ -40,6 +32,10 @@ var uiOrderProcess = require("./ui-order-submit-process.js"); uiOrderProcess.init(); + //查询参数 + var uiAutoSubmitForm = require("./ui-autosubmitform.js"); + uiAutoSubmitForm.init(); + //模式管理 var uiThemeManager = require("./ui-theme-manager.js"); uiThemeManager.init(); @@ -162,6 +158,9 @@ sessMgr.save(); }); $("#btnQuery").click(function () { + //记录 + citySelector.cityui.addCityToRecent(sessMgr.currentProfile.fromCode); + citySelector.cityui.addCityToRecent(sessMgr.currentProfile.toCode); ui_result.load(); }); diff --git a/Web12306/js/ui/ui-autosubmitform.js b/Web12306/js/ui/ui-autosubmitform.js new file mode 100644 index 0000000..67197a5 --- /dev/null +++ b/Web12306/js/ui/ui-autosubmitform.js @@ -0,0 +1,435 @@ +define(function (require, exports, module) { + var sessmgr = require("../account/sessionMgr.js"); + var mp = require("./widget_message_popup.js"); + var query = require("../otn/queryticket.js"); + var data = require("../data.js"); + + var initPassengerEditor = function () { + //UI组件 + var uiEditor = $("div.passenger-selector-wrap"); + var uiInput = uiEditor.find(":text"); + var uiDlg = uiEditor.find("section"); + var uiDlgTpl = uiDlg.find("script").doT(); + var uiDlgList = uiDlg.find("ul"); + var uiList = uiEditor.parent(); + var uiListTpl = uiList.find(">script").doT(); + + uiInput.focus(function () { + uiDlg.show(); + + uiDlg.addClass("loading"); + uiDlg.find(".empty-indicator").hide(); + sessmgr.getPassengers(function (data) { + uiDlg.removeClass("loading"); + allpasseengers = data; + currentSearchKey = null; + if (!data.length) { + uiDlg.find(".empty-indicator").show(); + } + performSearch(); + }); + uiInput.select(); + }).blur(function () { + uiDlg.hide(); + }); + uiDlg.mousedown(function (e) { + if (e.target && e.target.tagName === "LI") { + //选定 + var id = e.target.dataset.id; + var p = _.findWhere(allpasseengers, { key: id }); + if (p) + uiInput.trigger("selectPassenger", p); + } + + e.stopPropagation(); + e.preventDefault(); + }); + + var currentSearchKey = null; + var currentList = null; + var currentPageIndex = 1; + var allpasseengers = null; + var pagesize = 12; + var totalpage = 0; + var performSearch = function (key) { + key = key || uiInput.val(); + if (key !== currentSearchKey) { + currentSearchKey = key.toUpperCase(); + currentList = currentSearchKey ? _.filter(allpasseengers, function (p) { return p.key.indexOf(currentSearchKey) != -1 || p.first_letter.indexOf(currentSearchKey) != -1; }) : allpasseengers; + currentPageIndex = 1; + totalpage = Math.ceil(currentList.length / pagesize); + } + renderPage(); + }; + var renderPage = function () { + if (currentPageIndex > totalpage) + currentPageIndex = totalpage; + else if (currentPageIndex < 1) + currentPageIndex = 1; + + var renderList = currentList.slice((currentPageIndex - 1) * pagesize, pagesize); + uiDlgList.html(uiDlgTpl(renderList, { + isSelected: function (p) { + return sessmgr.currentProfile && sessmgr.currentProfile && _.findWhere(sessmgr.currentProfile.passengers, { key: p.key }) || false; + } + })); + + uiDlg.find("button.passenger-pager-prev").prop("disabled", currentPageIndex < 2); + uiDlg.find("button.passenger-pager-next").prop("disabled", totalpage - 1 <= currentPageIndex); + }; + uiDlg.find("button.passenger-pager-prev").click(function () { + currentPageIndex--; + renderPage(); + }); + uiDlg.find("button.passenger-pager-next").click(function () { + currentPageIndex++; + renderPage(); + }); + uiInput.keyup(function () { + performSearch(); + }); + uiInput.on("selectPassenger", function (e, p) { + if (exports.addPassengerToList(p)) + p.selected = true; + }); + uiList.on("click", ".optional-block .close", function (e) { + var span = $(this).closest(".optional-block"); + var key = span[0].dataset.id; + var cpl = sessmgr.currentProfile.passengers; + + for (var i = 0; i < cpl.length; i++) { + if (cpl[i].key === key) { + cpl.splice(i, 1); + sessmgr.save(); + break; + } + } + span.fadeOut('fast', function () { $(this).remove(); }); + + e.stopPropagation(); + }).on("click", ".optional-block", function (e) { + //添加儿童票 + var span = $(this).closest(".optional-block"); + var key = span[0].dataset.id; + var cpl = sessmgr.currentProfile.passengers; + + var p = _.findWhere(cpl, { key: key }); + if (!p) + return; + p = _.clone(p); + p.passenger_type = 2; + p.key += "$" + (Math.random() + '').substr(3, 4); + exports.addPassengerToList(p); + }); + + var resetList = function () { + uiList.find(">span").remove(); + if (sessmgr.currentProfile.passengers) { + uiList.append(uiListTpl(sessmgr.currentProfile.passengers)); + } + }; + + if (sessmgr.currentProfile) { + resetList(); + } + + sessmgr.on("sessionChanged", resetList); + sessmgr.on("currentProfileChanged", resetList); + + exports.addPassengerToList = function (p) { + var cp = sessmgr.currentProfile; + if (!cp) + return false; + + cp.passengers = cp.passengers || []; + + if (_.findWhere(cp.passengers, { key: p.key })) + return false; + if (cp.passengers.length >= 5) { + mp.showMessagePopup("error", "只能添加五个人喔。"); + return false; + } + + cp.passengers.push(p); + uiList.append(uiListTpl([p])); + sessmgr.save(); + + return true; + }; + }; + + var initTrainSelectEditor = function () { + var container = $(".options-train-selectorwarp"); + var listTpl = container.find("script:eq(1)").doT(); + var queryTpl = container.find("script:first").doT(); + var inputObj = container.find(":text"); + var queryTable = container.find(">div"); + var queryErrorRow = queryTable.find("table tr:eq(3)"); + var queryLoadingRow = queryTable.find("table tr:eq(1)"); + var queryTipRow = queryTable.find("table tr:eq(2)"); + var traindata; + + var currentKey = null; + + var showDropDown = function () { + queryErrorRow.hide(); + queryLoadingRow.hide(); + queryTipRow.hide(); + + var cp = sessmgr.currentProfile; + if (!cp) + return; + + var checkKey = cp.fromCode + cp.toCode + cp.depDate + cp.studentTicket; + if (checkKey != currentKey) { + //需要重新查询 + currentKey = checkKey; + + queryErrorRow.nextAll().remove(); + if (!cp.fromCode || !cp.toCode || !cp.depDate) { + queryTipRow.show(); + return; + } + + queryLoadingRow.show(); + query.queryTicket(cp.fromCode, cp.toCode, cp.depDate, cp.studentTicket) + .done(function () { + traindata = this; + if (!this.original.length) { + queryErrorRow.show(); + } else { + queryErrorRow.after(queryTpl(this.original)); + } + }).fail(function () { + queryErrorRow.show(); + }).always(function () { + queryLoadingRow.hide(); + }); + + } + queryTable.show(); + }; + var initialLoad = function () { + var cp = sessmgr.currentProfile; + container.find(">span").remove(); + if (cp && cp.selectedTrain) { + container.append(listTpl(cp.selectedTrain)); + } + }; + initialLoad(); + sessmgr.on("sessionChanged", initialLoad); + sessmgr.on("currentProfileChanged", initialLoad); + + inputObj.focus(function () { + showDropDown(); + }).blur(function () { + queryTable.hide(); + }).keydown(function (e) { + if (e.keyCode == 13) { + var s = this.value; + if (s) + exports.addTrainToList(s); + this.value = ""; + } + }); + + queryTable.mousedown(function (e) { + e.preventDefault(); + e.stopPropagation(); + }).on("click", "tr[data-id] td", function () { + var tr = $(this).closest("tr"); + var id = tr[0].dataset.id; + var t = _.findWhere(traindata.original, { id: id }); + if (!t) + return; + + exports.addTrainToList(t.code); + }); + container.on("click", ".optional-block", function () { + var obj = $(this).closest("span[data-code]"); + exports.removeTrainFromList(obj[0].dataset.code); + obj.fadeOut('fast', function () { $(this).remove(); }); + }); + + exports.addTrainToList = function (t) { + var cp = sessmgr.currentProfile; + if (!cp) + return; + + cp.selectedTrain = cp.selectedTrain || []; + if (_.indexOf(cp.selectedTrain, t) != -1) + return; + + cp.selectedTrain.push(t); + container.append(listTpl([t])); + sessmgr.save(); + }; + exports.removeTrainFromList = function (t) { + var cp = sessmgr.currentProfile; + if (!cp || !cp.selectedTrain) + return; + + for (var i = 0; i < cp.selectedTrain.length; i++) { + if (cp.selectedTrain[i] === t) { + cp.selectedTrain.splice(i, 1); + sessmgr.save(); + break; + } + } + }; + }; + + var initDateLoop = function () { + //UI + var container = $("#date_loop_editor"); + var tpl = container.find(">script").doT(); + var input = container.find("input"); + + var cp = sessmgr.currentProfile; + sessmgr.on("sessionChanged", function () { + cp = sessmgr.currentProfile; + initProfile(); + }); + sessmgr.on("currentProfileChanged", function () { + cp = sessmgr.currentProfile; + initProfile(); + }); + + var initProfile = function () { + container.find(">span").remove(); + if (cp && cp.dateloop) { + container.append(tpl(cp.dateloop)); + } + }; + + exports.addDateToLoopList = function (d) { + if (!d) return; + cp.dateloop = cp.dateloop || []; + + if (_.indexOf(cp.dateloop, d) !== -1) + return; + cp.dateloop.push(d); + sessmgr.save(); + //add to list + container.append(tpl([d])); + }; + exports.removeDateFromLoopList = function (d) { + if (!cp || !cp.dateloop) + return; + var idx = _.indexOf(cp.dateloop, d); + if (idx == -1) + return; + cp.dateloop.splice(idx, 1); + sessmgr.save(); + container.find(">span[data-date='" + d + "']").remove(); + }; + + input.change(function () { + if (this.value) + exports.addDateToLoopList(this.value); + this.value = ""; + }); + container.on("click", ">span[data-date]", function () { + exports.removeDateFromLoopList(this.dataset.date); + }); + + initProfile(); + }; + + var initSeatOrder = function () { + var seatDisplayOrder = "O319PM6420".split(''); + var recommand = ["O", "3", "1"]; + + var container = $("dd.options-seat-type"); + var ddTpl = container.find(">script:eq(0)").doT(); + var input = container.find(":text"); + var listTpl = container.find(">script:eq(1)").doT(); + var dropDown = null; + var cp = null; + + var initDropDown = function () { + container.append(ddTpl({ + order: seatDisplayOrder, + isSelected: function () { return false; }, + isRecommand: function (seat) { return _.indexOf(recommand, seat) != -1; }, + getName: data.toSeatTypeName + })); + + dropDown = container.find("ul"); + dropDown.mousedown(function(e) { + e.stopPropagation(); + e.preventDefault(); + }).click(function() { + input[0].focus(); + }); + }; + var initProfile = function () { + cp = sessmgr.currentProfile; + + container.find(">label>:checkbox").parent().remove(); + if (!cp || cp.selectedSeatType) + return; + container.append(listTpl({ + order: cp.selectedSeatType, + isSelected: function () { return false; }, + isRecommand: function () { return false; }, + getName: data.toSeatTypeName + })); + }; + exports.addSeat = function (code) { + if (!code || !cp) + return; + + cp.selectedSeatType = cp.selectedSeatType || []; + var idx = _.indexOf(cp.selectedSeatType, code); + if (idx != -1) + return; + cp.selectedSeatType.push(code); + sessmgr.save(); + container.append(listTpl({ + order: [code], + isSelected: function () { return false; }, + isRecommand: function () { return false; }, + getName: data.toSeatTypeName + })); + dropDown.find(":checkbox[value='" + code + "']").prop("checked", true); + }; + exports.removeSeat = function (code) { + if (!code || !cp) + return; + + var idx = _.indexOf(cp.selectedSeatType, code); + if (idx == -1) + return; + + cp.selectedSeatType.splice(idx, 1); + sessmgr.save(); + container.find(">label>input[value='" + code + "']").parent().remove(); + dropDown.find(":checkbox[value='" + code + "']").prop("checked", false); + }; + container.on("change", ":checkbox", function () { + if (this.checked) + exports.addSeat(this.value); + else exports.removeSeat(this.value); + }); + input.focus(function () { + dropDown.show(); + }).blur(function () { + dropDown.hide(); + }); + + + initDropDown(); + initProfile(); + sessmgr.on("sessionChanged", initProfile); + sessmgr.on("currentProfileChanged", initProfile); + }; + + exports.init = function () { + initPassengerEditor(); + initTrainSelectEditor(); + initDateLoop(); + initSeatOrder(); + }; + +}); diff --git a/Web12306/js/ui/ui-theme-manager.js b/Web12306/js/ui/ui-theme-manager.js index dd261ac..1ebff7d 100644 --- a/Web12306/js/ui/ui-theme-manager.js +++ b/Web12306/js/ui/ui-theme-manager.js @@ -14,7 +14,7 @@ var initList = function () { listContainer.empty(); - if (sessMgr.current.savedProfile) + if (sessMgr.current && sessMgr.current.savedProfile) listContainer.html(tpl(_.values(sessMgr.current.savedProfile))); }; diff --git a/Web12306/js/ui/widget_cityselector.js b/Web12306/js/ui/widget_cityselector.js index c6d8664..f016369 100644 --- a/Web12306/js/ui/widget_cityselector.js +++ b/Web12306/js/ui/widget_cityselector.js @@ -1,9 +1,13 @@ define(function (require, exports) { - var $html = '
    • 常用
    • A-E
    • F-J
    • K-O
    • P-T
    • U-Z

    最近查询

    常用城市

      '; + var $html = '
      • 常用
      • A-E
      • F-J
      • K-O
      • P-T
      • U-Z

      最近查询

      TEST

      常用城市

        '; var selector; var data = require("../data.js"); var cityMap = data.cities; + var citydata = data.citydata.data; + var popcity = data.citydata.popcity; + var maxRecentCity = 8; + var sessMgr = require("../account/sessionMgr.js"); var CitySelector = function (options) { var that = this; @@ -15,7 +19,37 @@ var target = null; var prevTab = null; var searchKey; - var blockClose = false; + var tplRecentCity = doT.template("{{~it:c:i}}
        {{!c.n}}
        {{~}}"); + var cp; + var container = $("#city_selector"); + + var initRecentCity = function () { + cp = sessMgr.current; + container.find("dd").remove(); + + if (!cp || !cp.recentCity) + return; + var cities = _.filter(cp.recentCity.map(function (e) { + return cityMap[e]; + }), function (e) { return e != null; }); + container.find("dl").html(tplRecentCity(cities)); + }; + initRecentCity(); + sessMgr.on("sessionChanged", initRecentCity); + + this.addCityToRecent = function (code) { + if (!code || !cp) + return; + cp.recentCity = cp.recentCity || []; + var idx = _.indexOf(cp.recentCity, code); + if (idx != -1) { + return; + } + container.find("dd[data-code='" + code + "']").remove(); + cp.recentCity.unshift(code); + sessMgr.save(); + container.find("dl").prepend(tplRecentCity([cityMap[code]])); + }; that.findExtractCity = function (val) { if (!val) @@ -116,21 +150,19 @@ that.focusOnText(); }; that.hidePopup = function (force) { - if (!blockClose) { - dom.removeClass("open"); + dom.removeClass("open"); - //验证 - var str = target.val(); - var city = that.findExtractCity(str); - if (!city) { - target.val(""); - target.attr("data-code", ""); - } else { - target.val(city.n); - target.attr("data-code", city.c); - } - target[0].dispatchEvent(new UIEvent("change")); + //验证 + var str = target.val(); + var city = that.findExtractCity(str); + if (!city) { + target.val(""); + target.attr("data-code", ""); + } else { + target.val(city.n); + target.attr("data-code", city.c); } + target[0].dispatchEvent(new UIEvent("change")); if (force) { @@ -151,7 +183,7 @@ currentPage = 0; if (code) { dom.find(".city-search>p").html("站点列表"); - currentList = _.values(data.data[code]); + currentList = _.values(citydata[code]); totalPage = Math.ceil(currentList.length / pageSize); that.renderPage(1); dom.find(".city-search").show(); @@ -294,10 +326,9 @@ target[0].blur(); } }); - $("#city_selector").mousedown(function () { - blockClose = true; - }).mouseup(function () { - blockClose = false; + $("#city_selector").mousedown(function (e) { + e.stopPropagation(); + e.preventDefault(); }); return this; @@ -310,14 +341,14 @@ (function () { var html = []; - _.each(data.popcity, function (c) { + _.each(popcity, function (c) { var city = cityMap[c]; html.push("
      • " + city.n + "
      • "); }); - if (data.popcity.length % 4 !== 0) { - for (var i = 0; i < 4 - data.popcity.length % 4; i++) { + if (popcity.length % 4 !== 0) { + for (var i = 0; i < 4 - popcity.length % 4; i++) { html.push("
      • "); } } @@ -327,6 +358,7 @@ args = $.extend({ rows: 9 }, args); selector = new CitySelector(args); + exports.cityui = selector; $(document).on("focus", eleSelector, function () { this.select(); diff --git a/Web12306/js/ui/widget_datedropdown.js b/Web12306/js/ui/widget_datedropdown.js index 9d2a02f..d8658a8 100644 --- a/Web12306/js/ui/widget_datedropdown.js +++ b/Web12306/js/ui/widget_datedropdown.js @@ -115,8 +115,8 @@ if (cell.hasClass("date-notavailable") || !container.data("date-target")) return; - var target = container.data("date-target").val(cell.attr("data-date")); - target.trigger("datechanged.widget.ui.datepopup").change(); + var target = container.data("date-target").val(cell.attr("data-date")).change(); + target.trigger("datechanged").change(); dropdownInstance.hidePopup(); container.removeData("date-target");