"use strict"; const common_vendor = require("../../common/vendor.js"); const api_index = require("../../api/index.js"); const utils_session = require("../../utils/session.js"); const composables_useNavigator = require("../../composables/useNavigator.js"); const utils_datetime = require("../../utils/datetime.js"); const utils_appointment = require("../../utils/appointment.js"); if (!Math) { (AppIcon + TabBar)(); } const TabBar = () => "../../components/TabBar.js"; const AppIcon = () => "../../components/AppIcon.js"; const _sfc_main = { __name: "Home", emits: ["change-page"], setup(__props, { emit: __emit }) { const userInfo = utils_session.getUserSession(); const storeInfo = utils_session.getStoreSession(); userInfo.id; const { goPage, navigateTo } = composables_useNavigator.useNavigator(); 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("doing"); const statusTabs = [ { title: "待确认", name: "new" }, { title: "进行中", name: "doing" }, { title: "已完成", name: "done" } ]; const orders = common_vendor.ref([]); const newApptCount = common_vendor.computed(() => orders.value.filter((o) => o.status === "new").length); const serviceTypes = common_vendor.ref([]); const showNewAppt = common_vendor.ref(false); const creatingAppt = common_vendor.ref(false); const petTypes = [ { label: "猫", value: "猫" }, { label: "狗", value: "狗" }, { label: "其他", value: "其他" } ]; const newAppt = common_vendor.ref({ petName: "", petType: "", serviceType: "", appointmentTime: "", remark: "" }); const appointmentDate = common_vendor.computed(() => { const raw = newAppt.value.appointmentTime || ""; return raw.includes("T") ? raw.split("T")[0] : ""; }); const appointmentTime = common_vendor.computed(() => { const raw = newAppt.value.appointmentTime || ""; if (!raw.includes("T")) return ""; return (raw.split("T")[1] || "").slice(0, 5); }); 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 tagClass = (status) => { return utils_appointment.getAppointmentTagClass(status); }; const onAppointmentDateChange = (e) => { var _a; const date = ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.value) || ""; const time = appointmentTime.value || "00:00"; newAppt.value.appointmentTime = date ? `${date}T${time}` : ""; }; const onAppointmentTimeOnlyChange = (e) => { var _a; const time = ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.value) || ""; const date = appointmentDate.value; if (!date) { common_vendor.index.showToast({ title: "请先选择日期", icon: "none" }); return; } newAppt.value.appointmentTime = `${date}T${time}`; }; const fetchAppointments = async () => { if (!storeInfo.id) return; const res = await api_index.getAppointmentList(null, storeInfo.id); 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 newCount = orders.value.filter((o) => o.status === "new").length; if (newCount > 0) { common_vendor.index.showToast({ title: `有 ${newCount} 个待确认预约`, icon: "none" }); } } }; const loadServiceTypes = async () => { if (!storeInfo.id) return; const res = await api_index.getServiceTypeList(storeInfo.id); if (res.code === 200) { serviceTypes.value = res.data.map((s) => ({ label: s.name, value: s.name })); } }; 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" }); fetchAppointments(); } 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" }); fetchAppointments(); } else { common_vendor.index.showToast({ title: r.message || "操作失败", icon: "none" }); } } }); }; const goReport = (item) => { navigateTo("report"); common_vendor.index.setStorageSync("petstore_report_prefill", JSON.stringify({ appointmentId: item.id, petName: item.petName, serviceType: item.serviceType, appointmentTime: item.appointmentTime })); }; const confirmNewAppt = async () => { const a = newAppt.value; if (!a.petName) { common_vendor.index.showToast({ title: "请输入宠物名字", icon: "none" }); return; } if (!a.petType) { common_vendor.index.showToast({ title: "请选择宠物类型", icon: "none" }); return; } if (!a.serviceType) { common_vendor.index.showToast({ title: "请选择服务类型", icon: "none" }); return; } if (!a.appointmentTime) { common_vendor.index.showToast({ title: "请选择预约时间", icon: "none" }); return; } creatingAppt.value = true; const res = await api_index.createAppointment({ ...a, storeId: storeInfo.id, userId: userInfo.id }); creatingAppt.value = false; if (res.code === 200) { common_vendor.index.showToast({ title: "预约创建成功", icon: "success" }); newAppt.value = { petName: "", petType: "", serviceType: "", appointmentTime: "", remark: "" }; showNewAppt.value = false; fetchAppointments(); } else { common_vendor.index.showToast({ title: res.message || "创建失败", icon: "none" }); } }; common_vendor.onMounted(() => { fetchAppointments(); loadServiceTypes(); }); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.unref(userInfo).role === "customer" }, common_vendor.unref(userInfo).role === "customer" ? { b: common_vendor.s(common_vendor.unref(navSafeStyle)), c: common_vendor.t(common_vendor.unref(storeInfo).name || "宠伴生活馆"), d: newAppt.value.petName, e: common_vendor.o(($event) => newAppt.value.petName = $event.detail.value), f: common_vendor.t(newAppt.value.petType || "请选择"), g: petTypes, h: common_vendor.o((e) => newAppt.value.petType = petTypes[e.detail.value].value), i: common_vendor.t(newAppt.value.serviceType || "请选择"), j: serviceTypes.value, k: common_vendor.o((e) => newAppt.value.serviceType = serviceTypes.value[e.detail.value].value), l: common_vendor.t(appointmentDate.value || "请选择日期"), m: appointmentDate.value, n: common_vendor.o(onAppointmentDateChange), o: common_vendor.t(appointmentTime.value || "请选择时间"), p: appointmentTime.value, q: common_vendor.o(onAppointmentTimeOnlyChange), r: newAppt.value.remark, s: common_vendor.o(($event) => newAppt.value.remark = $event.detail.value), t: creatingAppt.value, v: common_vendor.o(confirmNewAppt) } : common_vendor.e({ w: common_vendor.o(($event) => showNewAppt.value = true), x: common_vendor.s(common_vendor.unref(navSafeStyle)), y: common_vendor.f(statusTabs, (tab, k0, i0) => { return common_vendor.e({ a: common_vendor.t(tab.title), b: tab.name === "new" && newApptCount.value > 0 }, tab.name === "new" && newApptCount.value > 0 ? { c: common_vendor.t(newApptCount.value) } : {}, { d: tab.name, e: common_vendor.n({ active: currentStatus.value === tab.name }), f: common_vendor.o(($event) => currentStatus.value = tab.name, tab.name) }); }), z: filteredOrders.value.length > 0 }, filteredOrders.value.length > 0 ? { A: common_vendor.f(filteredOrders.value, (item, k0, i0) => { return common_vendor.e({ a: common_vendor.n(`dot-${item.status}`), b: "bd9bb22b-0-" + i0, c: common_vendor.t(item.petName), d: common_vendor.t(item.statusText), e: common_vendor.n(tagClass(item.status)), f: common_vendor.t(item.serviceType), g: common_vendor.n(`tag-${item.status}`), h: "bd9bb22b-1-" + i0, i: common_vendor.t(item.time), j: item.status === "new" }, item.status === "new" ? { k: common_vendor.o(($event) => startService(item), item.id), l: common_vendor.o(($event) => cancelService(item), item.id) } : item.status === "doing" ? { n: common_vendor.o(($event) => goReport(item), item.id) } : { o: common_vendor.t(item.status === "cancel" ? "已取消" : "已完成") }, { m: item.status === "doing", p: common_vendor.n(`card-${item.status}`), q: item.id }); }), B: common_vendor.p({ name: "profile", size: 14 }), C: common_vendor.p({ name: "orders", size: 13 }) } : {}, { D: filteredOrders.value.length === 0 }, filteredOrders.value.length === 0 ? {} : {}, { E: showNewAppt.value }, showNewAppt.value ? { F: common_vendor.o(($event) => showNewAppt.value = false), G: newAppt.value.petName, H: common_vendor.o(($event) => newAppt.value.petName = $event.detail.value), I: common_vendor.t(newAppt.value.petType || "请选择"), J: petTypes, K: common_vendor.o((e) => newAppt.value.petType = petTypes[e.detail.value].value), L: common_vendor.t(newAppt.value.serviceType || "请选择"), M: serviceTypes.value, N: common_vendor.o((e) => newAppt.value.serviceType = serviceTypes.value[e.detail.value].value), O: common_vendor.t(appointmentDate.value || "请选择日期"), P: appointmentDate.value, Q: common_vendor.o(onAppointmentDateChange), R: common_vendor.t(appointmentTime.value || "请选择时间"), S: appointmentTime.value, T: common_vendor.o(onAppointmentTimeOnlyChange), U: newAppt.value.remark, V: common_vendor.o(($event) => newAppt.value.remark = $event.detail.value), W: common_vendor.o(($event) => showNewAppt.value = false), X: creatingAppt.value, Y: common_vendor.o(confirmNewAppt), Z: common_vendor.o(() => { }), aa: common_vendor.o(($event) => showNewAppt.value = false) } : {}), { ab: common_vendor.o(common_vendor.unref(goPage)), ac: common_vendor.p({ ["current-page"]: "home" }) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-bd9bb22b"]]); wx.createPage(MiniProgramPage);