Compare commits
1
Commits
5ae8a62475
...
5fdcf8ea4c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fdcf8ea4c |
+32
-7
@@ -1,5 +1,6 @@
|
|||||||
// pages/home/index.js
|
// pages/home/index.js
|
||||||
const role = require('../../utils/role.js')
|
const role = require('../../utils/role.js')
|
||||||
|
const API = require('../../utils/api.js')
|
||||||
|
|
||||||
// 取消与 status 解耦:展示状态优先取 cancelStatus
|
// 取消与 status 解耦:展示状态优先取 cancelStatus
|
||||||
function resolveDisplayStatus(order) {
|
function resolveDisplayStatus(order) {
|
||||||
@@ -38,7 +39,9 @@ Page({
|
|||||||
isIntern: false,
|
isIntern: false,
|
||||||
levelText: '',
|
levelText: '',
|
||||||
quickEntries: [],
|
quickEntries: [],
|
||||||
online: true,
|
online: false,
|
||||||
|
showOnlineSwitch: false,
|
||||||
|
onlineSaving: false,
|
||||||
profile: {
|
profile: {
|
||||||
name: '',
|
name: '',
|
||||||
avatar: ''
|
avatar: ''
|
||||||
@@ -89,13 +92,18 @@ Page({
|
|||||||
.then((detail) => {
|
.then((detail) => {
|
||||||
const r = detail.role
|
const r = detail.role
|
||||||
const attendant = detail.attendant || null
|
const attendant = detail.attendant || null
|
||||||
|
// 接单开关只对正式陪诊师展示:管理员无接单身份,实习陪诊师不可接单
|
||||||
|
const isIntern = !!(attendant && attendant.stage === 'intern')
|
||||||
|
const showOnlineSwitch = r === 'attendant' && !isIntern
|
||||||
this.setData({
|
this.setData({
|
||||||
role: r,
|
role: r,
|
||||||
isAdmin: r === 'admin',
|
isAdmin: r === 'admin',
|
||||||
// 实习陪诊师可进工作台查看,但不能接单:首页给一条只读提示
|
// 实习陪诊师可进工作台查看,但不能接单:首页给一条只读提示
|
||||||
isIntern: !!(attendant && attendant.stage === 'intern'),
|
isIntern,
|
||||||
levelText: r === 'admin' ? '管理员' : (attendant ? attendant.text : ''),
|
levelText: r === 'admin' ? '管理员' : (attendant ? attendant.text : ''),
|
||||||
quickEntries: r === 'admin' ? ADMIN_ENTRIES : (r === 'attendant' ? ATTENDANT_ENTRIES : [])
|
quickEntries: r === 'admin' ? ADMIN_ENTRIES : (r === 'attendant' ? ATTENDANT_ENTRIES : []),
|
||||||
|
showOnlineSwitch,
|
||||||
|
online: showOnlineSwitch && attendant ? attendant.isOnline === true : false
|
||||||
})
|
})
|
||||||
this.loadUser()
|
this.loadUser()
|
||||||
this.getRecentOrders()
|
this.getRecentOrders()
|
||||||
@@ -118,10 +126,27 @@ Page({
|
|||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleOnline() {
|
async toggleOnline() {
|
||||||
this.setData({
|
if (!this.data.showOnlineSwitch || this.data.onlineSaving) return
|
||||||
online: !this.data.online
|
const next = !this.data.online
|
||||||
})
|
// 先乐观更新,请求失败再回滚
|
||||||
|
this.setData({ online: next, onlineSaving: true })
|
||||||
|
try {
|
||||||
|
const res = await API.employee.setOnline(next)
|
||||||
|
if (!res || res.code !== 0) {
|
||||||
|
throw new Error((res && res.msg) || '切换失败,请重试')
|
||||||
|
}
|
||||||
|
const info = res.data && res.data.employee ? res.data.employee.attendantInfo : null
|
||||||
|
const actual = info && typeof info.isOnline === 'boolean' ? info.isOnline : next
|
||||||
|
this.setData({ online: actual })
|
||||||
|
role.setAttendantOnline(actual)
|
||||||
|
wx.showToast({ title: actual ? '已开启接单' : '已暂停接单', icon: 'none' })
|
||||||
|
} catch (e) {
|
||||||
|
this.setData({ online: !next })
|
||||||
|
wx.showToast({ title: (e && e.message) || '切换失败,请重试', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ onlineSaving: false })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getStats() {
|
async getStats() {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<text class="greeting">{{greeting}},{{todayText}}</text>
|
<text class="greeting">{{greeting}},{{todayText}}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="online-switch" bindtap="toggleOnline">
|
<view class="online-switch" wx:if="{{showOnlineSwitch}}" bindtap="toggleOnline">
|
||||||
<text class="switch-text">{{online ? '接单中' : '休息中'}}</text>
|
<text class="switch-text">{{online ? '接单中' : '休息中'}}</text>
|
||||||
<view class="switch-track {{online ? 'on' : 'off'}}">
|
<view class="switch-track {{online ? 'on' : 'off'}}">
|
||||||
<view class="switch-thumb"></view>
|
<view class="switch-thumb"></view>
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ const API = {
|
|||||||
// 当前账号的员工档案:登录即可访问,用于判定在职陪诊员身份
|
// 当前账号的员工档案:登录即可访问,用于判定在职陪诊员身份
|
||||||
employee: {
|
employee: {
|
||||||
getMe: () => request.get('/health/employee/me'),
|
getMe: () => request.get('/health/employee/me'),
|
||||||
|
// 首页接单开关:仅在职正式陪诊师可切换
|
||||||
|
setOnline: (isOnline) => request.patch('/health/employee/me/online', { isOnline }),
|
||||||
// 共享订单时的陪诊师候选(在职陪诊师,含实习)
|
// 共享订单时的陪诊师候选(在职陪诊师,含实习)
|
||||||
getShareableAttendants: () => request.get('/health/employee/shareable-attendants'),
|
getShareableAttendants: () => request.get('/health/employee/shareable-attendants'),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ function normalizeAttendant(employee) {
|
|||||||
grade,
|
grade,
|
||||||
star,
|
star,
|
||||||
canAcceptOrder: stage === 'certified',
|
canAcceptOrder: stage === 'certified',
|
||||||
|
isOnline: info.isOnline === true,
|
||||||
text: stage === 'intern' ? '实习陪诊师' : `正式陪诊师 · ${gradeText}`
|
text: stage === 'intern' ? '实习陪诊师' : `正式陪诊师 · ${gradeText}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,6 +190,11 @@ function getAttendantSync() {
|
|||||||
return cachedAttendant
|
return cachedAttendant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 接单开关切换成功后同步快照,避免 onShow 复用旧值把开关弹回去
|
||||||
|
function setAttendantOnline(isOnline) {
|
||||||
|
if (cachedAttendant) cachedAttendant.isOnline = !!isOnline
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录 / 清除缓存后重置,避免沿用上一个账号的角色
|
* 退出登录 / 清除缓存后重置,避免沿用上一个账号的角色
|
||||||
*/
|
*/
|
||||||
@@ -242,6 +248,7 @@ module.exports = {
|
|||||||
ensureRoleSafe,
|
ensureRoleSafe,
|
||||||
getRoleSync,
|
getRoleSync,
|
||||||
getAttendantSync,
|
getAttendantSync,
|
||||||
|
setAttendantOnline,
|
||||||
resetRole,
|
resetRole,
|
||||||
queryOrders,
|
queryOrders,
|
||||||
guardAdminPage
|
guardAdminPage
|
||||||
|
|||||||
Reference in New Issue
Block a user