U.Date.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //#region
  2. //pc时间控件
  3. U.Date = (function (that) { //初始化
  4. var _UDE, _ = function (UDOD, UTI, UDE) {
  5. if (UDE && (UDE.id || UDOD.id) && _UDE.et[UDE.id || (UDOD.id + "time")]) { return _UDE.et[UDOD.id + "time"].dis(true); }
  6. else { return new _UDE.init(UDOD, UTI, UDE); }
  7. }
  8. _.prototype = _UDE = {
  9. et: {},
  10. get: function () { },
  11. set: function () { },
  12. init: function (UDOD, UTI, UDE) { //初始化时间控件
  13. var i, _UDE = ["FullYear", "Month", "Date", "Hours", "Minutes", "Seconds", "Day"]; UDE = UDE || {};
  14. this.ti = UTI || new Date(); this.el = UDOD || this.el;
  15. this.id = UDE.id || (UDOD.id ? UDOD.id + "time" : "U_TI" + Guid.guidNoDash());
  16. for (i = 0; i < _UDE.length; i++) { this[_UDE[i]] = this.ti["get" + _UDE[i]]() + (i == 1 ? 1 : 0); }
  17. this.Day = this.Day || 7;
  18. this.ex = {};
  19. this.startM = new Date(this.FullYear + "/" + this.Month + "/01").getDay() || 7; U.Ut.AddObj(this.ex, UDE || {});
  20. this.et[this.id] = this; this.create();
  21. },
  22. create: function () { //创建一个控件
  23. var i, _UCE, _UKE, _UDOD, _UDTD, _UDKD, _UE = U.M.GetElementInfo(this.el);
  24. this.be = _UDOD = $$("div", { "class": "U_TI", id: this.id, style: { top: _UE.BCRT + _UE.OH + "px", left: (_UE.BCRL - 120 < 0 ? 0 : _UE.BCRL - 120) + "px"} });
  25. this.title = _UDTD = $$("div", { "class": "U_TIH" }, _UDOD); _UCE = ["FullYear", "Month"];
  26. for (i = 0; i < _UCE.length; i++) { _UDKD = $$("div", { "class": "U_TIHL" }, _UDTD); $$("div", { "title": "前一" + (i ? "月" : "年"), "class": "U_TIHLL", innerHTML: "<".replaceHtmlSign(), onclick: U.M.apply(this, [[this["set" + _UCE[i]], [_UDKD, -1]]]) }, _UDKD); $$("div", { "class": "U_TIHLC", innerHTML: this.ti["get" + _UCE[i]]() + i }, _UDKD); $$("div", { "title": "下一" + (i ? "月" : "年"), "class": "U_TIHLL U_TIHLR", innerHTML: ">", onclick: U.M.apply(this, [[this["set" + _UCE[i]], [_UDKD, 1]]]) }, _UDKD); } //初始化当前时间
  27. _UDTD = $$("div", { "class": "U_TIM" }, _UDOD); for (i = 1; i < 8; i++) { $$("div", { style: { "marginLeft": i - 1 ? "" : "5px" }, innerHTML: U.MT.LowerToUpper(i + "", "day") }, _UDTD); } //星期
  28. this.content = _UDTD = $$("div", { "class": "U_TIN" }, _UDOD); this.setDay(_UDTD);
  29. _UDTD = $$("div", { "class": "U_TID" }, _UDOD); _UCE = ["取消", "确认", "当前"]; for (i = 0; i < _UCE.length; i++) { $$("div", { "class": "U_TIDO", innerHTML: _UCE[i], onclick: U.M.apply(this, [[this.button, [i]]]) }, _UDTD); };
  30. U.D.SetDTop(_UDOD); $("body").append(_UDOD);
  31. },
  32. mp: function () { //手机端时间控件
  33. U.Date.Phone();
  34. },
  35. getTime: function (UDE) { //选择当前选择的信息
  36. var i, _UTF, _UDTD, _UDAD = $(this.title).Child(); UDE = UDE || [this.FullYear, this.Month, this.Date];
  37. for (i = 0; i < 2; i++) { if ((_UDTD = $(_UDAD[i]).Child()[1]).innerText != UDE[i]) { _UDTD.innerText = UDE[i]; _UTF = true; } };
  38. _UDAD = $(this.content).childg(); _UDAD.addAttrArray({ "class": "" }); _UDAD[UDE[2] + this.startM - 2].className = "U_TINO";
  39. },
  40. setFullYear: function (UDOD, UTF) { //设置年
  41. $(UDOD).Child()[1].innerText = (this.FullYear += UTF); this.startM = new Date(this.FullYear + "/" + this.Month + "/01").getDay() || 7; this.setDay();
  42. },
  43. setMonth: function (UDOD, UTF) { //设置月
  44. $(UDOD).Child()[1].innerText = (this.Month += UTF); this.startM = new Date(this.FullYear + "/" + this.Month + "/01").getDay() || 7; this.setDay();
  45. },
  46. setDay: function (UDOD) {
  47. UDOD = UDOD || this.content; var i, _UTF, _UDE = U.MT.getYearMonthDay(); _UKE = this.startM, _UCE = this.getDay() + _UKE - 2; UDOD.innerText = "";
  48. for (i = 0; i <= _UCE; i++) {
  49. _UTF = i - this.startM + 2;
  50. $$("div", { "class": (_UTF == this.Date) ? ((_UDE[0] == this.FullYear && _UDE[1] == this.Month && _UDE[2] == this.Date) ? "U_TINO" : "U_TINT") : "", "style": { "marginLeft": i % 7 ? "" : "5px" }, innerHTML: _UTF > 0 ? _UTF : "", onclick: this.startM - 2 < i ? U.M.apply(this, [[this.setTime, [_UTF]], [this.click, ["day", _UTF]]]) : null }, UDOD);
  51. }
  52. },
  53. setTime: function (UIE) { //选择当前日期
  54. this.Date = UIE; this.setDay();
  55. },
  56. time: function () { //时间选择
  57. setInterval(function () { }, 1000);
  58. },
  59. getDay: function (UDE) { //获取指定年月的天数
  60. UDE = UDE || [this.FullYear, this.Month]; return U.MT.getDayOfMonth(UDE);
  61. },
  62. click: function (UTF, UIE) { // 点击处理
  63. var _UDE = [this.FullYear, this.Month, this.Date].join(this.ex.sy || "/"); (this.el) && (this.el[this.el.value != null ? "value" : "innerText"] = _UDE); try { (this.ex[UTF + "cb"]) && (this.ex[UTF + "cb"](_UDE)); } catch (e) { } this.dis();
  64. },
  65. button: function (UIE) { //按钮时间
  66. switch (UIE) { case 0: this.dis(); break; case 1: this.click("day", this.Date); break; case 2: this.init(); break; }
  67. },
  68. dis: function (UTF) { //显示隐藏
  69. $(this.be)[UTF ? "show" : "hide"](); return this;
  70. },
  71. TimeDif: function () { //时间差
  72. }
  73. };
  74. _UDE.init.prototype = _UDE; return _;
  75. })();
  76. //手机时间控件
  77. U.Date.Phone = function (UDOD, UDE) {
  78. var i, j, _UJE = [], _UDAD, _UDTD, _UDSD, _UDFD, _UDMD, _UDND, _UDKD, _UAE = ["FullYear", "Month", "Date", "Hours", "Minutes", "Seconds", "Day"]; UDE = UDE || {}; UDE.Date = UDE.Date || new Date(); UDOD = UDOD || event.srcElement || this;
  79. if ((_UDTD = $("#U_Time"))[0]) { _UDTD.css("display", "block"); _UDTD.Child()[1].className = "U_TimeG U_TimeS"; }
  80. else {
  81. for (i = 0; i < _UAE.length; i++) { _UAE[i] = UDE.Date["get" + _UAE[i]]() + (i == 1 ? 1 : 0); }
  82. _UDAD = $$("div", { className: "U_Time", "id": "U_Time" });
  83. $$("div", { className: "U_TimeM" }, _UDAD);
  84. _UDTD = $$("div", { className: "U_TimeG" }, _UDAD);
  85. $$("div", { className: "U_TimeON" }, _UDTD);
  86. $$("div", { className: "U_TimeT", innerHTML: "请选择时间" }, _UDTD);
  87. _UDSD = $$("div", { className: "U_TimeO" }, _UDTD);
  88. _UDFD = $$("div", { className: "U_TimeOA", "onscroll": [[U.Date.PhoneSc, ["this", "scroll"]]] }, _UDSD);
  89. for (i = -1; i < 203; i++) { _UDKD = $$("div", { innerHTML: i > -1 ? (i < 1 || i > 199) ? "" : _UAE[0] + i - 99 + "年" : "选择年份", "onclick": [[U.Date.PhoneC, ["this", i]]] }, _UDFD); if (i == 99) { _UDKD.className = ""; } }
  90. _UDMD = $$("div", { className: "U_TimeOA", "onscroll": [[U.Date.PhoneSc, ["this", "scroll"]]] }, _UDSD);
  91. for (i = -1; i < 16; i++) { _UDKD = $$("div", { innerHTML: i > -1 ? (i < 1 || i > 12) ? "" : i + "月" : "选择月份", "onclick": [[U.Date.PhoneC, ["this", i]]] }, _UDMD); }
  92. _UDND = $$("div", { className: "U_TimeOA", "onscroll": [[U.Date.PhoneSc, ["this", "scroll"]]] }, _UDSD); j = U.MT.getDayOfMonth[_UAE[0], _UAE[1]];
  93. for (i = -1; i < j + 4; i++) { _UDKD = $$("div", { innerHTML: i > -1 ? (i < 1 || i > j) ? "" : i + "日" : "选择日期", "onclick": [[U.Date.PhoneC, ["this", i]]] }, _UDND); }
  94. _UDKD = $$("div", { className: "U_TimeD" }, _UDTD);
  95. $$("div", { innerHTML: "确定", "onclick": [[U.Date.PhoneSet, [UDOD, _UDSD, "assigin", UDE]], [U.Date.PhoneSet, [_UDAD, _UDTD, "remove", UDE]]] }, _UDKD); $$("div", { innerHTML: "当前", "onclick": [[U.Date.PhoneSet, [UDOD, _UDSD, "current", UDE]], [U.Date.PhoneSet, [_UDAD, _UDTD, "remove", UDE]]] }, _UDKD); $$("div", { innerHTML: "取消", "onclick": [[U.Date.PhoneSet, [_UDAD, _UDTD, "remove", UDE]]] }, _UDKD);
  96. document.body.appendChild(_UDAD); _UDTD.className = "U_TimeG U_TimeS";
  97. _UJE = [_UDFD, _UDMD, _UDND]; for (i = 0; i < _UJE.length; i++) { _UJE[i].scrollTop = ((i ? _UAE[i] : 99) - 1) * 35; }
  98. }
  99. }
  100. //编辑变化
  101. U.Date.PhoneC = function (UDOD, UIE) {
  102. $(UDOD).Parent().scrollTop = (UIE - 1) * 35;
  103. }
  104. //滚动变化
  105. U.Date.PhoneSc = function (UDOD, UTF) {
  106. clearTimeout(UDOD._Time_);
  107. UDOD._Time_ = setTimeout(function () {
  108. UDOD.scrollTop = (Math.floor(UDOD.scrollTop / 35) + (UDOD.scrollTop % 35 > 15 ? 1 : 0)) * 35; (UDOD._Child_) && (UDOD._Child_.className = "");
  109. (UDOD._Child_ = $(UDOD).Child()[UDOD.scrollTop / 35 + 2]).className = "U_TimeOAS"; U.Date.Phone.T = null;
  110. }, 100);
  111. }
  112. //设置时间
  113. U.Date.PhoneSet = function (UDOD, UDTD, UTF, UDE) {
  114. var i, _UDAD, _UTH = "", _UTM = UDE["ps"] || "-";
  115. switch (UTF) {
  116. case "assigin":
  117. _UDAD = $(UDTD).Child(); for (i = 0; i < _UDAD.length; i++) { _UTH += _UDAD[i]._Child_.innerHTML.substr(0, _UDAD[i]._Child_.innerHTML.length - 1) + (i == _UDAD.length - 1 ? "" : _UTM); }
  118. UDOD.value = UDOD.innerHTML = _UTH;
  119. break;
  120. case "current":
  121. UDOD.value = UDOD.innerHTML = U.MT.getYearMonthDay("String");
  122. break;
  123. case "remove": UDTD.className = "U_TimeG"; $(UDOD).css("display", "none"); break;
  124. }
  125. }
  126. //#endregion