Files

67 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2026-06-05 16:10:58 +08:00
const employeesApi = require('../../api/employees')
const config = require('../../utils/config')
2026-06-04 16:39:06 +08:00
const mock = require('../../utils/mock')
2026-06-05 16:10:58 +08:00
const normalizeEmployee = (item = {}) => ({
id: item.userId || item.id,
name: item.nickname || item.name || item.artistName || '美甲师',
shortName: (item.nickname || item.name || item.artistName || '师').slice(-1),
color: item.color || '#7BA7C7',
monthOrders: item.monthOrders || item.orderCount || 0,
monthAmount: item.monthAmount || item.turnover || 0,
avgAmount: item.avgAmount || item.averageAmount || 0
})
2026-06-04 16:39:06 +08:00
Page({
data: {
id: '',
2026-06-05 16:10:58 +08:00
employee: {},
loadError: false,
errorMessage: ''
2026-06-04 16:39:06 +08:00
},
2026-06-05 16:10:58 +08:00
onLoad(options = {}) {
const id = options.id || ''
this.setData({ id })
this.loadEmployee()
},
async loadEmployee() {
this.setData({ loadError: false, errorMessage: '' })
try {
const employee = await employeesApi.detail(this.data.id)
this.setData({ employee: normalizeEmployee(employee) })
} catch (error) {
if (config.USE_DEV_MOCK_DATA) {
const artist = mock.artists.find(item => String(item.id) === String(this.data.id)) || mock.artists[0]
this.setData({
employee: normalizeEmployee({
...artist,
monthOrders: 32,
monthAmount: 5800,
avgAmount: 181
})
})
} else {
this.setData({
employee: {},
loadError: true,
errorMessage: error.message || '员工详情加载失败,请检查服务连接后重试'
})
2026-06-04 16:39:06 +08:00
}
2026-06-05 16:10:58 +08:00
}
2026-06-04 16:39:06 +08:00
},
go(event) {
2026-06-05 16:10:58 +08:00
if (this.data.loadError) {
wx.showToast({ title: '请先重新加载员工详情', icon: 'none' })
return
}
2026-06-04 16:39:06 +08:00
wx.navigateTo({ url: `${event.currentTarget.dataset.url}?id=${this.data.id}` })
},
back() {
wx.navigateBack()
}
})