统一甲屿云命名体系
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
const customersApi = require('../../api/customers')
|
||||
|
||||
function canCreateAppointment() {
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo || {}
|
||||
return Number(userInfo.type) !== 3
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
id: '',
|
||||
canCreateAppointment: true,
|
||||
avatarText: '客',
|
||||
customer: {},
|
||||
stats: { orderCount: 0, amount: 0, lastTime: '-' },
|
||||
orders: [],
|
||||
loadError: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
id: options.id || '',
|
||||
canCreateAppointment: canCreateAppointment()
|
||||
})
|
||||
this.loadCustomer()
|
||||
},
|
||||
|
||||
async loadCustomer() {
|
||||
if (!this.data.id) {
|
||||
this.setData({
|
||||
customer: {},
|
||||
stats: { orderCount: 0, amount: 0, lastTime: '-' },
|
||||
orders: [],
|
||||
loadError: '缺少客户 ID'
|
||||
})
|
||||
return
|
||||
}
|
||||
try {
|
||||
const detail = await customersApi.detail(this.data.id)
|
||||
if (!detail) {
|
||||
throw new Error('客户详情不存在')
|
||||
}
|
||||
const customer = {
|
||||
id: detail.id,
|
||||
name: detail.nickname || detail.name || detail.account || '客户',
|
||||
phone: detail.contactPhone || detail.phone || '未填写'
|
||||
}
|
||||
this.setData({
|
||||
customer,
|
||||
avatarText: String(customer.name || '客').slice(-1),
|
||||
stats: {
|
||||
orderCount: detail.orderCount || detail.totalOrderCount || 0,
|
||||
amount: detail.totalAmount || detail.consumeAmount || 0,
|
||||
lastTime: detail.lastOrderTime || detail.lastConsumeTime || '-'
|
||||
},
|
||||
orders: Array.isArray(detail.orders) ? detail.orders : [],
|
||||
loadError: ''
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
customer: {},
|
||||
stats: { orderCount: 0, amount: 0, lastTime: '-' },
|
||||
orders: [],
|
||||
loadError: error.message || '客户详情加载失败'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
createAppointment() {
|
||||
if (!this.data.canCreateAppointment) {
|
||||
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const customer = this.data.customer || {}
|
||||
wx.navigateTo({
|
||||
url: `/pages/appointment-form/index?customerName=${encodeURIComponent(customer.name || '')}&phone=${encodeURIComponent(customer.phone || '')}`
|
||||
})
|
||||
},
|
||||
|
||||
back() {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user