Files
persionalBrand/apps/miniapp/pages/services/index.js
T

72 lines
2.0 KiB
JavaScript

const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
const config = require("../../utils/config");
Page({
data: {
loading: false,
error: "",
offerings: [],
filtered: [],
modules: [],
theme: {},
brand: {},
presentation: {},
category: "all",
categories: [],
pageRenderer: "",
loadedBrandSlug: "",
templateKey: "",
navigation: [],
},
onLoad() {
this.loadWorkspace();
},
onShow() {
if (this.data.loadedBrandSlug && this.data.loadedBrandSlug !== config.brandSlug) {
this.loadWorkspace();
}
},
loadWorkspace() {
loadWorkspaceWithFallback()
.then((workspace) => {
const items = workspace.offerings || [];
this.setData({
offerings: items,
filtered: items,
categories: [
{ key: "all", label: "全部" },
...Array.from(new Set(items.map((item) => item.category).filter(Boolean))).map(
(key) => ({
key,
label: key,
}),
),
],
modules: workspace.modules || [],
theme: workspace.theme || {},
brand: workspace.brand || {},
presentation: workspace.brand?.visualPresentation?.offerings || {},
brand: workspace.brand || {},
pageRenderer: workspace.pageRenderers?.offerings || "",
loadedBrandSlug: config.brandSlug,
templateKey: workspace.visualTemplate?.key || "",
navigation: workspace.navigation || [],
});
})
.catch((error) => this.setData({ error: error.message }));
},
switchCategory(e) {
const category = e.currentTarget.dataset.category;
const items = this.data.offerings || [];
this.setData({
category,
filtered: category === "all" ? items : items.filter((item) => item.category === category),
});
},
open(e) {
wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id });
},
inquire() {
wx.navigateTo({ url: "/pages/inquiry/index" });
},
});