HistorySearchCard.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const utils_auth = require("../utils/auth.js");
  4. require("../utils/api.js");
  5. const _sfc_main = {
  6. __name: "HistorySearchCard",
  7. props: {
  8. poolType: { type: Number, default: 1 },
  9. canSearch: { type: Boolean, default: false }
  10. },
  11. emits: ["dateChange"],
  12. setup(__props, { emit }) {
  13. const props = __props;
  14. const getDefaultDates = () => {
  15. const now = /* @__PURE__ */ new Date();
  16. const year = now.getFullYear();
  17. const month = String(now.getMonth() + 1).padStart(2, "0");
  18. const lastDay = new Date(year, now.getMonth() + 1, 0).getDate();
  19. return {
  20. start: `${year}-${month}-01`,
  21. end: `${year}-${month}-${lastDay}`
  22. };
  23. };
  24. const defaultDates = getDefaultDates();
  25. const startDate = common_vendor.ref(defaultDates.start);
  26. const endDate = common_vendor.ref(defaultDates.end);
  27. const showDatePicker = common_vendor.ref(false);
  28. const currentPickerType = common_vendor.ref("start");
  29. const tempYear = common_vendor.ref((/* @__PURE__ */ new Date()).getFullYear());
  30. const tempMonth = common_vendor.ref((/* @__PURE__ */ new Date()).getMonth() + 1);
  31. const tempSelectedDay = common_vendor.ref(1);
  32. const weekDays = ["日", "一", "二", "三", "四", "五", "六"];
  33. const calendarDays = common_vendor.computed(() => {
  34. const days = [];
  35. const firstDay = new Date(tempYear.value, tempMonth.value - 1, 1).getDay();
  36. const daysInMonth = new Date(tempYear.value, tempMonth.value, 0).getDate();
  37. for (let i = 0; i < firstDay; i++) {
  38. days.push(null);
  39. }
  40. for (let i = 1; i <= daysInMonth; i++) {
  41. days.push(i);
  42. }
  43. return days;
  44. });
  45. const formatDateDisplay = (dateStr) => {
  46. if (!dateStr)
  47. return "请选择";
  48. const [year, month, day] = dateStr.split("-");
  49. return `${year}/${month}/${day}`;
  50. };
  51. const emitDateChange = () => {
  52. emit("dateChange", {
  53. startDate: startDate.value,
  54. endDate: endDate.value,
  55. poolType: props.poolType
  56. });
  57. };
  58. const openStartDatePicker = () => {
  59. currentPickerType.value = "start";
  60. const [year, month, day] = startDate.value.split("-").map(Number);
  61. tempYear.value = year;
  62. tempMonth.value = month;
  63. tempSelectedDay.value = day;
  64. showDatePicker.value = true;
  65. };
  66. const openEndDatePicker = () => {
  67. currentPickerType.value = "end";
  68. const [year, month, day] = endDate.value.split("-").map(Number);
  69. tempYear.value = year;
  70. tempMonth.value = month;
  71. tempSelectedDay.value = day;
  72. showDatePicker.value = true;
  73. };
  74. const closeDatePicker = () => {
  75. showDatePicker.value = false;
  76. };
  77. const prevMonth = () => {
  78. if (tempMonth.value === 1) {
  79. tempMonth.value = 12;
  80. tempYear.value--;
  81. } else {
  82. tempMonth.value--;
  83. }
  84. };
  85. const nextMonth = () => {
  86. if (tempMonth.value === 12) {
  87. tempMonth.value = 1;
  88. tempYear.value++;
  89. } else {
  90. tempMonth.value++;
  91. }
  92. };
  93. const selectDay = (day) => {
  94. tempSelectedDay.value = day;
  95. };
  96. const isSelected = (day) => {
  97. return day === tempSelectedDay.value;
  98. };
  99. const isToday = (day) => {
  100. const today = /* @__PURE__ */ new Date();
  101. return tempYear.value === today.getFullYear() && tempMonth.value === today.getMonth() + 1 && day === today.getDate();
  102. };
  103. const confirmDate = () => {
  104. const dateStr = `${tempYear.value}-${String(tempMonth.value).padStart(2, "0")}-${String(tempSelectedDay.value).padStart(2, "0")}`;
  105. if (currentPickerType.value === "start") {
  106. startDate.value = dateStr;
  107. } else {
  108. endDate.value = dateStr;
  109. }
  110. showDatePicker.value = false;
  111. emitDateChange();
  112. };
  113. const onSearch = () => {
  114. if (!startDate.value || !endDate.value) {
  115. common_vendor.index.showToast({ title: "请选择开始和结束日期", icon: "none" });
  116. return;
  117. }
  118. if (startDate.value > endDate.value) {
  119. common_vendor.index.showToast({ title: "开始日期不能晚于结束日期", icon: "none" });
  120. return;
  121. }
  122. if (!utils_auth.isLoggedIn()) {
  123. common_vendor.index.showModal({
  124. title: "登录提示",
  125. content: "此功能需要登录后使用,是否前往登录?",
  126. confirmText: "去登录",
  127. cancelText: "取消",
  128. success: (res) => {
  129. if (res.confirm) {
  130. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  131. }
  132. }
  133. });
  134. return;
  135. }
  136. common_vendor.index.navigateTo({
  137. url: `/pages/history/history?startDate=${startDate.value}&endDate=${endDate.value}&poolType=${props.poolType}`
  138. });
  139. };
  140. common_vendor.onMounted(() => {
  141. emitDateChange();
  142. });
  143. return (_ctx, _cache) => {
  144. return common_vendor.e({
  145. a: common_vendor.t(formatDateDisplay(startDate.value)),
  146. b: common_vendor.o(openStartDatePicker),
  147. c: common_vendor.t(formatDateDisplay(endDate.value)),
  148. d: common_vendor.o(openEndDatePicker),
  149. e: common_vendor.o(onSearch),
  150. f: showDatePicker.value
  151. }, showDatePicker.value ? {
  152. g: common_vendor.o(closeDatePicker),
  153. h: common_vendor.t(currentPickerType.value === "start" ? "选择开始日期" : "选择结束日期"),
  154. i: common_vendor.o(confirmDate),
  155. j: common_vendor.o(prevMonth),
  156. k: common_vendor.t(tempYear.value),
  157. l: common_vendor.t(tempMonth.value),
  158. m: common_vendor.o(nextMonth),
  159. n: common_vendor.f(weekDays, (day, k0, i0) => {
  160. return {
  161. a: common_vendor.t(day),
  162. b: day
  163. };
  164. }),
  165. o: common_vendor.f(common_vendor.unref(calendarDays), (day, index, i0) => {
  166. return common_vendor.e({
  167. a: day
  168. }, day ? {
  169. b: common_vendor.t(day)
  170. } : {}, {
  171. c: index,
  172. d: common_vendor.n({
  173. "empty": !day,
  174. "selected": day && isSelected(day),
  175. "today": day && isToday(day)
  176. }),
  177. e: common_vendor.o(($event) => day && selectDay(day), index)
  178. });
  179. }),
  180. p: common_vendor.o(() => {
  181. }),
  182. q: common_vendor.o(closeDatePicker)
  183. } : {});
  184. };
  185. }
  186. };
  187. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-df43cc4c"], ["__file", "D:/program/gupiao/gupiao-wx/src/components/HistorySearchCard.vue"]]);
  188. wx.createComponent(Component);