修复回归安全问题并补充验证
This commit is contained in:
@@ -255,3 +255,25 @@ button::after {
|
||||
color: #a39b91;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.error-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
margin: 18rpx 0;
|
||||
padding: 22rpx;
|
||||
border-color: rgba(191, 111, 104, 0.22);
|
||||
background: #fff8f6;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
color: #7f4540;
|
||||
font-size: 26rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.error-desc {
|
||||
color: #9b6a62;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const config = require('../../utils/config')
|
||||
const mock = require('../../utils/mock')
|
||||
|
||||
Page({
|
||||
@@ -6,21 +7,34 @@ Page({
|
||||
id: '',
|
||||
appointment: {},
|
||||
avatarText: '',
|
||||
timeText: ''
|
||||
timeText: '',
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
onLoad(options = {}) {
|
||||
this.setData({ id: options.id || '' })
|
||||
this.loadDetail()
|
||||
},
|
||||
|
||||
async loadDetail() {
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
try {
|
||||
const appointment = await planningApi.appointment(this.data.id)
|
||||
this.applyAppointment(appointment)
|
||||
} catch (error) {
|
||||
const demo = mock.buildCalendar(new Date()).appointments[0]
|
||||
this.applyAppointment(demo)
|
||||
if (config.USE_DEV_MOCK_DATA) {
|
||||
const demo = mock.buildCalendar(new Date()).appointments[0]
|
||||
this.applyAppointment(demo)
|
||||
} else {
|
||||
this.setData({
|
||||
appointment: {},
|
||||
avatarText: '',
|
||||
timeText: '',
|
||||
loadError: true,
|
||||
errorMessage: error.message || '预约详情加载失败,请检查服务连接后重试'
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -28,11 +42,17 @@ Page({
|
||||
this.setData({
|
||||
appointment,
|
||||
avatarText: String(appointment.customerName || '客').slice(0, 1),
|
||||
timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`
|
||||
timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`,
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
})
|
||||
},
|
||||
|
||||
async updateStatus(status) {
|
||||
if (!this.data.appointment.orderId) {
|
||||
wx.showToast({ title: '预约数据未加载', icon: 'none' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
await planningApi.updateStatus(this.data.appointment.orderId, status)
|
||||
wx.showToast({ title: '已更新' })
|
||||
|
||||
@@ -1,46 +1,54 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card detail-card">
|
||||
<view class="detail-head">
|
||||
<view class="detail-person">
|
||||
<view class="avatar">{{avatarText}}</view>
|
||||
<view>
|
||||
<text class="customer">{{appointment.customerName}}</text>
|
||||
<text class="phone">{{appointment.customerPhone}}</text>
|
||||
<view wx:if="{{loadError}}" class="card error-card">
|
||||
<text class="error-title">数据加载失败</text>
|
||||
<text class="error-desc">{{errorMessage}}</text>
|
||||
<button class="compact-btn" bindtap="loadDetail">重试</button>
|
||||
</view>
|
||||
|
||||
<block wx:else>
|
||||
<view class="card detail-card">
|
||||
<view class="detail-head">
|
||||
<view class="detail-person">
|
||||
<view class="avatar">{{avatarText}}</view>
|
||||
<view>
|
||||
<text class="customer">{{appointment.customerName}}</text>
|
||||
<text class="phone">{{appointment.customerPhone}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="detail-actions">
|
||||
<text class="tag">{{appointment.statusText}}</text>
|
||||
<button class="small-action" bindtap="goTransfer">改派</button>
|
||||
</view>
|
||||
</view>
|
||||
<view class="detail-actions">
|
||||
<text class="tag">{{appointment.statusText}}</text>
|
||||
<button class="small-action" bindtap="goTransfer">改派</button>
|
||||
<view class="detail-grid">
|
||||
<view>
|
||||
<text class="label">项目</text>
|
||||
<text class="value">{{appointment.productTitle}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">美甲师</text>
|
||||
<text class="value">{{appointment.artistName}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">时间</text>
|
||||
<text class="value">{{timeText}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">时长</text>
|
||||
<text class="value">{{appointment.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="detail-grid">
|
||||
<view>
|
||||
<text class="label">项目</text>
|
||||
<text class="value">{{appointment.productTitle}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">美甲师</text>
|
||||
<text class="value">{{appointment.artistName}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">时间</text>
|
||||
<text class="value">{{timeText}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">时长</text>
|
||||
<text class="value">{{appointment.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">备注</view>
|
||||
<view class="card note-card">{{appointment.remark || '暂无备注'}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">备注</view>
|
||||
<view class="card note-card">{{appointment.remark || '暂无备注'}}</view>
|
||||
</view>
|
||||
|
||||
<view class="fixed-bottom action-row">
|
||||
<button class="secondary-btn" bindtap="confirm">确认</button>
|
||||
<button class="primary-btn" bindtap="complete">完成</button>
|
||||
<button class="danger-btn" bindtap="cancel">取消</button>
|
||||
</view>
|
||||
<view class="fixed-bottom action-row">
|
||||
<button class="secondary-btn" bindtap="confirm">确认</button>
|
||||
<button class="primary-btn" bindtap="complete">完成</button>
|
||||
<button class="danger-btn" bindtap="cancel">取消</button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const productsApi = require('../../api/products')
|
||||
const config = require('../../utils/config')
|
||||
const mock = require('../../utils/mock')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
const toDurationMinutes = value => {
|
||||
if (typeof value === 'number') return value
|
||||
const parsed = parseInt(String(value || ''), 10)
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : 60
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
form: {
|
||||
@@ -16,15 +23,16 @@ Page({
|
||||
remark: ''
|
||||
},
|
||||
products: [],
|
||||
artists: mock.artists,
|
||||
artists: config.USE_DEV_MOCK_DATA ? mock.artists : [],
|
||||
selectedProduct: {},
|
||||
selectedArtist: {},
|
||||
conflictTip: '',
|
||||
conflictLevel: 'free',
|
||||
loading: false
|
||||
loading: false,
|
||||
optionError: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
onLoad(options = {}) {
|
||||
this.setData({
|
||||
'form.appointmentDate': options.date || dateUtil.formatDate(new Date()),
|
||||
'form.artistId': options.artistId || ''
|
||||
@@ -33,22 +41,38 @@ Page({
|
||||
},
|
||||
|
||||
async loadOptions() {
|
||||
const fallbackProducts = [
|
||||
{ id: 1, title: '纯色美甲', approximateDuration: '90分钟' },
|
||||
{ id: 2, title: '猫眼延长', approximateDuration: '120分钟' },
|
||||
{ id: 3, title: '手部护理', approximateDuration: '60分钟' }
|
||||
]
|
||||
let products = []
|
||||
let artists = []
|
||||
let optionError = ''
|
||||
try {
|
||||
const productsData = await productsApi.list({ page: 1, size: 100 })
|
||||
const products = productsData.list || productsData || fallbackProducts
|
||||
this.setData({ products })
|
||||
products = productsData.list || productsData || []
|
||||
} catch (error) {
|
||||
this.setData({ products: fallbackProducts })
|
||||
optionError = error.message || '项目数据加载失败'
|
||||
products = config.USE_DEV_MOCK_DATA
|
||||
? [
|
||||
{ id: 1, title: '纯色美甲', approximateDuration: '90分钟' },
|
||||
{ id: 2, title: '猫眼延长', approximateDuration: '120分钟' },
|
||||
{ id: 3, title: '手部护理', approximateDuration: '60分钟' }
|
||||
]
|
||||
: []
|
||||
}
|
||||
if (this.data.form.artistId) {
|
||||
const selectedArtist = this.data.artists.find(item => String(item.id) === String(this.data.form.artistId)) || {}
|
||||
this.setData({ selectedArtist })
|
||||
|
||||
try {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: this.data.form.appointmentDate,
|
||||
endDate: this.data.form.appointmentDate
|
||||
})
|
||||
artists = calendar.artists || []
|
||||
} catch (error) {
|
||||
optionError = optionError || error.message || '美甲师数据加载失败'
|
||||
artists = config.USE_DEV_MOCK_DATA ? mock.artists : []
|
||||
}
|
||||
|
||||
const selectedArtist = this.data.form.artistId
|
||||
? artists.find(item => String(item.id) === String(this.data.form.artistId)) || {}
|
||||
: {}
|
||||
this.setData({ products, artists, selectedArtist, optionError })
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
@@ -60,7 +84,7 @@ Page({
|
||||
|
||||
onDateChange(event) {
|
||||
this.setData({ 'form.appointmentDate': event.detail.value })
|
||||
this.checkAvailability()
|
||||
this.loadOptions()
|
||||
},
|
||||
|
||||
onTimeChange(event) {
|
||||
@@ -73,7 +97,7 @@ Page({
|
||||
this.setData({
|
||||
selectedProduct,
|
||||
'form.productId': selectedProduct.id,
|
||||
'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || 60)
|
||||
'form.durationMinutes': String(toDurationMinutes(selectedProduct.approximateDuration))
|
||||
})
|
||||
this.checkAvailability()
|
||||
},
|
||||
@@ -101,40 +125,42 @@ Page({
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
|
||||
let calendar
|
||||
try {
|
||||
let calendar
|
||||
try {
|
||||
calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
endDate: form.appointmentDate,
|
||||
artistId: form.artistId
|
||||
})
|
||||
} catch (error) {
|
||||
calendar = mock.buildCalendar(form.appointmentDate)
|
||||
}
|
||||
const conflicts = (calendar.appointments || []).filter(item => {
|
||||
if (String(item.artistId) !== String(form.artistId) || item.date !== form.appointmentDate) return false
|
||||
if (item.status === 3 || item.statusText === '已取消') return false
|
||||
const itemStart = Number(item.startMinute || dateUtil.minutesOfDay((item.startTime || '').slice(11, 16)))
|
||||
const itemEnd = itemStart + Number(item.durationMinutes || 60)
|
||||
return startMinute < itemEnd && endMinute > itemStart
|
||||
calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
endDate: form.appointmentDate,
|
||||
artistId: form.artistId
|
||||
})
|
||||
if (conflicts.length > 0) {
|
||||
const first = conflicts[0]
|
||||
const itemStart = Number(first.startMinute || dateUtil.minutesOfDay((first.startTime || '').slice(11, 16)))
|
||||
const itemEnd = itemStart + Number(first.durationMinutes || 60)
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${dateUtil.timeFromMinutes(itemStart)}-${dateUtil.timeFromMinutes(itemEnd)} 已有预约`
|
||||
} catch (error) {
|
||||
if (config.USE_DEV_MOCK_DATA) {
|
||||
calendar = mock.buildCalendar(form.appointmentDate)
|
||||
} else {
|
||||
const tip = error.message || '暂未获取到排班,无法确认该时段是否可预约'
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${form.appointmentTime}-${dateUtil.timeFromMinutes(endMinute)} 可预约`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'free' })
|
||||
return { ok: true, tip }
|
||||
} catch (error) {
|
||||
const tip = '暂未获取到排班,请保存时以系统校验为准'
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'warn' })
|
||||
return { ok: true, tip }
|
||||
}
|
||||
|
||||
const conflicts = (calendar.appointments || []).filter(item => {
|
||||
if (String(item.artistId) !== String(form.artistId) || item.date !== form.appointmentDate) return false
|
||||
if (item.status === 3 || item.statusText === '已取消') return false
|
||||
const itemStart = Number(item.startMinute || dateUtil.minutesOfDay((item.startTime || '').slice(11, 16)))
|
||||
const itemEnd = itemStart + Number(item.durationMinutes || 60)
|
||||
return startMinute < itemEnd && endMinute > itemStart
|
||||
})
|
||||
if (conflicts.length > 0) {
|
||||
const first = conflicts[0]
|
||||
const itemStart = Number(first.startMinute || dateUtil.minutesOfDay((first.startTime || '').slice(11, 16)))
|
||||
const itemEnd = itemStart + Number(first.durationMinutes || 60)
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${dateUtil.timeFromMinutes(itemStart)}-${dateUtil.timeFromMinutes(itemEnd)} 已有预约`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${form.appointmentTime}-${dateUtil.timeFromMinutes(endMinute)} 可预约`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'free' })
|
||||
return { ok: true, tip }
|
||||
},
|
||||
|
||||
async submit() {
|
||||
@@ -145,7 +171,7 @@ Page({
|
||||
}
|
||||
const availability = await this.checkAvailability()
|
||||
if (!availability.ok) {
|
||||
wx.showToast({ title: availability.tip || '该时段已被预约', icon: 'none' })
|
||||
wx.showToast({ title: availability.tip || '该时段不可预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
<view class="page no-tab">
|
||||
<view wx:if="{{optionError}}" class="card error-card">
|
||||
<text class="error-title">选项加载不完整</text>
|
||||
<text class="error-desc">{{optionError}}</text>
|
||||
<button class="compact-btn" bindtap="loadOptions">重试</button>
|
||||
</view>
|
||||
|
||||
<view class="card form-card">
|
||||
<view class="field">
|
||||
<text class="field-label">客户姓名</text>
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const config = require('../../utils/config')
|
||||
const mock = require('../../utils/mock')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
const normalizeArtists = artists => (artists || []).map((item, index) => ({
|
||||
id: item.id || item.userId || item.artistId,
|
||||
name: item.name || item.nickname || item.artistName || `美甲师${index + 1}`,
|
||||
shortName: item.shortName || String(item.name || item.nickname || '师').slice(-1),
|
||||
color: item.color || ['#7BA7C7', '#89A98B', '#A893BC', '#D49A89'][index % 4],
|
||||
statusText: item.statusText || '可接单',
|
||||
availableStatus: item.availableStatus || 'free',
|
||||
availableText: item.availableText || '可接'
|
||||
}))
|
||||
|
||||
Page({
|
||||
data: {
|
||||
id: '',
|
||||
@@ -9,18 +20,35 @@ Page({
|
||||
selectedArtistId: '',
|
||||
date: dateUtil.formatDate(new Date()),
|
||||
time: '13:00',
|
||||
loading: false
|
||||
loading: false,
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
id: options.id || '',
|
||||
artists: mock.artists.map((item, index) => ({
|
||||
...item,
|
||||
availableStatus: index === 1 ? 'busy' : index === 2 ? 'full' : 'free',
|
||||
availableText: index === 1 ? '有冲突' : index === 2 ? '已满' : '可接'
|
||||
}))
|
||||
})
|
||||
onLoad(options = {}) {
|
||||
this.setData({ id: options.id || '' })
|
||||
this.loadArtists()
|
||||
},
|
||||
|
||||
async loadArtists() {
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
try {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: this.data.date,
|
||||
endDate: this.data.date
|
||||
})
|
||||
this.setData({ artists: normalizeArtists(calendar.artists || []) })
|
||||
} catch (error) {
|
||||
if (config.USE_DEV_MOCK_DATA) {
|
||||
this.setData({ artists: normalizeArtists(mock.artists) })
|
||||
} else {
|
||||
this.setData({
|
||||
artists: [],
|
||||
loadError: true,
|
||||
errorMessage: error.message || '美甲师可接状态加载失败,请检查服务连接后重试'
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
selectArtist(event) {
|
||||
@@ -28,7 +56,8 @@ Page({
|
||||
},
|
||||
|
||||
onDateChange(event) {
|
||||
this.setData({ date: event.detail.value })
|
||||
this.setData({ date: event.detail.value, selectedArtistId: '' })
|
||||
this.loadArtists()
|
||||
},
|
||||
|
||||
onTimeChange(event) {
|
||||
@@ -36,6 +65,10 @@ Page({
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (this.data.loadError) {
|
||||
wx.showToast({ title: '请先重新加载可接员工', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.data.selectedArtistId) {
|
||||
wx.showToast({ title: '请选择美甲师', icon: 'none' })
|
||||
return
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<view class="page no-tab">
|
||||
<view class="list">
|
||||
<view wx:if="{{loadError}}" class="card error-card">
|
||||
<text class="error-title">数据加载失败</text>
|
||||
<text class="error-desc">{{errorMessage}}</text>
|
||||
<button class="compact-btn" bindtap="loadArtists">重试</button>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{!artists.length}}" class="empty">暂无可改派美甲师</view>
|
||||
|
||||
<view wx:else class="list">
|
||||
<view wx:for="{{artists}}" wx:key="id" class="card transfer-card {{selectedArtistId == item.id ? 'active' : ''}}" data-id="{{item.id}}" bindtap="selectArtist">
|
||||
<view class="row between">
|
||||
<view class="row">
|
||||
|
||||
@@ -1,26 +1,62 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const config = require('../../utils/config')
|
||||
const mock = require('../../utils/mock')
|
||||
|
||||
const normalizeEmployee = (item = {}) => ({
|
||||
id: item.userId || item.id,
|
||||
name: item.nickname || item.name || item.artistName || '美甲师',
|
||||
shortName: (item.nickname || item.name || item.artistName || '师').slice(-1),
|
||||
color: item.color || '#7BA7C7',
|
||||
monthOrders: item.monthOrders || item.orderCount || 0,
|
||||
monthAmount: item.monthAmount || item.turnover || 0,
|
||||
avgAmount: item.avgAmount || item.averageAmount || 0
|
||||
})
|
||||
|
||||
Page({
|
||||
data: {
|
||||
id: '',
|
||||
employee: {}
|
||||
employee: {},
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const id = options.id || mock.artists[0].id
|
||||
const artist = mock.artists.find(item => String(item.id) === String(id)) || mock.artists[0]
|
||||
this.setData({
|
||||
id,
|
||||
employee: {
|
||||
...artist,
|
||||
monthOrders: 32,
|
||||
monthAmount: 5800,
|
||||
avgAmount: 181
|
||||
onLoad(options = {}) {
|
||||
const id = options.id || ''
|
||||
this.setData({ id })
|
||||
this.loadEmployee()
|
||||
},
|
||||
|
||||
async loadEmployee() {
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
try {
|
||||
const employee = await employeesApi.detail(this.data.id)
|
||||
this.setData({ employee: normalizeEmployee(employee) })
|
||||
} catch (error) {
|
||||
if (config.USE_DEV_MOCK_DATA) {
|
||||
const artist = mock.artists.find(item => String(item.id) === String(this.data.id)) || mock.artists[0]
|
||||
this.setData({
|
||||
employee: normalizeEmployee({
|
||||
...artist,
|
||||
monthOrders: 32,
|
||||
monthAmount: 5800,
|
||||
avgAmount: 181
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.setData({
|
||||
employee: {},
|
||||
loadError: true,
|
||||
errorMessage: error.message || '员工详情加载失败,请检查服务连接后重试'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
go(event) {
|
||||
if (this.data.loadError) {
|
||||
wx.showToast({ title: '请先重新加载员工详情', icon: 'none' })
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: `${event.currentTarget.dataset.url}?id=${this.data.id}` })
|
||||
},
|
||||
|
||||
|
||||
@@ -1,33 +1,41 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card employee-head">
|
||||
<view class="avatar" style="background: {{employee.color}};">{{employee.shortName}}</view>
|
||||
<view>
|
||||
<text class="employee-name">{{employee.name}}</text>
|
||||
<text class="tag" style="background: {{employee.color}}; color: #fff;">员工色</text>
|
||||
</view>
|
||||
<view wx:if="{{loadError}}" class="card error-card">
|
||||
<text class="error-title">数据加载失败</text>
|
||||
<text class="error-desc">{{errorMessage}}</text>
|
||||
<button class="compact-btn" bindtap="loadEmployee">重试</button>
|
||||
</view>
|
||||
|
||||
<view class="stats">
|
||||
<view class="card stat">
|
||||
<text class="stat-value">{{employee.monthOrders}}</text>
|
||||
<text class="stat-label">本月订单</text>
|
||||
<block wx:else>
|
||||
<view class="card employee-head">
|
||||
<view class="avatar" style="background: {{employee.color}};">{{employee.shortName}}</view>
|
||||
<view>
|
||||
<text class="employee-name">{{employee.name}}</text>
|
||||
<text class="tag" style="background: {{employee.color}}; color: #fff;">员工色</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="card stat">
|
||||
<text class="stat-value">¥{{employee.monthAmount}}</text>
|
||||
<text class="stat-label">本月营业额</text>
|
||||
</view>
|
||||
<view class="card stat">
|
||||
<text class="stat-value">¥{{employee.avgAmount}}</text>
|
||||
<text class="stat-label">平均客单价</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="menu-grid">
|
||||
<view class="card menu-card" data-url="/pages/schedule-setting/index" bindtap="go">排班设置</view>
|
||||
<view class="card menu-card" data-url="/pages/leave-management/index" bindtap="go">请假管理</view>
|
||||
<view class="card menu-card" data-url="/pages/color-setting/index" bindtap="go">颜色设置</view>
|
||||
<view class="card menu-card" data-url="/pages/employee-orders/index" bindtap="go">订单记录</view>
|
||||
<view class="stats">
|
||||
<view class="card stat">
|
||||
<text class="stat-value">{{employee.monthOrders}}</text>
|
||||
<text class="stat-label">本月订单</text>
|
||||
</view>
|
||||
<view class="card stat">
|
||||
<text class="stat-value">¥{{employee.monthAmount}}</text>
|
||||
<text class="stat-label">本月营业额</text>
|
||||
</view>
|
||||
<view class="card stat">
|
||||
<text class="stat-value">¥{{employee.avgAmount}}</text>
|
||||
<text class="stat-label">平均客单价</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="menu-grid">
|
||||
<view class="card menu-card" data-url="/pages/schedule-setting/index" bindtap="go">排班设置</view>
|
||||
<view class="card menu-card" data-url="/pages/leave-management/index" bindtap="go">请假管理</view>
|
||||
<view class="card menu-card" data-url="/pages/color-setting/index" bindtap="go">颜色设置</view>
|
||||
<view class="card menu-card" data-url="/pages/employee-orders/index" bindtap="go">订单记录</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const mock = require('../../utils/mock')
|
||||
|
||||
const EMPLOYEE_COLORS = ['#7BA7C7', '#89A98B', '#A893BC', '#D49A89', '#C9A66B', '#7E9A9A']
|
||||
|
||||
Page({
|
||||
data: {
|
||||
employees: []
|
||||
employees: [],
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -11,11 +14,7 @@ Page({
|
||||
},
|
||||
|
||||
async loadEmployees() {
|
||||
const fallback = mock.artists.map((item, index) => ({
|
||||
...item,
|
||||
monthOrders: 32 - index * 5,
|
||||
monthAmount: 5800 - index * 760
|
||||
}))
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
try {
|
||||
const data = await employeesApi.list({ page: 1, size: 50 })
|
||||
const list = data.list || data || []
|
||||
@@ -24,13 +23,17 @@ Page({
|
||||
id: item.userId || item.id,
|
||||
name: item.nickname || item.name || item.artistName || `美甲师${index + 1}`,
|
||||
shortName: (item.nickname || item.name || '师').slice(-1),
|
||||
color: mock.artists[index % mock.artists.length].color,
|
||||
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: fallback })
|
||||
this.setData({
|
||||
employees: [],
|
||||
loadError: true,
|
||||
errorMessage: error.message || '员工数据加载失败,请检查服务连接后重试'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -4,7 +4,15 @@
|
||||
<button class="compact-btn" bindtap="addEmployee">新增</button>
|
||||
</view>
|
||||
|
||||
<view class="list">
|
||||
<view wx:if="{{loadError}}" class="card error-card">
|
||||
<text class="error-title">数据加载失败</text>
|
||||
<text class="error-desc">{{errorMessage}}</text>
|
||||
<button class="compact-btn" bindtap="loadEmployees">重试</button>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{!employees.length}}" class="empty">暂无员工数据</view>
|
||||
|
||||
<view wx:else class="list">
|
||||
<view wx:for="{{employees}}" wx:key="id" class="card employee-card" data-id="{{item.id}}" bindtap="openDetail">
|
||||
<view class="employee-left">
|
||||
<view class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const dateUtil = require('../../utils/date')
|
||||
const config = require('../../utils/config')
|
||||
const mock = require('../../utils/mock')
|
||||
|
||||
Page({
|
||||
@@ -40,7 +41,9 @@ Page({
|
||||
dayTotal: 0,
|
||||
freeArtistCount: 0,
|
||||
pendingCount: 0,
|
||||
loading: false
|
||||
loading: false,
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -130,9 +133,25 @@ Page({
|
||||
endDate: range.end,
|
||||
artistId: this.data.selectedArtistId || undefined
|
||||
})
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
this.applyCalendar(data)
|
||||
} catch (error) {
|
||||
this.applyCalendar(mock.buildCalendar(this.data.currentDateText))
|
||||
if (config.USE_DEV_MOCK_DATA) {
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
this.applyCalendar(mock.buildCalendar(this.data.currentDateText))
|
||||
} else {
|
||||
this.setData({
|
||||
loadError: true,
|
||||
errorMessage: error.message || '规划数据加载失败,请检查服务连接后重试'
|
||||
})
|
||||
this.applyCalendar({
|
||||
businessStartTime: this.data.businessStartTime,
|
||||
businessEndTime: this.data.businessEndTime,
|
||||
artists: this.data.artists,
|
||||
appointments: [],
|
||||
daySummaries: []
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loadError}}" class="card error-card">
|
||||
<text class="error-title">数据加载失败</text>
|
||||
<text class="error-desc">{{errorMessage}}</text>
|
||||
<button class="compact-btn" bindtap="loadCalendar">重试</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{viewMode === 'day'}}" class="section">
|
||||
<view class="day-summary">
|
||||
<view class="summary-item card">
|
||||
|
||||
@@ -3,5 +3,6 @@ const DEFAULT_DOMAIN = 'http://127.0.0.1:63341'
|
||||
module.exports = {
|
||||
API_DOMAIN: DEFAULT_DOMAIN,
|
||||
ADMIN_API_BASE_URL: `${DEFAULT_DOMAIN}/admin`,
|
||||
REQUEST_TIMEOUT: 10000
|
||||
REQUEST_TIMEOUT: 10000,
|
||||
USE_DEV_MOCK_DATA: false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user