feat: 完成真实咨询提交闭环
This commit is contained in:
1 parent
16b0967dc5
commit
ba0069ae6d
9 files changed
+259
-70
No files matched your search
@@ -1,4 +1,5 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const { request, customerRequest } = require("../../utils/request");
|
||||
Page({
|
||||
data: {
|
||||
offering: null,
|
||||
@@ -9,18 +10,24 @@ Page({
|
||||
submitLabel: "提交需求",
|
||||
values: {},
|
||||
fields: [],
|
||||
formId: "",
|
||||
},
|
||||
onLoad(options) {
|
||||
loadWorkspaceWithFallback().then((workspace) => {
|
||||
const offering =
|
||||
(workspace.offerings || []).find((item) => item.id === options.offeringId) || null;
|
||||
const form = (workspace.inquiryForms || [])[0];
|
||||
const forms = workspace.inquiryForms || [];
|
||||
const form =
|
||||
forms.find((item) => item.targetId && item.targetId === options.offeringId) ||
|
||||
forms.find((item) => item.target === "brand") ||
|
||||
forms[0];
|
||||
const isQuote =
|
||||
form?.purpose === "quote-request" ||
|
||||
(workspace.plugins || []).some((plugin) => plugin.key === "quote-request");
|
||||
this.setData({
|
||||
offering,
|
||||
fields: form?.fields || workspace.fields || [],
|
||||
formId: form?.key || form?.id || "",
|
||||
title: isQuote ? "获取报价方案" : "需求咨询",
|
||||
eyebrow: isQuote ? "QUOTE REQUEST" : "CONSULTATION",
|
||||
submitLabel: isQuote ? "提交报价需求" : "提交需求",
|
||||
@@ -35,24 +42,43 @@ Page({
|
||||
},
|
||||
submit() {
|
||||
const values = this.data.values;
|
||||
if (!values.name || !values.phone)
|
||||
return wx.showToast({ title: "请填写联系人和手机号", icon: "none" });
|
||||
const missing = this.data.fields.find(
|
||||
(field) => field.required && (values[field.key] === undefined || values[field.key] === ""),
|
||||
);
|
||||
if (missing) return wx.showToast({ title: "请填写" + missing.label, icon: "none" });
|
||||
if (!this.data.formId) return wx.showToast({ title: "咨询表单暂不可用", icon: "none" });
|
||||
this.setData({ submitting: true });
|
||||
setTimeout(() => {
|
||||
const id = "LJ" + Date.now().toString().slice(-8);
|
||||
const record = {
|
||||
id,
|
||||
offeringName: this.data.offering ? this.data.offering.name : "门系统定制咨询",
|
||||
type: values.doorType || "门系统定制",
|
||||
project: values.city || "待确认项目",
|
||||
status: "待主理人复核图纸",
|
||||
createdAt: new Date().toLocaleDateString("zh-CN"),
|
||||
values,
|
||||
};
|
||||
const records = wx.getStorageSync("linjingInquiryRecords") || [];
|
||||
wx.setStorageSync("linjingInquiryRecords", [record].concat(records));
|
||||
const send = () =>
|
||||
customerRequest("/customer/inquiry-submissions", {
|
||||
method: "POST",
|
||||
data: { formId: this.data.formId, values },
|
||||
}).then((submission) => {
|
||||
const record = {
|
||||
id: submission.id,
|
||||
offeringName: this.data.offering ? this.data.offering.name : "品牌合作",
|
||||
type: this.data.title,
|
||||
project: "已提交需求",
|
||||
status: submission.status === "new" ? "待处理" : submission.status,
|
||||
createdAt: submission.createdAt,
|
||||
};
|
||||
wx.setStorageSync("latestInquirySubmission", record);
|
||||
this.setData({ submitting: false });
|
||||
wx.redirectTo({ url: "/pages/inquiry-success/index?id=" + submission.id });
|
||||
});
|
||||
const fail = (error) => {
|
||||
this.setData({ submitting: false });
|
||||
wx.redirectTo({ url: "/pages/inquiry-success/index?id=" + id });
|
||||
}, 500);
|
||||
wx.showToast({ title: error.message || "提交失败,请重试", icon: "none" });
|
||||
};
|
||||
if (wx.getStorageSync("customerToken")) return send().catch(fail);
|
||||
wx.login({
|
||||
success: (login) =>
|
||||
request("/customer/session/wechat", { method: "POST", data: { code: login.code } })
|
||||
.then((result) => {
|
||||
wx.setStorageSync("customerToken", result.token);
|
||||
return send();
|
||||
})
|
||||
.catch(fail),
|
||||
fail,
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user