HistorySearchCard.js 6.2 KB

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