58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
const { getGoodsOrderDetail, cancelGoodsOrder } = require('../../api/orderApi')
|
|
const { getExpressOrderDetail, cancelExpressOrder, completeExpressOrder } = require('../../api/expressApi')
|
|
const { getGroupBuyOrderDetail, cancelGroupBuyOrder } = require('../../api/groupBuyApi')
|
|
const { statusText } = require('../../utils/request')
|
|
const { toOrderDetail } = require('../../utils/orderPresenter')
|
|
|
|
Page({
|
|
data: {
|
|
type: '',
|
|
order: null
|
|
},
|
|
|
|
onLoad(options) {
|
|
this.type = options.type
|
|
this.id = Number(options.id)
|
|
this.setData({ type: this.type })
|
|
this.load()
|
|
},
|
|
|
|
load() {
|
|
const loaders = {
|
|
goods: getGoodsOrderDetail,
|
|
express: getExpressOrderDetail,
|
|
group: getGroupBuyOrderDetail
|
|
}
|
|
loaders[this.type](this.id)
|
|
.then((order) => this.setData({ order: toOrderDetail(this.type, order) }))
|
|
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
|
},
|
|
|
|
cancel() {
|
|
const actions = {
|
|
goods: () => cancelGoodsOrder(this.id),
|
|
express: () => cancelExpressOrder(this.id, '用户取消'),
|
|
group: () => cancelGroupBuyOrder(this.id)
|
|
}
|
|
actions[this.type]()
|
|
.then(() => {
|
|
wx.showToast({ title: '已取消' })
|
|
this.load()
|
|
})
|
|
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
|
},
|
|
|
|
completeExpress() {
|
|
completeExpressOrder(this.id)
|
|
.then(() => {
|
|
wx.showToast({ title: '已完成' })
|
|
this.load()
|
|
})
|
|
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
|
},
|
|
|
|
statusText(status) {
|
|
return statusText(status)
|
|
}
|
|
})
|