101 lines
3.8 KiB
JavaScript
101 lines
3.8 KiB
JavaScript
const orderApi = require('../../api/order')
|
|
const afterSaleApi = require('../../api/after-sale')
|
|
const auth = require('../../utils/auth')
|
|
const navigation = require('../../utils/navigation')
|
|
const theme = require('../../utils/theme')
|
|
const { formatDateTime } = require('../../utils/format')
|
|
|
|
function safeList(value) {
|
|
if (Array.isArray(value)) return value
|
|
if (value && Array.isArray(value.list)) return value.list
|
|
return []
|
|
}
|
|
|
|
function buildNodes(order, reviews, changes, afterSales) {
|
|
const items = safeList(order && order.items)
|
|
const appointment = items.map(item => item && item.appointmentTime).find(Boolean)
|
|
const status = Number(order && order.status)
|
|
return [
|
|
{ key: 'created', title: '订单创建', text: formatDateTime(order && order.createTime) || '已提交', done: true, active: false },
|
|
{ key: 'appointment', title: '预约确认', text: formatDateTime(appointment) || '待确认', done: Boolean(appointment), active: status === 1 },
|
|
{ key: 'artist', title: '服务安排', text: changes.length ? `${changes.length} 条改派记录` : '按预约安排服务', done: changes.length > 0 || items.some(item => item.artistName), active: changes.some(item => String(item.status || '').toUpperCase() === 'PENDING') },
|
|
{ key: 'service', title: status === 3 ? '订单取消' : '服务完成', text: formatDateTime(order && (order.completeTime || order.cancelTime || order.updateTime)) || '等待服务', done: status === 2 || status === 3, active: status === 2 || status === 3 },
|
|
{ key: 'after-sale', title: '售后/评价', text: afterSales.length ? `${afterSales.length} 条售后` : (reviews.length ? `${reviews.length} 条评价` : '暂无记录'), done: afterSales.length > 0 || reviews.length > 0, active: afterSales.some(item => String(item.status || '').toUpperCase() === 'PENDING') }
|
|
]
|
|
}
|
|
|
|
Page({
|
|
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
|
|
orderId: '',
|
|
loading: false,
|
|
isLoggedIn: false,
|
|
order: null,
|
|
nodes: [],
|
|
items: [],
|
|
reviews: [],
|
|
changes: [],
|
|
afterSales: []
|
|
}),
|
|
|
|
onLoad(options) {
|
|
this.setData({
|
|
orderId: (options && (options.orderId || options.id)) || ''
|
|
})
|
|
},
|
|
|
|
onShow() {
|
|
this.loadProgress()
|
|
},
|
|
|
|
handleBack() {
|
|
navigation.goBack('/pages/orders/index')
|
|
},
|
|
|
|
async loadProgress() {
|
|
const isLoggedIn = auth.isLoggedIn()
|
|
this.setData({ isLoggedIn })
|
|
if (!isLoggedIn) {
|
|
navigation.openAuth(navigation.getCurrentPageUrl())
|
|
return
|
|
}
|
|
if (!this.data.orderId) return
|
|
|
|
this.setData({ loading: true })
|
|
try {
|
|
const [order, reviews, changes, afterSalePage] = await Promise.all([
|
|
orderApi.getOrderDetail(this.data.orderId),
|
|
orderApi.listOrderReviews(this.data.orderId).catch(() => []),
|
|
orderApi.listOrderArtistChangeRequests(this.data.orderId).catch(() => []),
|
|
afterSaleApi.getMyAfterSales({ page: 1, size: 50 }).catch(() => ({ list: [] }))
|
|
])
|
|
const afterSales = safeList(afterSalePage).filter(item => String(item.orderId) === String(this.data.orderId))
|
|
this.setData({
|
|
order,
|
|
items: safeList(order && order.items).map(item => ({
|
|
...item,
|
|
appointmentText: formatDateTime(item.appointmentTime)
|
|
})),
|
|
reviews,
|
|
changes,
|
|
afterSales,
|
|
nodes: buildNodes(order, reviews || [], changes || [], afterSales)
|
|
})
|
|
} catch (error) {
|
|
wx.showToast({
|
|
title: error.message || '服务进度加载失败',
|
|
icon: 'none'
|
|
})
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
openOrder() {
|
|
navigation.navigate('/pages/order-detail/index', { id: this.data.orderId })
|
|
},
|
|
|
|
openAfterSaleApply() {
|
|
navigation.navigate('/pages/after-sale-apply/index', { orderId: this.data.orderId })
|
|
}
|
|
})
|