149 lines
4.7 KiB
JavaScript
149 lines
4.7 KiB
JavaScript
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
|
const { request, customerRequest, customerTokenKey } = require("../../utils/request");
|
|
|
|
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: "沟通中",
|
|
replied: "已回复",
|
|
qualified: "已确认",
|
|
converted: "已转化",
|
|
closed: "已关闭",
|
|
};
|
|
|
|
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],
|
|
},
|
|
formId: "",
|
|
submitting: false,
|
|
formError: "",
|
|
},
|
|
onLoad(options) {
|
|
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 || "" });
|
|
})
|
|
.catch(() => {});
|
|
},
|
|
onShow() {
|
|
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 || "",
|
|
status: labels[item.status] || item.status,
|
|
replyNote: item.replyNote,
|
|
createdAt: new Date(item.createdAt).toLocaleDateString("zh-CN"),
|
|
})),
|
|
}),
|
|
)
|
|
.catch(() => {});
|
|
},
|
|
switchView(e) {
|
|
this.setData({ subView: e.currentTarget.dataset.view });
|
|
},
|
|
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 });
|
|
},
|
|
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: "请选择期望用餐日期" });
|
|
if (!formId) return this.setData({ formError: "咨询表单暂不可用,请稍后重试" });
|
|
this.setData({ submitting: true, formError: "" });
|
|
const send = () =>
|
|
customerRequest("/customer/inquiry-submissions", {
|
|
method: "POST",
|
|
data: { formId, values },
|
|
}).then((result) => {
|
|
wx.setStorageSync("latestInquirySubmission", result);
|
|
this.setData({ submitting: false, subView: "history" });
|
|
this.onShow();
|
|
wx.showToast({ title: "已提交,阿成会尽快联系你", icon: "none" });
|
|
});
|
|
const fail = (error) =>
|
|
this.setData({ submitting: false, formError: error.message || "提交失败,请重试" });
|
|
if (wx.getStorageSync(customerTokenKey())) return send().catch(fail);
|
|
wx.login({
|
|
success: (login) =>
|
|
request("/customer/session/wechat", { method: "POST", data: { code: login.code } })
|
|
.then((result) => {
|
|
wx.setStorageSync(customerTokenKey(), result.token);
|
|
return send();
|
|
})
|
|
.catch(fail),
|
|
fail,
|
|
});
|
|
},
|
|
});
|