"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_globalState = require("../../utils/globalState.js"); const api_index = require("../../api/index.js"); const utils_session = require("../../utils/session.js"); const utils_datetime = require("../../utils/datetime.js"); const utils_appointment = require("../../utils/appointment.js"); if (!Math) { AppIcon(); } const AppIcon = () => "../../components/AppIcon.js"; const _sfc_main = { __name: "MyOrders", emits: ["change-page"], setup(__props, { emit: __emit }) { const userInfo = utils_session.getUserSession(); const currentUserId = userInfo.id; const navSafeStyle = (() => { var _a, _b, _c, _d; const statusBarHeight = ((_b = (_a = common_vendor.index).getSystemInfoSync) == null ? void 0 : _b.call(_a).statusBarHeight) || 20; let navHeight = statusBarHeight + 44; const menuRect = (_d = (_c = common_vendor.index).getMenuButtonBoundingClientRect) == null ? void 0 : _d.call(_c); if (menuRect && menuRect.top && menuRect.height) { const verticalGap = Math.max(menuRect.top - statusBarHeight, 4); navHeight = statusBarHeight + verticalGap * 2 + menuRect.height; } return `padding-top:${statusBarHeight}px;height:${navHeight}px;`; })(); const currentStatus = common_vendor.ref("new"); const orders = common_vendor.ref([]); const statusTabs = [ { title: "待确认", name: "new" }, { title: "进行中", name: "doing" }, { title: "已完成", name: "done" } ]; const filteredOrders = common_vendor.computed(() => orders.value.filter((o) => { if (currentStatus.value === "new") return o.status === "new"; if (currentStatus.value === "doing") return o.status === "doing"; if (currentStatus.value === "done") return o.status === "done" || o.status === "cancel"; return true; })); const statusTagBg = (status) => { return utils_appointment.getAppointmentTagType(status); }; const fetchOrders = async () => { if (!currentUserId) return; const res = await api_index.getAppointmentList(currentUserId); if (res.code === 200) { orders.value = res.data.map((appt) => ({ id: appt.id, title: appt.serviceType || "洗澡美容预约", desc: `${appt.petType || ""} - ${appt.petName || ""}`, time: utils_datetime.formatDateTimeCN(appt.appointmentTime), status: appt.status || "new", statusText: utils_appointment.getAppointmentStatusText(appt.status), petName: appt.petName, petType: appt.petType, serviceType: appt.serviceType, appointmentTime: appt.appointmentTime })); } }; const startService = async (item) => { const res = await api_index.startAppointment(item.id, userInfo.id); if (res.code === 200) { common_vendor.index.showToast({ title: "已开始服务", icon: "success" }); fetchOrders(); } else { common_vendor.index.showToast({ title: res.message || "操作失败", icon: "none" }); } }; const cancelService = async (item) => { common_vendor.index.showModal({ title: "提示", content: "确定取消该预约?", success: async (res) => { if (!res.confirm) return; const r = await api_index.cancelAppointment(item.id); if (r.code === 200) { common_vendor.index.showToast({ title: "已取消", icon: "success" }); fetchOrders(); } } }); }; const goReport = (item) => { common_vendor.index.setStorageSync("petstore_report_prefill", JSON.stringify({ appointmentId: item.id, petName: item.petName, serviceType: item.serviceType, appointmentTime: item.appointmentTime })); utils_globalState.navigateTo("report"); }; common_vendor.onMounted(() => fetchOrders()); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.p({ name: "back", size: 18, color: "#ffffff" }), b: common_vendor.o(($event) => common_vendor.unref(utils_globalState.navigateTo)("mine")), c: common_vendor.s(common_vendor.unref(navSafeStyle)), d: common_vendor.f(statusTabs, (tab, k0, i0) => { return { a: common_vendor.t(tab.title), b: tab.name, c: common_vendor.n({ active: currentStatus.value === tab.name }), d: common_vendor.o(($event) => currentStatus.value = tab.name, tab.name) }; }), e: common_vendor.f(filteredOrders.value, (item, k0, i0) => { return common_vendor.e({ a: common_vendor.t(item.title), b: common_vendor.t(item.statusText), c: common_vendor.n(`van-tag van-tag--${statusTagBg(item.status)}`), d: "9fa5d3ab-1-" + i0, e: common_vendor.t(item.desc), f: "9fa5d3ab-2-" + i0, g: common_vendor.t(item.time), h: item.status === "new" }, item.status === "new" ? { i: common_vendor.o(($event) => startService(item), item.id), j: common_vendor.o(($event) => cancelService(item), item.id) } : item.status === "doing" ? { l: common_vendor.o(($event) => goReport(item), item.id) } : {}, { k: item.status === "doing", m: item.id }); }), f: common_vendor.p({ name: "profile", size: 12 }), g: common_vendor.p({ name: "orders", size: 12, color: "#94a3b8" }), h: filteredOrders.value.length === 0 }, filteredOrders.value.length === 0 ? {} : {}); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-9fa5d3ab"]]); wx.createPage(MiniProgramPage);