| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- "use strict";
- const common_vendor = require("../common/vendor.js");
- const utils_auth = require("../utils/auth.js");
- require("../utils/api.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 (!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;
- }
- if (!utils_auth.isLoggedIn()) {
- common_vendor.index.showModal({
- title: "登录提示",
- content: "此功能需要登录后使用,是否前往登录?",
- confirmText: "去登录",
- cancelText: "取消",
- success: (res) => {
- if (res.confirm) {
- common_vendor.index.navigateTo({ url: "/pages/login/login" });
- }
- }
- });
- 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: showDatePicker.value
- }, showDatePicker.value ? {
- g: common_vendor.o(closeDatePicker),
- h: common_vendor.t(currentPickerType.value === "start" ? "选择开始日期" : "选择结束日期"),
- i: common_vendor.o(confirmDate),
- j: common_vendor.o(prevMonth),
- k: common_vendor.t(tempYear.value),
- l: common_vendor.t(tempMonth.value),
- m: common_vendor.o(nextMonth),
- n: common_vendor.f(weekDays, (day, k0, i0) => {
- return {
- a: common_vendor.t(day),
- b: day
- };
- }),
- o: 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)
- });
- }),
- p: common_vendor.o(() => {
- }),
- q: 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);
|