fix: 收敛模板编辑发布契约并还原餐饮页面视觉
This commit is contained in:
1 parent
20bcb43534
commit
f4061a24bd
102 files changed
+4510
-870
No files matched your search
@@ -31,14 +31,15 @@ Page({
|
||||
// 字段全部来自后台已发布的咨询表单,模板只负责呈现。
|
||||
fields: [],
|
||||
values: {},
|
||||
displayValues: {},
|
||||
formId: "",
|
||||
submitting: false,
|
||||
formError: "",
|
||||
presentation: {},
|
||||
},
|
||||
onLoad(options) {
|
||||
this.offeringId = options.offeringId || "";
|
||||
loadWorkspaceWithFallback()
|
||||
this.offeringId = options?.offeringId || "";
|
||||
return loadWorkspaceWithFallback()
|
||||
.then((workspace) => {
|
||||
this.forms = workspace.inquiryForms || [];
|
||||
this.setData({ presentation: workspace.brand?.visualPresentation?.inquiry || {} });
|
||||
@@ -54,8 +55,15 @@ Page({
|
||||
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: {} });
|
||||
if (formId !== this.data.formId) {
|
||||
// 原型中的类型选项为按钮网格,人数/日期和预算/配送各占半行;数据与文案仍来自已发布表单。
|
||||
const fields = (form?.fields || []).map((field) => ({
|
||||
...field,
|
||||
useChips: field.key === "type" && (field.type === "select" || field.type === "radio"),
|
||||
halfWidth: ["people", "date", "budget", "delivery"].includes(field.key),
|
||||
}));
|
||||
this.setData({ formId, fields, values: {}, displayValues: {} });
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
// 本页是 tabBar 页,从详情页进入时参数经 openPage 暂存,而不是通过 onLoad 传入。
|
||||
@@ -90,10 +98,21 @@ Page({
|
||||
switchToForm() {
|
||||
this.setData({ subView: "form" });
|
||||
},
|
||||
chooseChip(e) {
|
||||
const { key, value } = e.currentTarget.dataset;
|
||||
this.setData({ ["values." + key]: 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 });
|
||||
if (option)
|
||||
this.setData({
|
||||
["values." + field.key]: option.value,
|
||||
["displayValues." + field.key]: option.label,
|
||||
});
|
||||
},
|
||||
checkboxChange(e) {
|
||||
this.setData({ ["values." + e.currentTarget.dataset.key]: e.detail.value });
|
||||
},
|
||||
input(e) {
|
||||
this.setData({ ["values." + e.currentTarget.dataset.key]: e.detail.value });
|
||||
@@ -101,7 +120,11 @@ Page({
|
||||
submit() {
|
||||
const { values, formId, fields } = this.data;
|
||||
const missing = fields.find(
|
||||
(field) => field.required && (values[field.key] === undefined || values[field.key] === ""),
|
||||
(field) =>
|
||||
field.required &&
|
||||
(values[field.key] === undefined ||
|
||||
values[field.key] === "" ||
|
||||
(Array.isArray(values[field.key]) && !values[field.key].length)),
|
||||
);
|
||||
if (missing) return this.setData({ formError: "请填写" + missing.label });
|
||||
if (!formId) return this.setData({ formError: "咨询表单暂不可用,请稍后重试" });
|
||||
|
||||
Reference in new issue
Block a user