fix: 完善预约订单交互与状态展示

This commit is contained in:
que01 committed 2026-09-19 11:51:58 +08:00
1 parent cd242767a6
commit 38e2a0fb64
5 files changed
+39 -7

No files matched your search

+10 -2
View File
@@ -1,2 +1,10 @@
const API=getApp().globalData.apiBaseUrl;
Page({data:{loading:true,bookings:[]},onLoad(){this.load()},onShow(){this.load()},load(){const token=wx.getStorageSync('customerToken');if(!token){this.setData({loading:false});return}wx.request({url:API+'/customer/bookings',header:{Authorization:'Bearer '+token},success:r=>this.setData({bookings:r.data,loading:false}),fail:()=>this.setData({loading:false})})},cancel(e){const id=e.currentTarget.dataset.id;wx.showModal({title:'取消预约',content:'确定取消这笔预约吗?',success:r=>{if(!r.confirm)return;wx.request({url:API+'/customer/bookings/'+id+'/cancel',method:'POST',header:{Authorization:'Bearer '+wx.getStorageSync('customerToken'),'content-type':'application/json'},data:{},success:res=>{if(res.statusCode<300)this.load();else wx.showToast({title:res.data?.error?.message||'取消失败',icon:'none'})},fail:err=>wx.showToast({title:err.errMsg||'网络请求失败',icon:'none'})})}})}});
const API = getApp().globalData.apiBaseUrl;
const STATUS_LABELS = { received: '待确认', contacting: '沟通中', confirmed: '已确认', completed: '已完成', cancelled: '已取消' };
const FULFILLMENT_LABELS = { pickup: '自取', delivery: '配送' };
Page({
data: { loading: true, error: '', bookings: [], cancellingId: '' },
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: '' }); wx.request({ url: API + '/customer/bookings', header: { Authorization: 'Bearer ' + token }, success: (res) => { if (res.statusCode >= 300) return this.setData({ loading: false, error: res.data?.error?.message || '订单加载失败' }); const bookings = (Array.isArray(res.data) ? res.data : []).map((item) => ({ ...item, statusLabel: STATUS_LABELS[item.status] || '未知状态', fulfillmentLabel: FULFILLMENT_LABELS[item.fulfillmentType] || '待确认', serviceName: item.service?.name || item.items?.[0]?.serviceName || '红烧肉家常套餐', quantityLabel: `${item.items?.[0]?.quantity || 1} 份` })); this.setData({ bookings, loading: false }); }, fail: (error) => this.setData({ loading: false, error: error.errMsg || '网络请求失败' }) }); },
retry() { this.load(); }, contact() { 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 }); wx.request({ url: API + '/customer/bookings/' + id + '/cancel', method: 'POST', header: { Authorization: 'Bearer ' + wx.getStorageSync('customerToken'), 'content-type': 'application/json' }, data: {}, success: (res) => { this.setData({ cancellingId: '' }); if (res.statusCode < 300) { wx.showToast({ title: '已取消预约', icon: 'success' }); this.load(); } else wx.showToast({ title: res.data?.error?.message || '取消失败', icon: 'none' }); }, fail: (error) => { this.setData({ cancellingId: '' }); wx.showToast({ title: error.errMsg || '网络请求失败', icon: 'none' }); } }); } }); }
});