48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
const employeesApi = require('../../api/employees')
|
|
|
|
const EMPLOYEE_COLORS = ['#7BA7C7', '#89A98B', '#A893BC', '#D49A89', '#C9A66B', '#7E9A9A']
|
|
|
|
Page({
|
|
data: {
|
|
employees: [],
|
|
loadError: false,
|
|
errorMessage: ''
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadEmployees()
|
|
},
|
|
|
|
async loadEmployees() {
|
|
this.setData({ loadError: false, errorMessage: '' })
|
|
try {
|
|
const data = await employeesApi.list({ page: 1, size: 50 })
|
|
const list = data.list || data || []
|
|
this.setData({
|
|
employees: list.map((item, index) => ({
|
|
id: item.userId || item.id,
|
|
name: item.nickname || item.name || item.artistName || `美甲师${index + 1}`,
|
|
shortName: (item.nickname || item.name || '师').slice(-1),
|
|
color: item.color || EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length],
|
|
monthOrders: item.monthOrders || item.orderCount || 0,
|
|
monthAmount: item.monthAmount || item.turnover || 0
|
|
}))
|
|
})
|
|
} catch (error) {
|
|
this.setData({
|
|
employees: [],
|
|
loadError: true,
|
|
errorMessage: error.message || '员工数据加载失败,请检查服务连接后重试'
|
|
})
|
|
}
|
|
},
|
|
|
|
openDetail(event) {
|
|
wx.navigateTo({ url: `/pages/employee-detail/index?id=${event.currentTarget.dataset.id}` })
|
|
},
|
|
|
|
addEmployee() {
|
|
wx.showToast({ title: '员工创建沿用后台账号', icon: 'none' })
|
|
}
|
|
})
|