fix: 修复模板页面跳转并移除无入口的下单页
新增运行时 openPage/takePageQuery,tabBar 页自动使用 switchTab 并传递参数 - 编译器写入 tabPages,并拒绝 navigateTo/redirectTo 到 tabBar 页或 switchTab 带参数 - 阿成首页、套餐、出摊、主理人、详情、记录、成功页跳转统一改用 openPage - 套餐筛选改用后台业务提供项分类;详情跳咨询时携带业务提供项 - 移除 capability-booking:小程序无入口且依赖已删除的 /public/brand,需求由咨询表单覆盖"
This commit is contained in:
1 parent
a97cc860cf
commit
55989a5dfe
29 files changed
+353
-119
No files matched your search
@@ -1,31 +1,7 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const { request, customerRequest, customerTokenKey } = require("../../utils/request");
|
||||
const { takePageQuery } = require("../../utils/navigation");
|
||||
|
||||
const typeOptions = [
|
||||
"日常留餐",
|
||||
"宿舍开黑餐",
|
||||
"社团 / 班级活动",
|
||||
"生日聚会",
|
||||
"考试周加餐",
|
||||
"其他需求",
|
||||
];
|
||||
const peopleOptions = [
|
||||
"1 人(单点)",
|
||||
"2-4 人(寝室小聚)",
|
||||
"5-10 人(部门小聚)",
|
||||
"10-30 人(社团活动)",
|
||||
"30 人以上(大型活动)",
|
||||
];
|
||||
const budgetOptions = [
|
||||
"15 元左右 / 人(实惠)",
|
||||
"18-22 元 / 人(荤素双拼)",
|
||||
"25 元以上 / 人(高规格定制)",
|
||||
];
|
||||
const deliveryOptions = [
|
||||
"摊位自取(报手机尾号即拿)",
|
||||
"送至宿舍楼下(满 3 份)",
|
||||
"送至指定教室 / 场地",
|
||||
];
|
||||
const labels = {
|
||||
new: "待处理",
|
||||
reviewing: "沟通中",
|
||||
@@ -35,50 +11,69 @@ const labels = {
|
||||
closed: "已关闭",
|
||||
};
|
||||
|
||||
/** 按提交时的表单快照把记录还原成「标签:值」,后台以后改字段,历史记录仍然可读。 */
|
||||
function summarize(item) {
|
||||
const fields = Array.isArray(item.fieldsSnapshot) ? item.fieldsSnapshot : [];
|
||||
const values = item.values || {};
|
||||
return fields
|
||||
.filter((field) => values[field.key] !== undefined && values[field.key] !== "")
|
||||
.map((field) => ({
|
||||
key: field.key,
|
||||
label: field.label || field.key,
|
||||
value: values[field.key],
|
||||
}));
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
subView: "form",
|
||||
records: [],
|
||||
typeOptions,
|
||||
peopleOptions,
|
||||
budgetOptions,
|
||||
deliveryOptions,
|
||||
peopleIndex: 1,
|
||||
budgetIndex: 1,
|
||||
deliveryIndex: 0,
|
||||
values: {
|
||||
type: "日常留餐",
|
||||
people: peopleOptions[1],
|
||||
budget: budgetOptions[1],
|
||||
delivery: deliveryOptions[0],
|
||||
},
|
||||
// 字段全部来自后台已发布的咨询表单,模板只负责呈现。
|
||||
fields: [],
|
||||
values: {},
|
||||
formId: "",
|
||||
submitting: false,
|
||||
formError: "",
|
||||
},
|
||||
onLoad(options) {
|
||||
this.offeringId = options.offeringId || "";
|
||||
loadWorkspaceWithFallback()
|
||||
.then((workspace) => {
|
||||
const form =
|
||||
(workspace.inquiryForms || []).find((item) => item.targetId === options.offeringId) ||
|
||||
(workspace.inquiryForms || []).find((item) => item.target === "brand") ||
|
||||
workspace.inquiryForms?.[0];
|
||||
this.setData({ formId: form?.key || form?.id || "" });
|
||||
this.forms = workspace.inquiryForms || [];
|
||||
this.selectForm();
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch((error) => this.setData({ formError: error.message }));
|
||||
},
|
||||
/** 按目标业务提供项选择表单;没有专属表单时回退到品牌表单。 */
|
||||
selectForm() {
|
||||
const forms = this.forms || [];
|
||||
const form =
|
||||
(this.offeringId && forms.find((item) => item.targetId === this.offeringId)) ||
|
||||
forms.find((item) => item.target === "brand") ||
|
||||
forms[0];
|
||||
const formId = form?.key || form?.id || "";
|
||||
if (formId !== this.data.formId)
|
||||
this.setData({ formId, fields: form?.fields || [], values: {} });
|
||||
},
|
||||
onShow() {
|
||||
// 本页是 tabBar 页,从详情页进入时参数经 openPage 暂存,而不是通过 onLoad 传入。
|
||||
const query = takePageQuery("pages/inquiry/index");
|
||||
if (query.offeringId) {
|
||||
this.offeringId = query.offeringId;
|
||||
this.setData({ subView: "form" });
|
||||
if (this.forms) this.selectForm();
|
||||
}
|
||||
this.loadRecords();
|
||||
},
|
||||
loadRecords() {
|
||||
if (!wx.getStorageSync(customerTokenKey())) return;
|
||||
customerRequest("/customer/inquiry-submissions")
|
||||
.then((items) =>
|
||||
this.setData({
|
||||
records: (items || []).map((item) => ({
|
||||
...item,
|
||||
type: item.inquiryForm?.name || item.values?.type || "品牌咨询",
|
||||
people: item.values?.people || "",
|
||||
time: item.values?.date || "",
|
||||
delivery: item.values?.delivery || "",
|
||||
remark: item.values?.remark || "",
|
||||
title: item.inquiryForm?.name || "品牌咨询",
|
||||
summary: summarize(item),
|
||||
status: labels[item.status] || item.status,
|
||||
replyNote: item.replyNote,
|
||||
createdAt: new Date(item.createdAt).toLocaleDateString("zh-CN"),
|
||||
@@ -93,32 +88,20 @@ Page({
|
||||
switchToForm() {
|
||||
this.setData({ subView: "form" });
|
||||
},
|
||||
chooseType(e) {
|
||||
this.setData({ "values.type": e.currentTarget.dataset.value });
|
||||
},
|
||||
choosePeople(e) {
|
||||
const index = Number(e.detail.value);
|
||||
this.setData({ peopleIndex: index, "values.people": peopleOptions[index] });
|
||||
},
|
||||
chooseBudget(e) {
|
||||
const index = Number(e.detail.value);
|
||||
this.setData({ budgetIndex: index, "values.budget": budgetOptions[index] });
|
||||
},
|
||||
chooseDelivery(e) {
|
||||
const index = Number(e.detail.value);
|
||||
this.setData({ deliveryIndex: index, "values.delivery": deliveryOptions[index] });
|
||||
},
|
||||
chooseDate(e) {
|
||||
this.setData({ "values.date": e.detail.value });
|
||||
choose(e) {
|
||||
const field = this.data.fields.find((item) => item.key === e.currentTarget.dataset.key);
|
||||
const option = field?.options?.[Number(e.detail.value)];
|
||||
if (option) this.setData({ ["values." + field.key]: option.value });
|
||||
},
|
||||
input(e) {
|
||||
this.setData({ ["values." + e.currentTarget.dataset.key]: e.detail.value });
|
||||
},
|
||||
submit() {
|
||||
const { values, formId } = this.data;
|
||||
if (!values.phone)
|
||||
return this.setData({ formError: "请填写手机号或微信号,以便阿成加您发排菜菜单" });
|
||||
if (!values.date) return this.setData({ formError: "请选择期望用餐日期" });
|
||||
const { values, formId, fields } = this.data;
|
||||
const missing = fields.find(
|
||||
(field) => field.required && (values[field.key] === undefined || values[field.key] === ""),
|
||||
);
|
||||
if (missing) return this.setData({ formError: "请填写" + missing.label });
|
||||
if (!formId) return this.setData({ formError: "咨询表单暂不可用,请稍后重试" });
|
||||
this.setData({ submitting: true, formError: "" });
|
||||
const send = () =>
|
||||
@@ -128,7 +111,7 @@ Page({
|
||||
}).then((result) => {
|
||||
wx.setStorageSync("latestInquirySubmission", result);
|
||||
this.setData({ submitting: false, subView: "history" });
|
||||
this.onShow();
|
||||
this.loadRecords();
|
||||
wx.showToast({ title: "已提交,阿成会尽快联系你", icon: "none" });
|
||||
});
|
||||
const fail = (error) =>
|
||||
|
||||
Reference in new issue
Block a user