功能:增加店长员工审核与登录提醒

This commit is contained in:
2026-10-12 16:45:42 +08:00
parent 247472fcae
commit e4aff0803a
23 changed files with 769 additions and 24 deletions
+107
View File
@@ -12,10 +12,28 @@ function buildScheduleSummary(item) {
return time ? `${mode} ${time}` : mode
}
function formatApplicationTime(value) {
if (!value) return ''
return String(value).replace('T', ' ').slice(0, 16)
}
function confirmModal(options) {
return new Promise(resolve => {
wx.showModal({ ...options, success: resolve, fail: () => resolve({ confirm: false }) })
})
}
Page({
data: {
employees: [],
loadError: '',
isManager: false,
reviewExpanded: false,
reviewApplications: [],
reviewPendingCount: 0,
reviewLoading: false,
reviewError: '',
reviewingId: '',
createModalVisible: false,
creating: false,
createForm: {
@@ -31,7 +49,96 @@ Page({
},
onLoad() {
const userInfo = getApp().globalData.userInfo || {}
this.setData({ isManager: Number(userInfo.type) === 2 })
this.loadEmployees()
if (Number(userInfo.type) === 2) this.loadReviewSummary()
},
onShow() {
const app = getApp()
if (!this.data.isManager || !app.globalData.openEmployeeReview) return
app.globalData.openEmployeeReview = false
this.setData({ reviewExpanded: true })
return this.loadReviewApplications()
},
async loadReviewSummary() {
if (!this.data.isManager) return
try {
const summary = await employeesApi.reviewSummary()
this.setData({ reviewPendingCount: Number(summary.pendingCount || 0) })
} catch (error) {
// 审核摘要失败不影响员工列表。
}
},
toggleReview() {
if (!this.data.isManager) return
const reviewExpanded = !this.data.reviewExpanded
this.setData({ reviewExpanded })
if (reviewExpanded) this.loadReviewApplications()
},
async loadReviewApplications() {
if (!this.data.isManager || this.data.reviewLoading) return
this.setData({ reviewLoading: true, reviewError: '' })
try {
const data = await employeesApi.reviewApplications()
const applications = (Array.isArray(data) ? data : []).map(item => ({
...item,
applicantNickname: item.applicantNickname || '待审核员工',
applicantAvatar: item.applicantAvatar || '',
applicantMaskedPhone: item.applicantMaskedPhone || '',
applicationTimeText: formatApplicationTime(item.createTime)
}))
this.setData({ reviewApplications: applications, reviewPendingCount: applications.length })
} catch (error) {
this.setData({ reviewError: error.message || '审核申请加载失败' })
} finally {
this.setData({ reviewLoading: false })
}
},
async approveApplication(event) {
const id = event.currentTarget.dataset.id
if (!id || this.data.reviewingId) return
const result = await confirmModal({ title: '通过员工申请', content: '确认允许该员工加入当前门店吗?' })
if (!result.confirm) return
await this.submitReview(id, () => employeesApi.approveApplication(id), '申请已通过')
},
async rejectApplication(event) {
const id = event.currentTarget.dataset.id
if (!id || this.data.reviewingId) return
const result = await confirmModal({
title: '驳回员工申请',
content: '',
editable: true,
placeholderText: '请输入驳回原因',
confirmText: '确认驳回'
})
if (!result.confirm) return
const reason = String(result.content || '').trim()
if (!reason) {
wx.showToast({ title: '请输入驳回原因', icon: 'none' })
return
}
await this.submitReview(id, () => employeesApi.rejectApplication(id, reason), '申请已驳回')
},
async submitReview(id, action, successMessage) {
this.setData({ reviewingId: String(id) })
try {
await action()
wx.showToast({ title: successMessage, icon: 'success' })
await Promise.all([this.loadReviewApplications(), this.loadEmployees()])
} catch (error) {
wx.showToast({ title: error.message || '申请状态已变化,请刷新重试', icon: 'none' })
await this.loadReviewApplications()
} finally {
this.setData({ reviewingId: '' })
}
},
async loadEmployees() {