"use strict"; const common_vendor = require("../common/vendor.js"); const _sfc_main = { __name: "HistorySearchCard", props: { poolType: { type: Number, default: 1 }, canSearch: { type: Boolean, default: false } }, emits: ["dateChange"], setup(__props, { emit }) { const props = __props; const getDefaultDates = () => { const now = /* @__PURE__ */ new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, "0"); const lastDay = new Date(year, now.getMonth() + 1, 0).getDate(); return { start: `${year}-${month}-01`, end: `${year}-${month}-${lastDay}` }; }; const defaultDates = getDefaultDates(); const startDate = common_vendor.ref(defaultDates.start); const endDate = common_vendor.ref(defaultDates.end); const showDatePicker = common_vendor.ref(false); const currentPickerType = common_vendor.ref("start"); const tempYear = common_vendor.ref((/* @__PURE__ */ new Date()).getFullYear()); const tempMonth = common_vendor.ref((/* @__PURE__ */ new Date()).getMonth() + 1); const tempSelectedDay = common_vendor.ref(1); const weekDays = ["日", "一", "二", "三", "四", "五", "六"]; const calendarDays = common_vendor.computed(() => { const days = []; const firstDay = new Date(tempYear.value, tempMonth.value - 1, 1).getDay(); const daysInMonth = new Date(tempYear.value, tempMonth.value, 0).getDate(); for (let i = 0; i < firstDay; i++) { days.push(null); } for (let i = 1; i <= daysInMonth; i++) { days.push(i); } return days; }); const formatDateDisplay = (dateStr) => { if (!dateStr) return "请选择"; const [year, month, day] = dateStr.split("-"); return `${year}/${month}/${day}`; }; const emitDateChange = () => { emit("dateChange", { startDate: startDate.value, endDate: endDate.value, poolType: props.poolType }); }; const openStartDatePicker = () => { currentPickerType.value = "start"; const [year, month, day] = startDate.value.split("-").map(Number); tempYear.value = year; tempMonth.value = month; tempSelectedDay.value = day; showDatePicker.value = true; }; const openEndDatePicker = () => { currentPickerType.value = "end"; const [year, month, day] = endDate.value.split("-").map(Number); tempYear.value = year; tempMonth.value = month; tempSelectedDay.value = day; showDatePicker.value = true; }; const closeDatePicker = () => { showDatePicker.value = false; }; const prevMonth = () => { if (tempMonth.value === 1) { tempMonth.value = 12; tempYear.value--; } else { tempMonth.value--; } }; const nextMonth = () => { if (tempMonth.value === 12) { tempMonth.value = 1; tempYear.value++; } else { tempMonth.value++; } }; const selectDay = (day) => { tempSelectedDay.value = day; }; const isSelected = (day) => { return day === tempSelectedDay.value; }; const isToday = (day) => { const today = /* @__PURE__ */ new Date(); return tempYear.value === today.getFullYear() && tempMonth.value === today.getMonth() + 1 && day === today.getDate(); }; const confirmDate = () => { const dateStr = `${tempYear.value}-${String(tempMonth.value).padStart(2, "0")}-${String(tempSelectedDay.value).padStart(2, "0")}`; if (currentPickerType.value === "start") { startDate.value = dateStr; } else { endDate.value = dateStr; } showDatePicker.value = false; emitDateChange(); }; const onSearch = () => { if (!props.canSearch) { common_vendor.index.showToast({ title: "请先订阅该股票池", icon: "none" }); return; } if (!startDate.value || !endDate.value) { common_vendor.index.showToast({ title: "请选择开始和结束日期", icon: "none" }); return; } if (startDate.value > endDate.value) { common_vendor.index.showToast({ title: "开始日期不能晚于结束日期", icon: "none" }); return; } common_vendor.index.navigateTo({ url: `/pages/history/history?startDate=${startDate.value}&endDate=${endDate.value}&poolType=${props.poolType}` }); }; common_vendor.onMounted(() => { emitDateChange(); }); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.t(formatDateDisplay(startDate.value)), b: common_vendor.o(openStartDatePicker), c: common_vendor.t(formatDateDisplay(endDate.value)), d: common_vendor.o(openEndDatePicker), e: common_vendor.o(onSearch), f: !__props.canSearch }, !__props.canSearch ? {} : {}, { g: showDatePicker.value }, showDatePicker.value ? { h: common_vendor.o(closeDatePicker), i: common_vendor.t(currentPickerType.value === "start" ? "选择开始日期" : "选择结束日期"), j: common_vendor.o(confirmDate), k: common_vendor.o(prevMonth), l: common_vendor.t(tempYear.value), m: common_vendor.t(tempMonth.value), n: common_vendor.o(nextMonth), o: common_vendor.f(weekDays, (day, k0, i0) => { return { a: common_vendor.t(day), b: day }; }), p: common_vendor.f(common_vendor.unref(calendarDays), (day, index, i0) => { return common_vendor.e({ a: day }, day ? { b: common_vendor.t(day) } : {}, { c: index, d: common_vendor.n({ "empty": !day, "selected": day && isSelected(day), "today": day && isToday(day) }), e: common_vendor.o(($event) => day && selectDay(day), index) }); }), q: common_vendor.o(() => { }), r: common_vendor.o(closeDatePicker) } : {}); }; } }; const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-df43cc4c"], ["__file", "D:/program/gupiao/gupiao-wx/src/components/HistorySearchCard.vue"]]); wx.createComponent(Component);