改造员工页列表和新增入口
This commit is contained in:
@@ -12,11 +12,23 @@ function buildScheduleSummary(item) {
|
||||
}
|
||||
|
||||
function buildRoleText(item) {
|
||||
return Number(item.type) === 2 ? '店长' : '店员'
|
||||
if (Number(item.type) === 2 || item.identity === '店长') {
|
||||
return '店长'
|
||||
}
|
||||
return item.identity || item.roleName || '美甲师'
|
||||
}
|
||||
|
||||
function buildStatusCode(item) {
|
||||
return item.currentStatusCode || (Number(item.status) === 0 ? 'DISABLED' : 'NORMAL')
|
||||
}
|
||||
|
||||
function buildStatusText(item, statusCode) {
|
||||
return item.currentStatusText || (statusCode === 'DISABLED' ? '停用' : statusCode === 'REST' ? '休假' : '正常')
|
||||
}
|
||||
|
||||
function toEmployeeRow(item, index) {
|
||||
const name = item.nickname || item.name || item.artistName || `美甲师${index + 1}`
|
||||
const statusCode = buildStatusCode(item)
|
||||
return {
|
||||
id: item.userId || item.id,
|
||||
name,
|
||||
@@ -25,16 +37,48 @@ function toEmployeeRow(item, index) {
|
||||
color: item.color || EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length],
|
||||
monthOrders: item.monthOrders || item.orderCount || 0,
|
||||
monthAmount: item.monthAmount || item.turnover || 0,
|
||||
todayOrders: item.todayOrders || item.todayAppointments || item.todayAppointmentCount || 0,
|
||||
avgAmount: item.avgAmount || 0,
|
||||
scheduleSummary: buildScheduleSummary(item),
|
||||
roleText: buildRoleText(item),
|
||||
statusCode,
|
||||
statusText: buildStatusText(item, statusCode),
|
||||
statusClass: statusCode === 'DISABLED' ? 'disabled' : statusCode === 'REST' ? 'rest' : 'normal',
|
||||
isManager: Number(item.type) === 2
|
||||
}
|
||||
}
|
||||
|
||||
function buildStatusFilters(rows) {
|
||||
const countByStatus = rows.reduce((map, item) => {
|
||||
map[item.statusCode] = (map[item.statusCode] || 0) + 1
|
||||
return map
|
||||
}, {})
|
||||
return [
|
||||
{ value: 'ALL', label: '全部', count: rows.length },
|
||||
{ value: 'NORMAL', label: '正常', count: countByStatus.NORMAL || 0 },
|
||||
{ value: 'REST', label: '休假', count: countByStatus.REST || 0 },
|
||||
{ value: 'DISABLED', label: '停用', count: countByStatus.DISABLED || 0 }
|
||||
]
|
||||
}
|
||||
|
||||
function filterEmployees(rows, status) {
|
||||
if (status === 'ALL') {
|
||||
return rows
|
||||
}
|
||||
return rows.filter(item => item.statusCode === status)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
managers: [],
|
||||
allEmployees: [],
|
||||
employees: [],
|
||||
statusFilters: [
|
||||
{ value: 'ALL', label: '全部', count: 0 },
|
||||
{ value: 'NORMAL', label: '正常', count: 0 },
|
||||
{ value: 'REST', label: '休假', count: 0 },
|
||||
{ value: 'DISABLED', label: '停用', count: 0 }
|
||||
],
|
||||
activeStatus: 'ALL',
|
||||
loadError: '',
|
||||
createModalVisible: false,
|
||||
creating: false,
|
||||
@@ -61,18 +105,28 @@ Page({
|
||||
const rows = list.map(toEmployeeRow)
|
||||
this.setData({
|
||||
loadError: '',
|
||||
managers: rows.filter(item => item.isManager),
|
||||
employees: rows.filter(item => !item.isManager)
|
||||
allEmployees: rows,
|
||||
statusFilters: buildStatusFilters(rows),
|
||||
employees: filterEmployees(rows, this.data.activeStatus)
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
managers: [],
|
||||
allEmployees: [],
|
||||
employees: [],
|
||||
loadError: error.message || '美甲师列表加载失败'
|
||||
statusFilters: buildStatusFilters([]),
|
||||
loadError: error.message || '员工列表加载失败'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
switchStatus(event) {
|
||||
const status = event.currentTarget.dataset.status
|
||||
this.setData({
|
||||
activeStatus: status,
|
||||
employees: filterEmployees(this.data.allEmployees, status)
|
||||
})
|
||||
},
|
||||
|
||||
openDetail(event) {
|
||||
wx.navigateTo({ url: `/pages/employee-detail/index?id=${event.currentTarget.dataset.id}` })
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user