Files
persionalBrand/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js
T

74 lines
2.3 KiB
JavaScript

const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
const { openPage } = require("../../utils/navigation");
// 每种内容对应一个固定视觉区域,按已配置记录优先选择,避免旧记录遮住编辑结果。
function selectSlot(items, type) {
return (
items
.filter((item) => item.type === type)
.sort(
(a, b) =>
Number(Object.keys(b.config || {}).length > 0) -
Number(Object.keys(a.config || {}).length > 0),
)[0] || null
);
}
Page({
data: {
brand: {},
presentation: {},
schedule: null,
coverage: null,
process: null,
loading: true,
error: false,
},
onLoad() {
this.load();
},
load() {
this.setData({ loading: true, error: false });
return loadWorkspaceWithFallback()
.then((workspace) => {
const items = workspace.trustItems || [];
const schedule = selectSlot(items, "schedule");
const coverage = selectSlot(items, "coverage");
const process = selectSlot(items, "process");
const config = schedule?.config || {};
const rows = [
{
title: config.weekdayLabel,
detail: config.weekdayDetail,
hours: config.weekdayHours,
tag: config.weekdayTag,
tone: "orange",
},
{
title: config.weekendLabel,
detail: config.weekendDetail,
hours: config.weekendHours,
tag: config.weekendTag,
tone: "blue",
},
].filter((row) => row.title && row.detail);
const steps = Array.isArray(process?.config?.steps)
? process.config.steps
.filter((step) => step.title && step.detail)
.map((step, index) => ({ ...step, index }))
: [];
this.setData({
brand: workspace.brand || {},
presentation: workspace.brand?.visualPresentation?.service || {},
schedule: rows.length ? { ...schedule, rows } : null,
coverage:
coverage?.config?.pickupDetail && coverage?.config?.deliveryDetail ? coverage : null,
process: steps.length ? { ...process, steps } : null,
loading: false,
});
})
.catch(() => this.setData({ loading: false, error: true }));
},
inquire() {
openPage("/pages/inquiry/index");
},
});