This commit is contained in:
@@ -31,7 +31,15 @@ Page({
|
||||
reviewPendingCount: 0,
|
||||
reviewLoading: false,
|
||||
reviewError: '',
|
||||
reviewingId: ''
|
||||
reviewingId: '',
|
||||
associationSheetVisible: false,
|
||||
associationLoading: false,
|
||||
associationError: '',
|
||||
associationApplicationId: '',
|
||||
associationArtists: [],
|
||||
associationItems: [],
|
||||
associationKeyword: '',
|
||||
associationSelectedId: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -73,7 +81,7 @@ Page({
|
||||
const data = await employeesApi.reviewApplications()
|
||||
const applications = (Array.isArray(data) ? data : []).map(item => ({
|
||||
...item,
|
||||
applicantNickname: item.applicantNickname || '待审核美甲师',
|
||||
applicantDisplayName: item.applicantNickname || '待审核美甲师',
|
||||
applicantAvatar: item.applicantAvatar || '',
|
||||
applicantMaskedPhone: item.applicantMaskedPhone || '',
|
||||
applicationTimeText: formatApplicationTime(item.createTime)
|
||||
@@ -88,10 +96,124 @@ Page({
|
||||
|
||||
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), '申请已通过')
|
||||
if (!id || this.data.reviewingId || this.data.associationLoading) return
|
||||
this.setData({
|
||||
associationApplicationId: String(id),
|
||||
associationKeyword: '',
|
||||
associationSelectedId: '',
|
||||
associationSheetVisible: true
|
||||
})
|
||||
await this.loadApprovalArtists()
|
||||
},
|
||||
|
||||
async loadApprovalArtists() {
|
||||
const applicationId = this.data.associationApplicationId
|
||||
if (!applicationId || this.data.associationLoading) return
|
||||
this.setData({ associationLoading: true, associationError: '' })
|
||||
try {
|
||||
const application = this.data.reviewApplications.find(item => String(item.id) === String(applicationId))
|
||||
const data = await employeesApi.unboundArtists(applicationId)
|
||||
const artists = (Array.isArray(data) ? data : []).map(item => ({
|
||||
id: item.userId || item.id,
|
||||
name: item.nickname || item.name || '未命名美甲师',
|
||||
avatar: item.avatar || ''
|
||||
}))
|
||||
const selectedId = application && application.targetArtistUserId
|
||||
? String(application.targetArtistUserId)
|
||||
: ''
|
||||
this.setData({
|
||||
associationArtists: artists,
|
||||
associationSelectedId: selectedId,
|
||||
associationItems: this.filterApprovalArtists(artists, this.data.associationKeyword)
|
||||
})
|
||||
if (!artists.length) {
|
||||
this.setData({ associationSheetVisible: false })
|
||||
await confirmModal({
|
||||
title: '暂时无法通过',
|
||||
content: '当前门店没有未关联微信的美甲师档案,请先新增美甲师,再审核这条申请。',
|
||||
confirmText: '知道了',
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
this.setData({ associationError: error.message || '未关联美甲师加载失败' })
|
||||
} finally {
|
||||
this.setData({ associationLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
filterApprovalArtists(artists, keywordValue) {
|
||||
const keyword = String(keywordValue || '').trim().toLowerCase()
|
||||
return (artists || [])
|
||||
.filter(item => !keyword || String(item.name || '').toLowerCase().includes(keyword))
|
||||
.map(item => ({
|
||||
id: item.id,
|
||||
title: item.name,
|
||||
subtitle: '当前门店 · 尚未关联微信登录',
|
||||
avatar: item.avatar,
|
||||
badge: '可关联'
|
||||
}))
|
||||
},
|
||||
|
||||
onApprovalSearch(event) {
|
||||
const associationKeyword = event.detail.value || ''
|
||||
this.setData({
|
||||
associationKeyword,
|
||||
associationItems: this.filterApprovalArtists(this.data.associationArtists, associationKeyword)
|
||||
})
|
||||
},
|
||||
|
||||
closeApprovalAssociation() {
|
||||
if (this.data.associationLoading || this.data.reviewingId) return
|
||||
this.setData({ associationSheetVisible: false })
|
||||
},
|
||||
|
||||
async selectApprovalArtist(event) {
|
||||
const artist = event.detail && event.detail.item
|
||||
const applicationId = this.data.associationApplicationId
|
||||
const application = this.data.reviewApplications.find(item => String(item.id) === String(applicationId))
|
||||
if (!artist || !application || this.data.reviewingId) return
|
||||
this.setData({ associationSelectedId: String(artist.id) })
|
||||
},
|
||||
|
||||
async confirmApprovalAssociation() {
|
||||
const applicationId = this.data.associationApplicationId
|
||||
const application = this.data.reviewApplications.find(item => String(item.id) === String(applicationId))
|
||||
const artist = this.data.associationArtists.find(item => String(item.id) === String(this.data.associationSelectedId))
|
||||
if (!artist || !application || this.data.reviewingId) {
|
||||
wx.showToast({ title: '请选择要关联的美甲师', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const useApplicantNickname = application.applicantNickname
|
||||
? await this.askProfileAdoption('昵称', application.applicantNickname)
|
||||
: false
|
||||
const useApplicantAvatar = application.applicantAvatar
|
||||
? await this.askProfileAdoption('头像', '已通过内容审核的申请头像')
|
||||
: false
|
||||
const summary = [
|
||||
`关联到:${artist.name || '所选美甲师'}`,
|
||||
useApplicantNickname ? '采用申请昵称' : '保留门店姓名',
|
||||
useApplicantAvatar ? '采用申请头像' : '保留门店头像'
|
||||
].join('\n')
|
||||
const confirmed = await confirmModal({ title: '确认关联并通过', content: summary, confirmText: '确认通过' })
|
||||
if (!confirmed.confirm) return
|
||||
|
||||
this.setData({ associationSheetVisible: false })
|
||||
await this.submitReview(applicationId, () => employeesApi.approveApplication(applicationId, {
|
||||
targetArtistUserId: artist.id,
|
||||
useApplicantNickname,
|
||||
useApplicantAvatar
|
||||
}), '申请已通过')
|
||||
},
|
||||
|
||||
askProfileAdoption(field, value) {
|
||||
return confirmModal({
|
||||
title: `采用申请${field}?`,
|
||||
content: field === '昵称' ? `申请昵称为“${value}”,采用后会替换门店员工姓名。` : '采用后会替换门店员工当前头像。',
|
||||
confirmText: `采用申请${field}`,
|
||||
cancelText: `保留门店${field}`
|
||||
}).then(result => Boolean(result.confirm))
|
||||
},
|
||||
|
||||
async rejectApplication(event) {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
{
|
||||
"navigationBarTitleText": "美甲师"
|
||||
"navigationBarTitleText": "美甲师",
|
||||
"usingComponents": {
|
||||
"entity-selector-sheet": "/components/entity-selector-sheet/index"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
const assert = require('assert')
|
||||
|
||||
const modalChoices = []
|
||||
const toasts = []
|
||||
const modals = []
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
getStorageSync: () => '',
|
||||
setStorageSync: () => {},
|
||||
removeStorageSync: () => {}
|
||||
}
|
||||
|
||||
const appMock = {
|
||||
globalData: {
|
||||
userInfo: { type: 2 },
|
||||
openEmployeeReview: true
|
||||
showToast: options => toasts.push(options.title),
|
||||
showModal: options => {
|
||||
modals.push(options)
|
||||
options.success({ confirm: modalChoices.shift() !== false })
|
||||
}
|
||||
}
|
||||
global.getApp = () => appMock
|
||||
global.getApp = () => ({ globalData: { userInfo: { type: 2 }, openEmployeeReview: false } })
|
||||
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
@@ -24,26 +22,61 @@ function createPage() {
|
||||
return {
|
||||
...definition,
|
||||
data: { ...definition.data, isManager: true },
|
||||
setData(values) { Object.assign(this.data, values) }
|
||||
setData(values) {
|
||||
Object.entries(values).forEach(([key, value]) => {
|
||||
const parts = key.split('.')
|
||||
let target = this.data
|
||||
for (let index = 0; index < parts.length - 1; index += 1) {
|
||||
target[parts[index]] = target[parts[index]] || {}
|
||||
target = target[parts[index]]
|
||||
}
|
||||
target[parts[parts.length - 1]] = value
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const employeesApi = require('../../api/employees')
|
||||
employeesApi.reviewApplications = async () => [{
|
||||
const planningApi = require('../../api/planning')
|
||||
const application = {
|
||||
id: 12,
|
||||
applicationNo: 'SALON-001',
|
||||
applicantNickname: '小周',
|
||||
createTime: '2026-10-12T10:30:00'
|
||||
}]
|
||||
applicantNickname: '微信昵称',
|
||||
applicantAvatar: 'https://example.test/avatar.png',
|
||||
targetArtistUserId: 22
|
||||
}
|
||||
employeesApi.reviewApplications = async () => [application]
|
||||
employeesApi.unboundArtists = async () => [
|
||||
{ userId: 22, nickname: '门店员工A', avatar: '/staff-a.png' },
|
||||
{ userId: 23, nickname: '门店员工B' }
|
||||
]
|
||||
employeesApi.list = async () => []
|
||||
planningApi.calendar = async () => ({ appointments: [], artists: [] })
|
||||
let submitted
|
||||
employeesApi.approveApplication = async (id, payload) => { submitted = { id, payload } }
|
||||
|
||||
const page = createPage()
|
||||
await page.onShow()
|
||||
page.data.reviewApplications = [application]
|
||||
await page.approveApplication({ currentTarget: { dataset: { id: 12 } } })
|
||||
assert.strictEqual(page.data.associationSheetVisible, true)
|
||||
assert.strictEqual(page.data.associationSelectedId, '22')
|
||||
assert.deepStrictEqual(page.data.associationItems.map(item => item.title), ['门店员工A', '门店员工B'])
|
||||
|
||||
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')
|
||||
modalChoices.push(true, false, true)
|
||||
await page.confirmApprovalAssociation()
|
||||
assert.deepStrictEqual(submitted, {
|
||||
id: '12',
|
||||
payload: { targetArtistUserId: 22, useApplicantNickname: true, useApplicantAvatar: false }
|
||||
})
|
||||
assert.strictEqual(page.data.associationSheetVisible, false)
|
||||
assert.strictEqual(page.data.reviewingId, '')
|
||||
assert(toasts.includes('申请已通过'))
|
||||
|
||||
employeesApi.unboundArtists = async () => []
|
||||
page.data.reviewApplications = [application]
|
||||
await page.approveApplication({ currentTarget: { dataset: { id: 12 } } })
|
||||
assert.strictEqual(page.data.associationSheetVisible, false)
|
||||
assert(modals.some(item => String(item.content || '').includes('当前门店没有未关联微信的美甲师档案')))
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
<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 class="review-name">{{item.applicantDisplayName}}</text>
|
||||
<text wx:if="{{item.targetArtistUserId}}" class="review-meta">已预关联美甲师</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>
|
||||
@@ -57,4 +58,22 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<entity-selector-sheet
|
||||
visible="{{associationSheetVisible}}"
|
||||
title="选择要关联的美甲师"
|
||||
keyword="{{associationKeyword}}"
|
||||
placeholder="搜索美甲师姓名"
|
||||
items="{{associationItems}}"
|
||||
selected-id="{{associationSelectedId}}"
|
||||
loading="{{associationLoading}}"
|
||||
error-text="{{associationError}}"
|
||||
empty-text="没有匹配的未关联美甲师"
|
||||
action-text="确认关联并通过"
|
||||
bind:search="onApprovalSearch"
|
||||
bind:select="selectApprovalArtist"
|
||||
bind:action="confirmApprovalAssociation"
|
||||
bind:retry="loadApprovalArtists"
|
||||
bind:close="closeApprovalAssociation"
|
||||
/>
|
||||
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user