59 lines
2.1 KiB
JavaScript
59 lines
2.1 KiB
JavaScript
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
|
Page({
|
|
data: {
|
|
offering: null,
|
|
submitting: false,
|
|
eyebrow: "CONSULTATION",
|
|
title: "需求咨询",
|
|
subtitle: "提交信息后由主理人与你联系",
|
|
submitLabel: "提交需求",
|
|
values: {},
|
|
fields: [],
|
|
},
|
|
onLoad(options) {
|
|
loadWorkspaceWithFallback().then((workspace) => {
|
|
const offering =
|
|
(workspace.offerings || []).find((item) => item.id === options.offeringId) || null;
|
|
const form = (workspace.inquiryForms || [])[0];
|
|
const isQuote =
|
|
form?.purpose === "quote-request" ||
|
|
(workspace.plugins || []).some((plugin) => plugin.key === "quote-request");
|
|
this.setData({
|
|
offering,
|
|
fields: form?.fields || workspace.fields || [],
|
|
title: isQuote ? "获取报价方案" : "需求咨询",
|
|
eyebrow: isQuote ? "QUOTE REQUEST" : "CONSULTATION",
|
|
submitLabel: isQuote ? "提交报价需求" : "提交需求",
|
|
});
|
|
});
|
|
},
|
|
onInput(e) {
|
|
this.setData({ ["values." + e.currentTarget.dataset.key]: e.detail.value });
|
|
},
|
|
onComponentInput(e) {
|
|
this.setData({ ["values." + e.detail.key]: e.detail.value });
|
|
},
|
|
submit() {
|
|
const values = this.data.values;
|
|
if (!values.name || !values.phone)
|
|
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));
|
|
this.setData({ submitting: false });
|
|
wx.redirectTo({ url: "/pages/inquiry-success/index?id=" + id });
|
|
}, 500);
|
|
},
|
|
});
|