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

67 lines
2.0 KiB
JavaScript

const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
const { customerRequest, customerTokenKey } = require("../../utils/request");
const { openPage } = require("../../utils/navigation");
Page({
data: {
brand: {},
credentials: [],
cases: [],
promises: [],
presentation: {},
records: [],
error: "",
},
onLoad() {
loadWorkspaceWithFallback()
.then((workspace) =>
this.setData({
brand: workspace.brand || {},
presentation: workspace.brand?.visualPresentation?.profile || {},
credentials: (workspace.trustItems || []).filter((item) => item.type === "credential"),
cases: (workspace.trustItems || [])
.filter((item) => item.type === "case")
.map((item) => ({
...item,
entries: (item.config?.entries || []).map((entry, index) => ({
...entry,
index,
tone: index % 3,
})),
})),
promises: (workspace.trustItems || []).filter((item) => item.type === "promise"),
records: [],
}),
)
.catch((error) => this.setData({ error: error.message }));
},
onShow() {
this.loadRecords();
},
loadRecords() {
if (!wx.getStorageSync(customerTokenKey())) return this.setData({ records: [] });
customerRequest("/customer/inquiry-submissions")
.then((records) => this.setData({ records: Array.isArray(records) ? records : [] }))
.catch(() => this.setData({ records: [] }));
},
call() {
wx.makePhoneCall({
phoneNumber: (this.data.brand.phone || this.data.brand.contactPhone || "").replace(
/[^0-9-]/g,
"",
),
});
},
copyWechat() {
wx.setClipboardData({
data: this.data.brand.wechat || this.data.brand.contactWechat || "",
success: () => wx.showToast({ title: "微信号已复制", icon: "none" }),
});
},
recordsPage() {
openPage("/pages/records/index");
},
inquire() {
openPage("/pages/inquiry/index");
},
});