index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. "use strict";
  2. var _page = _interopRequireDefault(require("../../common/page"));
  3. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. (0, _page["default"])({
  6. data: {
  7. date: {
  8. maxRange: [],
  9. selectSingle: null,
  10. selectRange: [],
  11. selectMultiple: [],
  12. quickSelect1: null,
  13. quickSelect2: [],
  14. customColor: [],
  15. customConfirm: [],
  16. customRange: null,
  17. customDayText: [],
  18. customPosition: null
  19. },
  20. type: "single",
  21. round: true,
  22. color: undefined,
  23. minDate: Date.now(),
  24. maxDate: new Date(new Date().getFullYear(), new Date().getMonth() + 6, new Date().getDate()).getTime(),
  25. maxRange: undefined,
  26. position: undefined,
  27. formatter: undefined,
  28. showConfirm: false,
  29. showCalendar: false,
  30. tiledMinDate: new Date(2012, 0, 10).getTime(),
  31. tiledMaxDate: new Date(2012, 2, 20).getTime(),
  32. confirmText: undefined,
  33. confirmDisabledText: undefined
  34. },
  35. onConfirm: function onConfirm(event) {
  36. console.log(event);
  37. this.setData({
  38. showCalendar: false
  39. });
  40. this.setData(_defineProperty({}, "date.".concat(this.data.id), event.detail));
  41. },
  42. onSelect: function onSelect(event) {
  43. console.log(event);
  44. },
  45. onUnselect: function onUnselect(event) {
  46. console.log(event);
  47. },
  48. onClose: function onClose() {
  49. this.setData({
  50. showCalendar: false
  51. });
  52. },
  53. onOpen: function onOpen() {
  54. console.log("open");
  55. },
  56. onOpened: function onOpened() {
  57. console.log("opened");
  58. },
  59. onClosed: function onClosed() {
  60. console.log("closed");
  61. },
  62. resetSettings: function resetSettings() {
  63. this.setData({
  64. round: true,
  65. color: null,
  66. minDate: Date.now(),
  67. maxDate: new Date(new Date().getFullYear(), new Date().getMonth() + 6, new Date().getDate()).getTime(),
  68. maxRange: null,
  69. position: "bottom",
  70. formatter: null,
  71. showConfirm: true,
  72. confirmText: "确定",
  73. confirmDisabledText: null
  74. });
  75. },
  76. show: function show(event) {
  77. this.resetSettings();
  78. var _event$currentTarget$ = event.currentTarget.dataset,
  79. type = _event$currentTarget$.type,
  80. id = _event$currentTarget$.id;
  81. var data = {
  82. id: id,
  83. type: type,
  84. showCalendar: true
  85. };
  86. switch (id) {
  87. case "quickSelect1":
  88. case "quickSelect2":
  89. data.showConfirm = false;
  90. break;
  91. case "customColor":
  92. data.color = "#07c160";
  93. break;
  94. case "customConfirm":
  95. data.confirmText = "完成";
  96. data.confirmDisabledText = "请选择结束时间";
  97. break;
  98. case "customRange":
  99. data.minDate = new Date(2010, 0, 1).getTime();
  100. data.maxDate = new Date(2010, 0, 31).getTime();
  101. break;
  102. case "customDayText":
  103. data.minDate = new Date(2010, 4, 1).getTime();
  104. data.maxDate = new Date(2010, 4, 31).getTime();
  105. data._formatter = true;
  106. data.formatter = this.dayFormatter;
  107. break;
  108. case "customPosition":
  109. data.round = false;
  110. data.position = "right";
  111. break;
  112. case "maxRange":
  113. data.maxRange = 3;
  114. break;
  115. }
  116. this.setData(data);
  117. },
  118. _dayFormatter: function _dayFormatter(day) {
  119. return this.data._formatter ? this.dayFormatter(day) : function (day) {
  120. return day;
  121. };
  122. },
  123. dayFormatter: function dayFormatter(day) {
  124. var month = day.date.getMonth() + 1;
  125. var date = day.date.getDate();
  126. if (month === 5) {
  127. if (date === 1) {
  128. day.topInfo = "劳动节";
  129. } else if (date === 4) {
  130. day.topInfo = "五四青年节";
  131. } else if (date === 11) {
  132. day.text = "今天";
  133. }
  134. }
  135. if (day.type === "start") {
  136. day.bottomInfo = "入店";
  137. } else if (day.type === "end") {
  138. day.bottomInfo = "离店";
  139. }
  140. return day;
  141. }
  142. });