feat: 首页接单开关接入服务端落库
This commit is contained in:
+32
-7
@@ -1,5 +1,6 @@
|
||||
// pages/home/index.js
|
||||
const role = require('../../utils/role.js')
|
||||
const API = require('../../utils/api.js')
|
||||
|
||||
// 取消与 status 解耦:展示状态优先取 cancelStatus
|
||||
function resolveDisplayStatus(order) {
|
||||
@@ -38,7 +39,9 @@ Page({
|
||||
isIntern: false,
|
||||
levelText: '',
|
||||
quickEntries: [],
|
||||
online: true,
|
||||
online: false,
|
||||
showOnlineSwitch: false,
|
||||
onlineSaving: false,
|
||||
profile: {
|
||||
name: '',
|
||||
avatar: ''
|
||||
@@ -89,13 +92,18 @@ Page({
|
||||
.then((detail) => {
|
||||
const r = detail.role
|
||||
const attendant = detail.attendant || null
|
||||
// 接单开关只对正式陪诊师展示:管理员无接单身份,实习陪诊师不可接单
|
||||
const isIntern = !!(attendant && attendant.stage === 'intern')
|
||||
const showOnlineSwitch = r === 'attendant' && !isIntern
|
||||
this.setData({
|
||||
role: r,
|
||||
isAdmin: r === 'admin',
|
||||
// 实习陪诊师可进工作台查看,但不能接单:首页给一条只读提示
|
||||
isIntern: !!(attendant && attendant.stage === 'intern'),
|
||||
isIntern,
|
||||
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.getRecentOrders()
|
||||
@@ -118,10 +126,27 @@ Page({
|
||||
.catch(() => {})
|
||||
},
|
||||
|
||||
toggleOnline() {
|
||||
this.setData({
|
||||
online: !this.data.online
|
||||
})
|
||||
async toggleOnline() {
|
||||
if (!this.data.showOnlineSwitch || this.data.onlineSaving) return
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user