功能:增加店长员工审核与登录提醒
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
const assert = require('assert')
|
||||
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
getStorageSync: () => '',
|
||||
setStorageSync: () => {},
|
||||
removeStorageSync: () => {}
|
||||
}
|
||||
|
||||
const appMock = {
|
||||
globalData: {
|
||||
userInfo: { type: 2 },
|
||||
openEmployeeReview: true
|
||||
}
|
||||
}
|
||||
global.getApp = () => appMock
|
||||
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
require('./index')
|
||||
|
||||
function createPage() {
|
||||
return {
|
||||
...definition,
|
||||
data: { ...definition.data, isManager: true },
|
||||
setData(values) { Object.assign(this.data, values) }
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const employeesApi = require('../../api/employees')
|
||||
employeesApi.reviewApplications = async () => [{
|
||||
id: 12,
|
||||
applicationNo: 'SALON-001',
|
||||
applicantNickname: '小周',
|
||||
createTime: '2026-10-12T10:30:00'
|
||||
}]
|
||||
|
||||
const page = createPage()
|
||||
await page.onShow()
|
||||
|
||||
assert.strictEqual(appMock.globalData.openEmployeeReview, false)
|
||||
assert.strictEqual(page.data.reviewExpanded, true)
|
||||
assert.strictEqual(page.data.reviewPendingCount, 1)
|
||||
assert.strictEqual(page.data.reviewApplications[0].applicationTimeText, '2026-10-12 10:30')
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
@@ -1,9 +1,40 @@
|
||||
<view class="page">
|
||||
<view class="list-heading">
|
||||
<text>美甲师</text>
|
||||
<button wx:if="{{isManager}}" class="compact-btn review-toggle {{reviewExpanded ? 'is-open' : ''}}" bindtap="toggleReview">
|
||||
审核<text wx:if="{{reviewPendingCount > 0}}" class="review-badge">{{reviewPendingCount}}</text>
|
||||
</button>
|
||||
<button class="compact-btn" bindtap="addEmployee">新增</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{isManager && reviewExpanded}}" class="review-panel card">
|
||||
<view class="review-panel-head">
|
||||
<view><text class="review-title">员工申请审核</text><text class="review-subtitle">仅显示当前门店待处理申请</text></view>
|
||||
<text class="review-count">{{reviewPendingCount}} 项</text>
|
||||
</view>
|
||||
<view wx:if="{{reviewLoading}}" class="review-state">正在加载申请…</view>
|
||||
<view wx:elif="{{reviewError}}" class="review-state review-error">
|
||||
<text>{{reviewError}}</text>
|
||||
<button class="secondary-btn review-retry" bindtap="loadReviewApplications">重试</button>
|
||||
</view>
|
||||
<view wx:elif="{{reviewApplications.length === 0}}" class="review-state">暂无待审核员工申请</view>
|
||||
<view wx:else class="review-list">
|
||||
<view wx:for="{{reviewApplications}}" wx:key="id" class="review-item">
|
||||
<image class="review-avatar" src="{{item.applicantAvatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill"></image>
|
||||
<view class="review-info">
|
||||
<text class="review-name">{{item.applicantNickname}}</text>
|
||||
<text wx:if="{{item.applicantMaskedPhone}}" class="review-meta">{{item.applicantMaskedPhone}}</text>
|
||||
<text class="review-meta">{{item.shopName || '当前门店'}} · {{item.applicationTimeText}}</text>
|
||||
<text class="review-number">申请编号 {{item.applicationNo}}</text>
|
||||
</view>
|
||||
<view class="review-actions">
|
||||
<button class="review-action reject" data-id="{{item.id}}" disabled="{{reviewingId}}" bindtap="rejectApplication">驳回</button>
|
||||
<button class="review-action approve" data-id="{{item.id}}" loading="{{reviewingId == item.id}}" disabled="{{reviewingId}}" bindtap="approveApplication">通过</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="list">
|
||||
<view wx:if="{{loadError}}" class="empty card">
|
||||
<text>{{loadError}}</text>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.list-heading text {
|
||||
.list-heading > text {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,173 @@
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.list-heading .review-toggle {
|
||||
position: relative;
|
||||
margin-right: 12rpx;
|
||||
margin-left: 0;
|
||||
border-color: #c9d8d2;
|
||||
background: #eef5f2;
|
||||
color: #2f6f62;
|
||||
}
|
||||
|
||||
.list-heading .review-toggle.is-open {
|
||||
background: #2f6f62;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.review-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 30rpx;
|
||||
height: 30rpx;
|
||||
margin-left: 8rpx;
|
||||
padding: 0 7rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #d9685f;
|
||||
color: #fff;
|
||||
font-size: 19rpx;
|
||||
line-height: 30rpx;
|
||||
}
|
||||
|
||||
.review-panel {
|
||||
margin-bottom: 22rpx;
|
||||
padding: 22rpx;
|
||||
border: 1rpx solid #dce8e3;
|
||||
background: #f8fcfa;
|
||||
}
|
||||
|
||||
.review-panel-head,
|
||||
.review-item,
|
||||
.review-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.review-panel-head {
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.review-title,
|
||||
.review-subtitle,
|
||||
.review-name,
|
||||
.review-meta,
|
||||
.review-number {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.review-title {
|
||||
color: #25211d;
|
||||
font-size: 28rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.review-subtitle {
|
||||
margin-top: 4rpx;
|
||||
color: #8b847c;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
|
||||
.review-count {
|
||||
color: #2f6f62;
|
||||
font-size: 23rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.review-list {
|
||||
display: grid;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.review-item {
|
||||
gap: 14rpx;
|
||||
padding: 18rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 5rpx 18rpx rgba(47, 111, 98, 0.07);
|
||||
}
|
||||
|
||||
.review-avatar {
|
||||
flex: 0 0 auto;
|
||||
width: 72rpx;
|
||||
height: 72rpx;
|
||||
border-radius: 50%;
|
||||
background: #eee9e1;
|
||||
}
|
||||
|
||||
.review-info {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.review-name {
|
||||
color: #28231f;
|
||||
font-size: 27rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.review-meta,
|
||||
.review-number {
|
||||
margin-top: 4rpx;
|
||||
overflow: hidden;
|
||||
color: #817a72;
|
||||
font-size: 20rpx;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.review-number {
|
||||
color: #aaa198;
|
||||
font-size: 18rpx;
|
||||
}
|
||||
|
||||
.review-actions {
|
||||
flex: 0 0 auto;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
.review-action {
|
||||
width: auto;
|
||||
min-width: 82rpx;
|
||||
height: 54rpx;
|
||||
margin: 0;
|
||||
padding: 0 15rpx;
|
||||
border-radius: 999rpx;
|
||||
font-size: 21rpx;
|
||||
font-weight: 800;
|
||||
line-height: 54rpx;
|
||||
}
|
||||
|
||||
.review-action.reject {
|
||||
border: 1rpx solid #e7c7c2;
|
||||
background: #fff5f3;
|
||||
color: #a8554e;
|
||||
}
|
||||
|
||||
.review-action.approve {
|
||||
border: 1rpx solid #2f6f62;
|
||||
background: #2f6f62;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.review-state {
|
||||
padding: 34rpx 12rpx;
|
||||
color: #8c857d;
|
||||
font-size: 23rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.review-state.review-error {
|
||||
color: #a8554e;
|
||||
}
|
||||
|
||||
.review-retry {
|
||||
width: 150rpx;
|
||||
min-width: 150rpx;
|
||||
margin: 16rpx auto 0;
|
||||
}
|
||||
|
||||
.employee-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user