style: 统一全仓代码格式
This commit is contained in:
1 parent
d811478d0f
commit
8033cabff9
30 files changed
+1183
-187
No files matched your search
@@ -1,10 +1,72 @@
|
||||
const { request, customerRequest } = require('../../utils/request');
|
||||
const { bookingViewModel } = require('../../utils/labels');
|
||||
const { getTemplate } = require('../../utils/templates');
|
||||
const { request, customerRequest } = require("../../utils/request");
|
||||
const { bookingViewModel } = require("../../utils/labels");
|
||||
const { getTemplate } = require("../../utils/templates");
|
||||
Page({
|
||||
data: { loading: true, error: '', bookings: [], cancellingId: '', template: getTemplate('personal') },
|
||||
onLoad() { this.load(); }, onShow() { this.load(); },
|
||||
load() { const token = wx.getStorageSync('customerToken'); if (!token) return this.setData({ loading: false, bookings: [], error: '' }); this.setData({ loading: true, error: '' }); Promise.all([customerRequest('/customer/bookings'), request('/public/brand')]).then(([items, brand]) => { getApp().globalData.brand = brand; const template = getTemplate(brand.templateKey); this.setData({ template, bookings: (Array.isArray(items) ? items : []).map((item) => bookingViewModel(item, template)), loading: false }); }).catch((error) => this.setData({ loading: false, error: error.message || '网络请求失败' })); },
|
||||
retry() { this.load(); }, contact() { const brand = getApp().globalData.brand || {}; if (brand.contactPhone) return wx.makePhoneCall({ phoneNumber: brand.contactPhone }); if (brand.contactWechat) return wx.showModal({ title: '联系品牌方', content: '微信号:' + brand.contactWechat, showCancel: false }); wx.showToast({ title: '暂未配置联系方式', icon: 'none' }); },
|
||||
cancel(e) { const id = e.currentTarget.dataset.id; if (this.data.cancellingId) return; wx.showModal({ title: '取消预约', content: '确定取消这笔预约吗?', success: (result) => { if (!result.confirm) return; this.setData({ cancellingId: id }); customerRequest('/customer/bookings/' + id + '/cancel', { method: 'POST', data: {} }).then(() => { this.setData({ cancellingId: '' }); wx.showToast({ title: '已取消预约', icon: 'success' }); this.load(); }).catch((error) => { this.setData({ cancellingId: '' }); wx.showToast({ title: error.message || '取消失败', icon: 'none' }); }); } }); }
|
||||
data: {
|
||||
loading: true,
|
||||
error: "",
|
||||
bookings: [],
|
||||
cancellingId: "",
|
||||
template: getTemplate("personal"),
|
||||
},
|
||||
onLoad() {
|
||||
this.load();
|
||||
},
|
||||
onShow() {
|
||||
this.load();
|
||||
},
|
||||
load() {
|
||||
const token = wx.getStorageSync("customerToken");
|
||||
if (!token) return this.setData({ loading: false, bookings: [], error: "" });
|
||||
this.setData({ loading: true, error: "" });
|
||||
Promise.all([customerRequest("/customer/bookings"), request("/public/brand")])
|
||||
.then(([items, brand]) => {
|
||||
getApp().globalData.brand = brand;
|
||||
const template = getTemplate(brand.templateKey);
|
||||
this.setData({
|
||||
template,
|
||||
bookings: (Array.isArray(items) ? items : []).map((item) =>
|
||||
bookingViewModel(item, template),
|
||||
),
|
||||
loading: false,
|
||||
});
|
||||
})
|
||||
.catch((error) => this.setData({ loading: false, error: error.message || "网络请求失败" }));
|
||||
},
|
||||
retry() {
|
||||
this.load();
|
||||
},
|
||||
contact() {
|
||||
const brand = getApp().globalData.brand || {};
|
||||
if (brand.contactPhone) return wx.makePhoneCall({ phoneNumber: brand.contactPhone });
|
||||
if (brand.contactWechat)
|
||||
return wx.showModal({
|
||||
title: "联系品牌方",
|
||||
content: "微信号:" + brand.contactWechat,
|
||||
showCancel: false,
|
||||
});
|
||||
wx.showToast({ title: "暂未配置联系方式", icon: "none" });
|
||||
},
|
||||
cancel(e) {
|
||||
const id = e.currentTarget.dataset.id;
|
||||
if (this.data.cancellingId) return;
|
||||
wx.showModal({
|
||||
title: "取消预约",
|
||||
content: "确定取消这笔预约吗?",
|
||||
success: (result) => {
|
||||
if (!result.confirm) return;
|
||||
this.setData({ cancellingId: id });
|
||||
customerRequest("/customer/bookings/" + id + "/cancel", { method: "POST", data: {} })
|
||||
.then(() => {
|
||||
this.setData({ cancellingId: "" });
|
||||
wx.showToast({ title: "已取消预约", icon: "success" });
|
||||
this.load();
|
||||
})
|
||||
.catch((error) => {
|
||||
this.setData({ cancellingId: "" });
|
||||
wx.showToast({ title: error.message || "取消失败", icon: "none" });
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user