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

47 lines
1.4 KiB
JavaScript

const { request } = require("../../utils/request");
const config = require("../../utils/config");
const { getTemplate } = require("../../utils/templates");
Page({
data: { loading: true, error: "", brand: {}, services: [], copy: {} },
onLoad() {
this.load();
},
load() {
this.setData({ loading: true, error: "" });
Promise.all([request("/public/brand"), request("/public/offerings")])
.then(([brand, services]) => {
getApp().globalData.brand = brand;
wx.setNavigationBarTitle({ title: brand.name || "个人品牌" });
const copy = getTemplate(brand.templateKey);
this.setData({
brand: { ...brand, coverUrl: brand.coverUrl || "/assets/brand/home-hero.jpg" },
services,
copy,
loading: false,
});
})
.catch(() => this.setData({ loading: false, error: "暂时无法加载内容" }));
},
selectService(event) {
wx.navigateTo({
url: "/pages/booking/index?offeringId=" + encodeURIComponent(event.currentTarget.dataset.id),
});
},
goServices() {
wx.switchTab({ url: "/pages/services/index" });
},
goPrivateChef() {
wx.navigateTo({ url: "/pages/booking/index?type=private_chef" });
},
goBooking() {
wx.navigateTo({ url: "/pages/booking/index" });
},
goBookings() {
wx.switchTab({ url: "/pages/bookings/index" });
},
goHome() {
wx.switchTab({ url: "/pages/index/index" });
},
});