petstore-frontend/dist/dev/mp-weixin/pages/home/Home.js
2026-04-12 22:57:48 +08:00

275 lines
11 KiB
JavaScript

"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.o(($event) => showNewAppt.value = true),
b: common_vendor.s(common_vendor.unref(navSafeStyle)),
c: 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)
});
}),
d: filteredOrders.value.length > 0
}, filteredOrders.value.length > 0 ? {
e: 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
});
}),
f: common_vendor.p({
name: "profile",
size: 14
}),
g: common_vendor.p({
name: "orders",
size: 13
})
} : {}, {
h: filteredOrders.value.length === 0
}, filteredOrders.value.length === 0 ? {} : {}, {
i: showNewAppt.value
}, showNewAppt.value ? {
j: common_vendor.o(($event) => showNewAppt.value = false),
k: newAppt.value.petName,
l: common_vendor.o(($event) => newAppt.value.petName = $event.detail.value),
m: common_vendor.t(newAppt.value.petType || "请选择"),
n: petTypes,
o: common_vendor.o((e) => newAppt.value.petType = petTypes[e.detail.value].value),
p: common_vendor.t(newAppt.value.serviceType || "请选择"),
q: serviceTypes.value,
r: common_vendor.o((e) => newAppt.value.serviceType = serviceTypes.value[e.detail.value].value),
s: common_vendor.t(appointmentDate.value || "请选择日期"),
t: appointmentDate.value,
v: common_vendor.o(onAppointmentDateChange),
w: common_vendor.t(appointmentTime.value || "请选择时间"),
x: appointmentTime.value,
y: common_vendor.o(onAppointmentTimeOnlyChange),
z: newAppt.value.remark,
A: common_vendor.o(($event) => newAppt.value.remark = $event.detail.value),
B: common_vendor.o(($event) => showNewAppt.value = false),
C: creatingAppt.value,
D: common_vendor.o(confirmNewAppt),
E: common_vendor.o(() => {
}),
F: common_vendor.o(($event) => showNewAppt.value = false)
} : {}, {
G: common_vendor.o(common_vendor.unref(goPage)),
H: common_vendor.p({
["current-page"]: "home"
})
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-bd9bb22b"]]);
wx.createPage(MiniProgramPage);