diff --git a/src/api/escort.ts b/src/api/escort.ts index 99286d0..c823325 100644 --- a/src/api/escort.ts +++ b/src/api/escort.ts @@ -30,6 +30,12 @@ export const escortApi = { body, }), + assign: (id: string, employeeId: string) => + request<{ record: EscortRecord }>(`/health/escort-record/${id}/assign`, { + method: 'POST', + body: { employeeId }, + }), + updateStatus: (id: string, status: string, reason?: string) => request<{ record: EscortRecord; deleted?: boolean }>(`/health/escort-record/${id}/status`, { method: 'PATCH', diff --git a/src/views/attendants/index.vue b/src/views/attendants/index.vue index 82cf7b9..1d439e5 100644 --- a/src/views/attendants/index.vue +++ b/src/views/attendants/index.vue @@ -124,6 +124,7 @@
取消 - - {{ assignSubmitting ? '提交中...' : '确认指派' }} + + {{ assignSubmitting ? '提交中...' : '确认分配' }}
@@ -509,9 +513,10 @@ const canRecordOffline = computed(() => { && ['pending', 'confirmed'].includes(record.value.status || '') }) -// 指派陪诊师:仅未进入取消流程且服务未结束时允许 +// 分配陪诊师:仅未分配且未进入取消流程的进行中订单允许 const canAssignAttendant = computed(() => { if (!record.value) return false + if (record.value.attendant?.id || record.value.attendant?.name) return false return (record.value.cancelStatus || 'none') === 'none' && ['pending', 'confirmed', 'in_progress'].includes(record.value.status || '') }) @@ -523,16 +528,26 @@ const attendants = ref([]) const assignTarget = ref(null) const openAssign = async () => { - const currentId = record.value?.attendant?.id - assignTarget.value = currentId - ? attendants.value.find((emp) => emp.userId && String(emp.userId) === String(currentId)) || null - : null + assignTarget.value = null assignVisible.value = true if (!attendants.value.length) { assignLoading.value = true try { - const data = await employeeApi.list({ page: 1, pageSize: 100, role: 'attendant', status: 'active' }) - attendants.value = data.employees + // 分页拉全量在职陪诊师:单页有上限,只拉一页会静默漏人 + const fetched: Employee[] = [] + let page = 1 + let total = Number.POSITIVE_INFINITY + while (fetched.length < total && page <= 20) { + const data = await employeeApi.list({ page, pageSize: 100, role: 'attendant', status: 'active' }) + total = data.total + fetched.push(...data.employees) + if (!data.employees.length) break + page += 1 + } + // 实习陪诊师不可被指派,后端同样会拦截 + attendants.value = fetched.filter( + (emp) => (emp.attendantInfo?.stage || 'certified') !== 'intern' + ) } catch { // 错误提示由请求层统一弹出 } finally { @@ -543,20 +558,10 @@ const openAssign = async () => { const submitAssign = async () => { if (!record.value || !assignTarget.value) return - const emp = assignTarget.value - // 后端 attendant.sex 枚举仅 none/male/female,员工档案里的 other 需归一到 none - const rawSex = emp.profile?.sex - const attendant = { - name: emp.profile?.name || '', - sex: rawSex === 'male' || rawSex === 'female' ? rawSex : 'none', - mobile: emp.profile?.phone || '', - ...(emp.userId ? { id: emp.userId } : {}), - } assignSubmitting.value = true try { - // 后端 attendant 子文档结构:{ id: 关联登录用户ID, name, sex, mobile } - await escortApi.update(record.value._id, { attendant }) - notify.success('陪诊师已指派') + await escortApi.assign(record.value._id, assignTarget.value._id) + notify.success('陪诊师已分配') assignVisible.value = false await load() } catch {