feat(admin): 新增陪诊员入驻申请与全局角色守卫

- 新增 pages/apply 入驻申请页:填写资料、上传证件、查看审核状态
- 新增 utils/role.js 统一角色解析与管理端页面守卫
- app.js 包装 Page 构造器集中做 onShow 守卫,无身份用户重定向至申请页
- 订单、客户、档案、统计等按角色区分能力:陪诊员不请求档案接口,改用订单快照
- 订单列表支持待取消订单一键同意取消;新增订单价格由服务目录决定只读展示
This commit is contained in:
lik
2026-11-08 12:01:48 +08:00
parent bfe820aa31
commit c8bcc79865
27 changed files with 1332 additions and 206 deletions
+46 -20
View File
@@ -1,6 +1,7 @@
// pages/order/orderEdit.js
const API = require('../../utils/api.js')
const { calcAge } = require('../../utils/format.js')
const role = require('../../utils/role.js')
// 支付方式选项:与 schema 的 payment.method 枚举一一对应,空串表示未记录
const METHOD_OPTIONS = [
@@ -17,6 +18,8 @@ Page({
*/
data: {
isEdit: false,
// 角色:代客下单仅管理员可用
isAdmin: false,
form: {
hospital: { province: '', name: '', department: '', doctor: '' },
schedule: { date: '', startTime: '08:30' },
@@ -44,6 +47,10 @@ Page({
amountLocked: false,
// 已收款/退款中的订单锁定支付信息,避免把退款状态改回未支付后被重复收款
paymentLocked: false,
// 新增模式下服务价格只读展示(后端按服务目录取价)
servicePrice: '',
// 所选档案未关联客户:订单归属留空,可后期补录
profileOwnerMissing: false,
today: '',
submitting: false
},
@@ -59,7 +66,17 @@ Page({
this.setData({ today })
this.loadServices()
if (options && options.orderId) {
role.ensureRole().then(r => {
this.setData({ isAdmin: r === 'admin' })
this.enterPage(options || {})
})
},
/**
* 角色就绪后进入页面:新增仅管理员可用
*/
enterPage(options) {
if (options.orderId) {
// 编辑模式
this.orderId = options.orderId
this.setData({ isEdit: true })
@@ -68,8 +85,17 @@ Page({
return
}
if (!this.data.isAdmin) {
wx.showToast({ title: '仅管理员可新增预约', icon: 'none' })
setTimeout(() => wx.navigateBack(), 600)
return
}
// 幂等键:进入新增页生成一次,连点或弱网重试不会重复建单
this.idempotencyKey = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
wx.setNavigationBarTitle({ title: '新增预约' })
if (!options || !options.id) {
if (!options.id) {
// 未携带档案ID:弹出档案选择
this.setData({ needPickProfile: true })
this.openProfilePicker()
@@ -273,7 +299,9 @@ Page({
height: h.height || '',
weight: h.weight || '',
remark: h.remark || ''
}
},
// 档案未关联客户:订单归属留空,提示管理员后期补录
profileOwnerMissing: !this.data.isEdit && !profile.userId
})
},
@@ -363,7 +391,9 @@ Page({
if (!svc) return
this.setData({
'form.escort.serviceId': svc.id,
'form.escort.serviceName': svc.title
'form.escort.serviceName': svc.title,
// 新增订单价格以后端服务目录为准,这里只做只读展示
servicePrice: Number(svc.price) || 0
}, () => this.syncProvinces())
},
@@ -407,23 +437,21 @@ Page({
if (form.escort.serviceId === -1) return wx.showToast({ title: '请选择服务', icon: 'none' })
if (!form.schedule.date) return wx.showToast({ title: '请选择就诊日期', icon: 'none' })
const app = getApp()
const userId = app.globalData.user?._id
if (!userId) return wx.showToast({ title: '未获取到用户信息,请重新登录', icon: 'none' })
if (this.data.isEdit) {
this.updateOrder(form)
} else {
this.createOrder(form, userId)
this.createOrder(form)
}
},
/**
* 新增订单
* 归属、价格与支付状态均由后端派生:订单归属取档案 userId(无归属留空),
* 价格取服务目录,初始为未支付,因此这里不再提交 userId / payment
*/
createOrder(form, userId) {
createOrder(form) {
const payload = {
userId,
idempotencyKey: this.idempotencyKey,
healthProfileId: this.profileId || null,
patient: this.patientInfo,
hospital: {
@@ -434,19 +462,12 @@ Page({
},
schedule: {
date: form.schedule.date,
startTime: form.schedule.startTime || '',
duration: 60
startTime: form.schedule.startTime || ''
},
escort: {
serviceId: form.escort.serviceId || -1,
serviceName: form.escort.serviceName
},
payment: {
totalFee: form.payment.totalFee ? Number(form.payment.totalFee) : 0,
method: form.payment.method || '',
paidFee: 0,
status: 'unpaid'
},
notes: {
patientNote: form.notes.patientNote
},
@@ -467,8 +488,13 @@ Page({
return wx.showToast({ title: res.msg || '创建失败', icon: 'none' })
}
wx.showToast({ title: '创建成功', icon: 'success' })
const recordId = res.data && res.data.record ? res.data.record._id : ''
setTimeout(() => {
wx.navigateBack()
if (recordId) {
wx.redirectTo({ url: `/pages/order/orderDetail?id=${recordId}` })
} else {
wx.navigateBack()
}
}, 600)
})
.catch(err => {