Files
persionalBrand/packages/capability-booking/miniapp/pages/booking/index.js
T
que01 55989a5dfe fix: 修复模板页面跳转并移除无入口的下单页
新增运行时 openPage/takePageQuery,tabBar 页自动使用 switchTab 并传递参数
- 编译器写入 tabPages,并拒绝 navigateTo/redirectTo 到 tabBar 页或 switchTab 带参数
- 阿成首页、套餐、出摊、主理人、详情、记录、成功页跳转统一改用 openPage
- 套餐筛选改用后台业务提供项分类;详情跳咨询时携带业务提供项
- 移除 capability-booking:小程序无入口且依赖已删除的 /public/brand,需求由咨询表单覆盖"
2026-09-27 10:10:23 +08:00

94 lines
3.5 KiB
JavaScript

const { request, customerRequest, customerTokenKey } = require("../../utils/request");
const { getTemplate } = require("../../utils/booking-templates");
const { openPage } = require("../../utils/navigation");
Page({
data: {
service: {},
form: {},
offeringId: "",
quantity: 1,
fulfillment: "pickup",
submitting: false,
template: getTemplate("personal"),
},
onLoad(query) {
Promise.all([request("/public/offerings"), request("/public/brand")])
.then(([services, brand]) => {
const list = Array.isArray(services) ? services : [];
const service =
list.find((item) => item.id === query.offeringId || item.id === query.serviceId) ||
list.find((item) => item.priceAmount !== null) ||
{};
this.setData({
service,
offeringId: service.id || "",
template: getTemplate(brand.templateKey),
});
})
.catch(() => wx.showToast({ title: "服务加载失败", icon: "none" }));
},
input(event) {
this.setData({ ["form." + event.currentTarget.dataset.key]: event.detail.value });
},
chooseFulfillment(event) {
this.setData({ fulfillment: event.currentTarget.dataset.value });
},
increase() {
if (this.data.quantity < 50) this.setData({ quantity: this.data.quantity + 1 });
},
decrease() {
if (this.data.quantity > 1) this.setData({ quantity: this.data.quantity - 1 });
},
submit() {
const form = this.data.form;
if (!this.data.offeringId) return wx.showToast({ title: "请先选择服务", icon: "none" });
if (!form.customerName || !form.wechatId)
return wx.showToast({ title: "请填写称呼和联系方式", icon: "none" });
if (this.data.fulfillment === "delivery" && !form.deliveryAddress)
return wx.showToast({ title: "请填写" + this.data.template.locationLabel, icon: "none" });
this.setData({ submitting: true });
const send = () =>
customerRequest("/customer/bookings", {
method: "POST",
data: {
requestType: this.data.template.requestType,
customerName: form.customerName,
wechatId: form.wechatId,
contactPreference: "wechat",
fulfillmentType: this.data.fulfillment,
deliveryAddress: form.deliveryAddress,
requestedTime: form.requestedTime,
note: form.note,
items: [{ offeringId: this.data.offeringId, quantity: this.data.quantity }],
},
})
.then(() => {
this.setData({ submitting: false });
wx.showToast({ title: "预约已提交" });
setTimeout(() => openPage("/pages/bookings/index"), 500);
})
.catch((error) => {
this.setData({ submitting: false });
wx.showToast({ title: error.message || "提交失败", icon: "none" });
});
const token = wx.getStorageSync(customerTokenKey());
if (token) return send();
wx.login({
success: (login) =>
request("/customer/session/wechat", { method: "POST", data: { code: login.code } })
.then((result) => {
wx.setStorageSync(customerTokenKey(), result.token);
send();
})
.catch((error) => {
this.setData({ submitting: false });
wx.showToast({ title: error.message || "微信登录失败", icon: "none" });
}),
fail: (error) => {
this.setData({ submitting: false });
wx.showToast({ title: error.errMsg || "微信登录失败", icon: "none" });
},
});
},
});