更新
This commit is contained in:
+109
-3
@@ -376,6 +376,8 @@ export function getMsgAuditPermitUsers() {
|
||||
export interface PrescriptionEsignConfig {
|
||||
enabled: boolean
|
||||
environment: 'sandbox' | 'production'
|
||||
verification_method?: 'sms' | 'quick'
|
||||
review_enabled?: boolean
|
||||
}
|
||||
|
||||
export interface PrescriptionEsignStatus extends PrescriptionEsignConfig {
|
||||
@@ -384,7 +386,19 @@ export interface PrescriptionEsignStatus extends PrescriptionEsignConfig {
|
||||
status_label: string
|
||||
can_sign: boolean
|
||||
can_download: boolean
|
||||
can_resume_identity?: boolean
|
||||
doctor_identity_required?: boolean
|
||||
signing_authorization_required?: boolean
|
||||
signing_authorization_reason?: 'missing' | 'expired' | 'exhausted' | 'invalid'
|
||||
sms_sent?: boolean
|
||||
can_retry_verify?: boolean
|
||||
message: string
|
||||
issued_at?: number
|
||||
signature_time?: number
|
||||
signature_time_source?: 'tsa' | 'local' | ''
|
||||
review_signer_name?: string
|
||||
review_signature_time?: number
|
||||
signed_at?: number
|
||||
auth_url?: string
|
||||
}
|
||||
|
||||
@@ -394,6 +408,57 @@ export interface PrescriptionEsignFile {
|
||||
sha256: string
|
||||
}
|
||||
|
||||
export interface PrescriptionEsignReviewStatus {
|
||||
required: boolean
|
||||
state: 'pending' | 'signing' | 'verifying' | 'signed' | 'failed' | 'uncertain'
|
||||
can_confirm: boolean
|
||||
can_retry_verify: boolean
|
||||
can_approve: boolean
|
||||
can_setup: boolean
|
||||
actor_id: number
|
||||
actor_name: string
|
||||
signer_name: string
|
||||
signature_time: number
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface PrescriptionEsignReviewTarget {
|
||||
id: number
|
||||
order_id?: number
|
||||
}
|
||||
|
||||
export function prescriptionEsignReviewStatus(params: PrescriptionEsignReviewTarget, signal?: AbortSignal): Promise<PrescriptionEsignReviewStatus> {
|
||||
return request.get({ url: '/tcm.prescription/esignReviewStatus', params, signal },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true })
|
||||
}
|
||||
|
||||
export function prescriptionEsignReviewConfirm(
|
||||
params: PrescriptionEsignReviewTarget & { actor_id: number; verify_only: boolean }
|
||||
): Promise<PrescriptionEsignReviewStatus> {
|
||||
return request.post({ url: '/tcm.prescription/esignReviewConfirm', params, timeout: 360000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true })
|
||||
}
|
||||
|
||||
export interface PrescriptionEsignIdentityStatus extends PrescriptionEsignStatus {
|
||||
identity_status: 'INIT' | 'ING' | 'SUCCESS' | 'FAIL' | 'EXPIRED' | 'UNAVAILABLE'
|
||||
can_complete: boolean
|
||||
identity_details_required?: boolean
|
||||
}
|
||||
|
||||
export interface PrescriptionEsignDoctorStatus {
|
||||
enabled: boolean
|
||||
status: 'unbound' | 'needs_mobile' | 'renewal_required' | 'authenticating' | 'binding_required' | 'ready'
|
||||
cert_expires_at: number
|
||||
identity_details_required?: boolean
|
||||
quicksign_enabled?: boolean
|
||||
quicksign_authorizing?: boolean
|
||||
quicksign_expires_at?: number
|
||||
quicksign_remaining_times?: number
|
||||
quicksign_unavailable_reason?: '' | 'missing' | 'expired' | 'exhausted' | 'invalid'
|
||||
auth_url?: string
|
||||
message?: string
|
||||
}
|
||||
|
||||
export function prescriptionEsignConfig(): Promise<PrescriptionEsignConfig> {
|
||||
return request.get({ url: '/tcm.prescription/esignConfig' })
|
||||
}
|
||||
@@ -402,16 +467,57 @@ export function prescriptionEsignStatus(params: { id: number }): Promise<Prescri
|
||||
return request.get({ url: '/tcm.prescription/esignStatus', params })
|
||||
}
|
||||
|
||||
export function prescriptionEsignStart(params: { id: number }): Promise<PrescriptionEsignStatus> {
|
||||
/** Read-only identity readiness; this endpoint never submits a signature. */
|
||||
export function prescriptionEsignIdentityStatus(params: { id: number }, signal?: AbortSignal): Promise<PrescriptionEsignIdentityStatus> {
|
||||
return request.get(
|
||||
{ url: '/tcm.prescription/esignIdentityStatus', params, signal, timeout: 15000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true }
|
||||
)
|
||||
}
|
||||
|
||||
export function prescriptionEsignStart(params: { id: number; restart_identity?: true }): Promise<PrescriptionEsignStatus> {
|
||||
return request.post(
|
||||
{ url: '/tcm.prescription/esignStart', params, timeout: 180000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true }
|
||||
)
|
||||
}
|
||||
|
||||
export function prescriptionEsignComplete(params: { id: number }): Promise<PrescriptionEsignStatus> {
|
||||
export function prescriptionEsignVerifyWillingness(params: { id: number; auth_code: string }): Promise<PrescriptionEsignIdentityStatus> {
|
||||
return request.post(
|
||||
{ url: '/tcm.prescription/esignComplete', params, timeout: 180000 },
|
||||
{ url: '/tcm.prescription/esignVerifyWillingness', params, timeout: 60000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true }
|
||||
)
|
||||
}
|
||||
|
||||
export function prescriptionEsignDoctorStatus(signal?: AbortSignal): Promise<PrescriptionEsignDoctorStatus> {
|
||||
return request.get(
|
||||
{ url: '/tcm.prescription/esignDoctorStatus', signal, timeout: 15000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true }
|
||||
)
|
||||
}
|
||||
|
||||
export function prescriptionEsignDoctorStart(params: { mobile?: string }): Promise<PrescriptionEsignDoctorStatus> {
|
||||
return request.post(
|
||||
{ url: '/tcm.prescription/esignDoctorStart', params, timeout: 180000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true }
|
||||
)
|
||||
}
|
||||
|
||||
export function prescriptionEsignDoctorComplete(params: { identity_number?: string }): Promise<PrescriptionEsignDoctorStatus> {
|
||||
return request.post(
|
||||
{ url: '/tcm.prescription/esignDoctorComplete', params, timeout: 180000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true }
|
||||
)
|
||||
}
|
||||
|
||||
export function prescriptionEsignComplete(params: { id: number } & (
|
||||
{ verify_only: true; identity_number?: never } | { verify_only?: never; identity_number?: string }
|
||||
)): Promise<PrescriptionEsignStatus> {
|
||||
const payload = { id: params.id }
|
||||
if (params.verify_only) Object.assign(payload, { verify_only: true })
|
||||
else if (params.identity_number !== undefined) Object.assign(payload, { identity_number: params.identity_number })
|
||||
return request.post(
|
||||
{ url: '/tcm.prescription/esignComplete', params: payload, timeout: 180000 },
|
||||
{ isOpenRetry: false, retryCount: 0, ignoreCancelToken: true }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,406 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="true"
|
||||
:title="reviewer ? '审核签署身份' : '医生电子签署身份'"
|
||||
:width="frameUrl ? 'min(760px, 94vw)' : 'min(520px, 94vw)'"
|
||||
top="5vh"
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
:before-close="dismiss"
|
||||
>
|
||||
<p class="doctor-esign__message" role="status">{{ guidance }}</p>
|
||||
<dl v-if="state?.enabled && state.status === 'ready'" class="doctor-esign__expiry">
|
||||
<template v-if="state.cert_expires_at">
|
||||
<dt>签署证书有效期至</dt>
|
||||
<dd>{{ formatExpiry(state.cert_expires_at) }}</dd>
|
||||
</template>
|
||||
<template v-if="grantActive">
|
||||
<dt>快捷签授权有效期至</dt>
|
||||
<dd>{{ formatExpiry(state.quicksign_expires_at) }}</dd>
|
||||
<dt>快捷签剩余次数</dt>
|
||||
<dd>{{ state.quicksign_remaining_times }}</dd>
|
||||
</template>
|
||||
</dl>
|
||||
<p v-if="error" class="doctor-esign__error" role="alert">{{ error }}</p>
|
||||
<label v-if="needsMobile" class="doctor-esign__field">
|
||||
本人手机号码
|
||||
<el-input
|
||||
v-model="mobile"
|
||||
:disabled="!!pending"
|
||||
type="tel"
|
||||
inputmode="numeric"
|
||||
maxlength="11"
|
||||
autocomplete="off"
|
||||
placeholder="请输入 11 位大陆手机号码"
|
||||
/>
|
||||
</label>
|
||||
<label v-if="needsIdentityNumber" class="doctor-esign__field">
|
||||
本次认证使用的身份证号码
|
||||
<el-input
|
||||
v-model="identityNumber"
|
||||
:disabled="!!pending"
|
||||
type="password"
|
||||
maxlength="18"
|
||||
autocomplete="off"
|
||||
:spellcheck="false"
|
||||
placeholder="请输入 15 或 18 位大陆居民身份证号码"
|
||||
/>
|
||||
</label>
|
||||
<iframe
|
||||
v-if="frameUrl"
|
||||
:src="frameUrl"
|
||||
class="doctor-esign__frame"
|
||||
title="e签宝本人身份核验"
|
||||
sandbox="allow-forms allow-scripts allow-same-origin"
|
||||
referrerpolicy="no-referrer"
|
||||
@error="authenticationUnavailable"
|
||||
/>
|
||||
<template #footer>
|
||||
<div class="doctor-esign__actions">
|
||||
<el-button v-if="needsMobile || canAuthorizeQuick" type="primary" :disabled="!!pending" @click="start">
|
||||
{{ startLabel }}
|
||||
</el-button>
|
||||
<el-button v-if="canResume" type="primary" :disabled="!!pending" @click="openAuthentication">
|
||||
{{ state?.quicksign_authorizing ? '继续快捷签授权' : '继续人脸认证' }}
|
||||
</el-button>
|
||||
<el-button v-if="canComplete" type="primary" :disabled="!!pending" @click="complete">
|
||||
{{ state?.quicksign_authorizing ? '确认快捷签授权' : '确认绑定签署身份' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="canResume && !state?.quicksign_authorizing"
|
||||
:disabled="!!pending"
|
||||
@click="enterMobile"
|
||||
>重新输入手机号</el-button>
|
||||
<el-button :disabled="!!pending" @click="refresh">检查状态</el-button>
|
||||
<el-button v-if="frameUrl" link @click="authenticationUnavailable">验证页面不可用</el-button>
|
||||
<el-button @click="dismiss">关闭</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
|
||||
import {
|
||||
prescriptionEsignDoctorComplete,
|
||||
prescriptionEsignDoctorStart,
|
||||
prescriptionEsignDoctorStatus,
|
||||
type PrescriptionEsignDoctorStatus
|
||||
} from '@/api/tcm'
|
||||
import { safeEsignAuthUrl } from '@/utils/prescription-esign'
|
||||
|
||||
const props = defineProps<{ serverTimeOffsetMs: number; reviewer?: boolean }>()
|
||||
const emit = defineEmits<{ (event: 'close'): void }>()
|
||||
type DoctorRequest = 'status' | 'start' | 'complete'
|
||||
|
||||
const enrollmentStatuses = ['unbound', 'needs_mobile', 'renewal_required']
|
||||
const statuses = [...enrollmentStatuses, 'authenticating', 'binding_required', 'ready']
|
||||
const pollInterval = 5000
|
||||
const authenticationTimeout = 10 * 60 * 1000
|
||||
const expiryFormatter = new Intl.DateTimeFormat('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hourCycle: 'h23'
|
||||
})
|
||||
|
||||
const state = ref<ReturnType<typeof validateStatus> | null>(null)
|
||||
const pending = ref<DoctorRequest | null>(null)
|
||||
const frameUrl = ref('')
|
||||
const mobile = ref('')
|
||||
const identityNumber = ref('')
|
||||
const editingMobile = ref(false)
|
||||
const error = ref('')
|
||||
const now = ref(Date.now() + props.serverTimeOffsetMs)
|
||||
|
||||
const authUrl = computed(() => state.value?.auth_url ?? '')
|
||||
const authenticating = computed(() => state.value?.enabled === true && state.value.status === 'authenticating')
|
||||
const canResume = computed(() => authenticating.value && !!authUrl.value && !frameUrl.value && !editingMobile.value)
|
||||
const canComplete = computed(() => state.value?.enabled === true && state.value.status === 'binding_required')
|
||||
const needsIdentityNumber = computed(() => canComplete.value && !state.value?.quicksign_authorizing
|
||||
&& state.value?.identity_details_required === true)
|
||||
const needsMobile = computed(() => state.value?.enabled === true
|
||||
&& (enrollmentStatuses.includes(state.value.status) || editingMobile.value))
|
||||
const quickReady = computed(() => state.value?.enabled === true && state.value.status === 'ready'
|
||||
&& state.value.quicksign_enabled === true)
|
||||
const grantActive = computed(() => quickReady.value && !!state.value && !state.value.quicksign_unavailable_reason
|
||||
&& (state.value.quicksign_remaining_times ?? 0) > 0 && state.value.quicksign_expires_at * 1000 > now.value)
|
||||
const canAuthorizeQuick = computed(() => quickReady.value && !grantActive.value)
|
||||
const startLabel = computed(() => {
|
||||
if (canAuthorizeQuick.value) return '授权快捷签'
|
||||
if (state.value?.status === 'renewal_required') return '开始续期认证'
|
||||
return '开始人脸认证'
|
||||
})
|
||||
const guidance = computed(() => {
|
||||
const current = state.value
|
||||
if (!current) return pending.value === 'status' ? '正在查询医生签署身份…' : ''
|
||||
if (!current.enabled) return '当前环境未启用医生电子签署身份。'
|
||||
switch (current.status) {
|
||||
case 'unbound':
|
||||
return '首次电子签署前,请验证本人身份并绑定签署证书。'
|
||||
case 'needs_mobile':
|
||||
return '请使用本人手机号码完成签署身份验证。'
|
||||
case 'renewal_required':
|
||||
return '签署证书需要续期,请使用本人手机号码完成人脸认证。'
|
||||
case 'authenticating':
|
||||
if (editingMobile.value) return '请使用本人手机号码完成人脸认证。'
|
||||
if (current.authUrlUnavailable) return '验证链接不可用,请检查状态后重试。'
|
||||
if (!authUrl.value) return '认证请求处理中,请稍后检查状态。'
|
||||
if (!frameUrl.value) return current.quicksign_authorizing ? '请继续完成快捷签授权。' : '请继续完成本人人脸认证。'
|
||||
return current.quicksign_authorizing
|
||||
? '请使用手机支付宝扫码刷脸,并按 e签宝页面提示确认授权。'
|
||||
: '请使用手机支付宝扫描 e签宝页面中的二维码并完成人脸识别。'
|
||||
case 'binding_required':
|
||||
if (current.quicksign_authorizing) return '人脸认证已通过,请确认启用本人的快捷签。'
|
||||
if (needsIdentityNumber.value) return '人脸认证已通过。首次绑定证书需要补充与本次认证一致的身份证号码。'
|
||||
return '人脸认证已通过,请确认完成本人的签署身份认证。'
|
||||
case 'ready': {
|
||||
if (!quickReady.value) return '医生签署身份已就绪。'
|
||||
if (grantActive.value) return props.reviewer ? '快捷签授权有效。每张处方由审核人本人确认签名。'
|
||||
: '快捷签授权有效。每张处方仍需开方医生本人确认签名。'
|
||||
const reason = current.quicksign_unavailable_reason
|
||||
if (reason === 'expired' || (current.quicksign_expires_at > 0 && current.quicksign_expires_at * 1000 <= now.value)) {
|
||||
return '快捷签授权已过期,请重新授权。'
|
||||
}
|
||||
if (reason === 'exhausted') return '快捷签授权次数已用完,请重新授权。'
|
||||
if (reason === 'invalid') return '快捷签授权已失效,请重新授权。'
|
||||
return '签署身份已就绪。请授权使用本人的快捷签,每张处方仍需本人确认签名。'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let closed = false
|
||||
let generation = 0
|
||||
let statusRequest: AbortController | undefined
|
||||
let pollTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let deadlineTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let grantExpiryTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
function formatExpiry(timestamp: number) {
|
||||
return `${expiryFormatter.format(timestamp * 1000)}(北京时间)`
|
||||
}
|
||||
|
||||
function validTime(value: number) {
|
||||
return Number.isSafeInteger(value) && value >= 0 && value <= 253402300799
|
||||
}
|
||||
|
||||
function validateStatus(result: PrescriptionEsignDoctorStatus) {
|
||||
const {
|
||||
enabled, status, cert_expires_at,
|
||||
identity_details_required = false, quicksign_enabled = false, quicksign_authorizing = false,
|
||||
quicksign_expires_at = 0, quicksign_remaining_times = 0, quicksign_unavailable_reason = ''
|
||||
} = result
|
||||
if (!statuses.includes(status) || typeof enabled !== 'boolean'
|
||||
|| typeof quicksign_enabled !== 'boolean' || typeof quicksign_authorizing !== 'boolean'
|
||||
|| !validTime(cert_expires_at) || !validTime(quicksign_expires_at)
|
||||
|| typeof identity_details_required !== 'boolean'
|
||||
|| (identity_details_required && (!enabled || status !== 'binding_required' || quicksign_authorizing))
|
||||
|| (quicksign_authorizing && (!enabled || !quicksign_enabled || !['authenticating', 'binding_required'].includes(status)))
|
||||
|| !Number.isSafeInteger(quicksign_remaining_times) || quicksign_remaining_times < 0
|
||||
|| !['', 'missing', 'expired', 'exhausted', 'invalid'].includes(quicksign_unavailable_reason)) {
|
||||
throw new Error('医生签署状态无效')
|
||||
}
|
||||
const providerUrl = enabled && status === 'authenticating' ? result.auth_url : undefined
|
||||
const auth_url = safeEsignAuthUrl(providerUrl)
|
||||
return {
|
||||
enabled, status, cert_expires_at, identity_details_required, quicksign_enabled, quicksign_authorizing,
|
||||
quicksign_expires_at, quicksign_remaining_times, quicksign_unavailable_reason, auth_url,
|
||||
authUrlUnavailable: Boolean(providerUrl && !auth_url)
|
||||
}
|
||||
}
|
||||
|
||||
function clearInputs() {
|
||||
mobile.value = ''
|
||||
identityNumber.value = ''
|
||||
}
|
||||
|
||||
function stopAuthentication() {
|
||||
clearTimeout(pollTimer)
|
||||
clearTimeout(deadlineTimer)
|
||||
frameUrl.value = ''
|
||||
}
|
||||
|
||||
function cancelWork() {
|
||||
generation++
|
||||
statusRequest?.abort()
|
||||
statusRequest = undefined
|
||||
pending.value = null
|
||||
clearInputs()
|
||||
stopAuthentication()
|
||||
}
|
||||
|
||||
function clearStatus() {
|
||||
cancelWork()
|
||||
clearTimeout(grantExpiryTimer)
|
||||
state.value = null
|
||||
editingMobile.value = false
|
||||
error.value = ''
|
||||
}
|
||||
|
||||
function dismiss() {
|
||||
closed = true
|
||||
clearStatus()
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function canAct() {
|
||||
return !closed && document.visibilityState === 'visible'
|
||||
}
|
||||
|
||||
function accept(result: ReturnType<typeof validateStatus>) {
|
||||
clearTimeout(grantExpiryTimer)
|
||||
now.value = Date.now() + props.serverTimeOffsetMs
|
||||
editingMobile.value = false
|
||||
state.value = result
|
||||
if (!authenticating.value || (frameUrl.value && frameUrl.value !== authUrl.value)) stopAuthentication()
|
||||
if (grantActive.value) {
|
||||
const expiresIn = result.quicksign_expires_at * 1000 - now.value
|
||||
if (expiresIn <= 2147483647) {
|
||||
grantExpiryTimer = setTimeout(() => { now.value = Date.now() + props.serverTimeOffsetMs }, expiresIn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function schedulePoll() {
|
||||
if (frameUrl.value) pollTimer = setTimeout(() => void refresh(), pollInterval)
|
||||
}
|
||||
|
||||
function openAuthentication() {
|
||||
if (!canAct() || pending.value || !canResume.value) return
|
||||
frameUrl.value = authUrl.value
|
||||
error.value = ''
|
||||
deadlineTimer = setTimeout(() => {
|
||||
cancelWork()
|
||||
error.value = '自动检查已结束,请检查状态后继续。'
|
||||
}, authenticationTimeout)
|
||||
schedulePoll()
|
||||
}
|
||||
|
||||
function authenticationUnavailable() {
|
||||
if (!frameUrl.value) return
|
||||
cancelWork()
|
||||
error.value = '无法加载 e签宝认证页面,请检查状态后重试。'
|
||||
}
|
||||
|
||||
function enterMobile() {
|
||||
if (!canAct() || pending.value || !canResume.value || state.value?.quicksign_authorizing) return
|
||||
editingMobile.value = true
|
||||
error.value = ''
|
||||
}
|
||||
|
||||
async function submit(
|
||||
kind: DoctorRequest,
|
||||
request: () => Promise<PrescriptionEsignDoctorStatus>
|
||||
) {
|
||||
if (!canAct() || pending.value) return
|
||||
const current = generation
|
||||
clearInputs()
|
||||
clearTimeout(pollTimer)
|
||||
error.value = ''
|
||||
pending.value = kind
|
||||
try {
|
||||
const result = validateStatus(await request())
|
||||
if (current !== generation || !canAct()) return
|
||||
accept(result)
|
||||
} catch {
|
||||
if (current !== generation || !canAct()) return
|
||||
clearStatus()
|
||||
error.value = '医生签署身份状态待确认,请检查状态后继续。'
|
||||
return
|
||||
} finally {
|
||||
if (current === generation) pending.value = null
|
||||
}
|
||||
if (kind === 'start') openAuthentication()
|
||||
else schedulePoll()
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (!canAct() || pending.value) return
|
||||
const controller = new AbortController()
|
||||
statusRequest = controller
|
||||
try {
|
||||
await submit('status', () => prescriptionEsignDoctorStatus(controller.signal))
|
||||
} finally {
|
||||
if (statusRequest === controller) statusRequest = undefined
|
||||
}
|
||||
}
|
||||
|
||||
async function start() {
|
||||
if (!canAct() || pending.value) return
|
||||
if (canAuthorizeQuick.value) {
|
||||
await submit('start', () => prescriptionEsignDoctorStart({}))
|
||||
} else if (needsMobile.value) {
|
||||
const number = mobile.value.trim()
|
||||
clearInputs()
|
||||
if (!/^1[3-9]\d{9}$/.test(number)) {
|
||||
error.value = '请输入有效的大陆手机号码。'
|
||||
return
|
||||
}
|
||||
await submit('start', () => prescriptionEsignDoctorStart({ mobile: number }))
|
||||
}
|
||||
}
|
||||
|
||||
async function complete() {
|
||||
if (!canAct() || pending.value || !canComplete.value) return
|
||||
if (needsIdentityNumber.value) {
|
||||
const number = identityNumber.value.trim().toUpperCase()
|
||||
clearInputs()
|
||||
if (!/^(?:\d{15}|\d{17}[\dX])$/.test(number)) {
|
||||
error.value = '请输入本次认证使用的 15 或 18 位大陆居民身份证号码。'
|
||||
return
|
||||
}
|
||||
await submit('complete', () => prescriptionEsignDoctorComplete({ identity_number: number }))
|
||||
} else {
|
||||
await submit('complete', () => prescriptionEsignDoctorComplete({}))
|
||||
}
|
||||
}
|
||||
|
||||
function onVisibilityChange() {
|
||||
if (document.visibilityState === 'visible') void refresh()
|
||||
else clearStatus()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('visibilitychange', onVisibilityChange)
|
||||
void refresh()
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
closed = true
|
||||
clearStatus()
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.doctor-esign__message, .doctor-esign__error {
|
||||
margin: 0 0 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.doctor-esign__message:empty { display: none; }
|
||||
.doctor-esign__error { color: var(--el-color-danger); }
|
||||
.doctor-esign__expiry {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
gap: 8px 16px;
|
||||
margin: 0 0 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--el-border-color-light);
|
||||
}
|
||||
.doctor-esign__expiry dt { color: var(--el-text-color-secondary); }
|
||||
.doctor-esign__expiry dd { margin: 0; }
|
||||
.doctor-esign__field { display: grid; gap: 6px; max-width: 350px; }
|
||||
.doctor-esign__frame {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: min(60vh, 620px);
|
||||
border: 1px solid var(--el-border-color-light);
|
||||
border-radius: 4px;
|
||||
background: white;
|
||||
}
|
||||
.doctor-esign__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
|
||||
.doctor-esign__actions .el-button + .el-button { margin-left: 0; }
|
||||
</style>
|
||||
@@ -1,59 +1,137 @@
|
||||
<template>
|
||||
<section class="esign-panel" aria-label="处方电子签署" v-loading="busy">
|
||||
<section v-show="showControls || signingTime || reviewState?.required" class="esign-panel" aria-label="处方电子签署" v-loading="busy">
|
||||
<div class="esign-panel__heading">
|
||||
<strong>医师电子签署</strong>
|
||||
<el-tag v-if="state && confirmed" :type="state.status === 'signed' ? 'success' : 'info'" size="small">
|
||||
{{ state.status_label }}
|
||||
</el-tag>
|
||||
<el-tag v-if="state?.environment === 'sandbox' && state?.status !== 'legacy'" type="warning" size="small">
|
||||
<el-tag v-if="confirmed && state?.environment === 'sandbox' && state.status !== 'legacy'" type="warning" size="small">
|
||||
沙箱测试
|
||||
</el-tag>
|
||||
</div>
|
||||
<p v-if="state?.message" class="esign-panel__message">{{ state.message }}</p>
|
||||
<p v-if="state?.environment === 'sandbox' && state?.status !== 'legacy'" class="esign-panel__message">
|
||||
当前为沙箱测试签署,仅用于接入验证。
|
||||
</p>
|
||||
<p v-if="error" class="esign-panel__error" role="alert">{{ error }}</p>
|
||||
<div class="esign-panel__actions">
|
||||
<el-button
|
||||
v-if="state?.can_sign"
|
||||
type="primary"
|
||||
size="small"
|
||||
:disabled="busy || !confirmed"
|
||||
@click="start"
|
||||
>{{ state.status === 'failed' ? '重试核身签署' : authUrl ? '重新获取核身链接' : '发起核身签署' }}</el-button>
|
||||
<el-link v-if="authUrl && state?.can_sign && confirmed" :href="authUrl" target="_blank" rel="noopener noreferrer" type="primary">
|
||||
打开核身页面
|
||||
</el-link>
|
||||
<el-button
|
||||
v-if="state?.can_sign && (state.status === 'authenticating' || authUrl)"
|
||||
size="small"
|
||||
:disabled="busy || !confirmed"
|
||||
@click="complete"
|
||||
>已完成核身,继续签署</el-button>
|
||||
<el-button size="small" :disabled="busy" @click="refresh">刷新签署状态</el-button>
|
||||
<el-button v-if="state?.can_download" size="small" :disabled="busy || !confirmed" @click="download">
|
||||
下载已签原始 PDF
|
||||
</el-button>
|
||||
<el-steps v-if="(confirmed || busy) && state?.required && state.status !== 'voided' && (!audit || state.can_sign || state.can_retry_verify)" :active="activeStep" finish-status="success" simple>
|
||||
<el-step title="处方草稿已保存" />
|
||||
<el-step :title="verificationMethod === 'quick' ? '核对快捷签授权' : verificationMethod === 'sms' ? '校验短信验证码' : '验证医生身份'" />
|
||||
<el-step title="签名并完成" />
|
||||
</el-steps>
|
||||
<p v-if="message" class="esign-panel__message" aria-live="polite">{{ message }}</p>
|
||||
<div v-if="signingTime" class="esign-panel__message" aria-live="polite">
|
||||
<div v-if="signingTime.issuedTime">开具时间:{{ signingTime.issuedTime }}(北京时间)</div>
|
||||
<div v-if="signingTime.signatureTime">
|
||||
医生签署时间:{{ signingTime.signatureTime }}(北京时间 · {{ signingTime.source }})
|
||||
</div>
|
||||
<template v-else>
|
||||
<div>签署时间待核实</div>
|
||||
<div v-if="signingTime.verifiedTime">系统验签完成时间:{{ signingTime.verifiedTime }}(北京时间)</div>
|
||||
</template>
|
||||
<div v-if="!audit && state?.review_signature_time">
|
||||
审核签署时间:{{ formatSigningTime(state.review_signature_time) }}(北京时间 · 可信时间戳)
|
||||
<span v-if="state.review_signer_name"> · {{ state.review_signer_name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="authUrl && state?.can_sign" class="esign-panel__message">
|
||||
请在新页面完成核身,然后返回继续签署;关闭页面后可从处方详情继续。
|
||||
</p>
|
||||
<p v-if="error" class="esign-panel__error" role="alert">{{ error }}</p>
|
||||
<label v-if="identityDetailsRequired" class="esign-panel__identity">
|
||||
本次验证使用的身份证号
|
||||
<el-input
|
||||
v-model="identityNumber"
|
||||
type="password"
|
||||
maxlength="18"
|
||||
autocomplete="off"
|
||||
:spellcheck="false"
|
||||
placeholder="输入18位大陆居民身份证号"
|
||||
/>
|
||||
</label>
|
||||
<label v-if="smsCodeEntry" class="esign-panel__identity">
|
||||
短信验证码
|
||||
<el-input
|
||||
v-model="smsCode"
|
||||
type="password"
|
||||
inputmode="numeric"
|
||||
maxlength="6"
|
||||
autocomplete="off"
|
||||
:spellcheck="false"
|
||||
:disabled="busy"
|
||||
placeholder="输入6位短信验证码"
|
||||
/>
|
||||
</label>
|
||||
<div v-if="showControls && prescriptionId > 0" class="esign-panel__actions">
|
||||
<el-button type="primary" size="small" :disabled="busy || dialogVisible || (action.run === sendSms && smsSendCoolingDown)" @click="action.run">
|
||||
{{ action.label }}
|
||||
</el-button>
|
||||
<el-button v-if="smsCodeEntry" size="small" :disabled="busy || smsSendCoolingDown" @click="sendSms">
|
||||
{{ smsSendCoolingDown ? '请稍后重新发送' : '重新发送验证码' }}
|
||||
</el-button>
|
||||
<el-button v-if="readiness" size="small" :disabled="busy" @click="closeAuthentication">取消</el-button>
|
||||
</div>
|
||||
<EsignReviewPanel
|
||||
v-if="audit && confirmed && state"
|
||||
:prescription-id="prescriptionId"
|
||||
:order-id="reviewOrderId"
|
||||
:doctor-signed="state.status === 'signed'"
|
||||
@change="updateReview"
|
||||
/>
|
||||
<el-dialog
|
||||
:model-value="dialogVisible"
|
||||
title="验证医生身份"
|
||||
width="min(720px, 94vw)"
|
||||
top="5vh"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
:before-close="closeAuthentication"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<p class="esign-panel__message">请在下方完成本人身份验证。</p>
|
||||
<iframe
|
||||
v-if="authUrl && dialogVisible"
|
||||
:src="authUrl"
|
||||
class="esign-panel__frame"
|
||||
title="e签宝本人身份核验"
|
||||
sandbox="allow-forms allow-scripts allow-same-origin"
|
||||
referrerpolicy="no-referrer"
|
||||
@error="authenticationUnavailable"
|
||||
/>
|
||||
<template #footer>
|
||||
<el-button link @click="authenticationUnavailable">验证页面不可用</el-button>
|
||||
<el-button @click="closeAuthentication">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed, onBeforeUnmount, onDeactivated, onMounted, ref, toRaw, watch } from 'vue'
|
||||
import {
|
||||
prescriptionEsignComplete,
|
||||
prescriptionEsignDoctorStatus,
|
||||
prescriptionEsignIdentityStatus,
|
||||
prescriptionEsignStart,
|
||||
prescriptionEsignStatus,
|
||||
prescriptionEsignVerifyWillingness,
|
||||
type PrescriptionEsignIdentityStatus,
|
||||
type PrescriptionEsignReviewStatus,
|
||||
type PrescriptionEsignStatus
|
||||
} from '@/api/tcm'
|
||||
import { downloadPrescriptionPdfIfRequired, safeEsignAuthUrl, validateEsignStatus } from '@/utils/prescription-esign'
|
||||
import {
|
||||
canApprovePrescriptionEsign,
|
||||
canCheckEsignIdentity,
|
||||
downloadOriginalEsignPdf,
|
||||
formatSigningTime,
|
||||
prescriptionEsignTiming,
|
||||
safeEsignAuthUrl,
|
||||
validateEsignIdentityStatus,
|
||||
validateEsignStatus
|
||||
} from '@/utils/prescription-esign'
|
||||
import EsignReviewPanel from '@/components/EsignReviewPanel.vue'
|
||||
|
||||
const props = defineProps<{ prescriptionId: number; initialState?: PrescriptionEsignStatus; audit?: boolean; reviewOrderId?: number }>()
|
||||
const emit = defineEmits<{
|
||||
(e: 'status-change', state: PrescriptionEsignStatus): void
|
||||
(e: 'review-change', state: PrescriptionEsignReviewStatus | null): void
|
||||
}>()
|
||||
|
||||
const reviewState = ref<PrescriptionEsignReviewStatus | null>(null)
|
||||
function updateReview(result: PrescriptionEsignReviewStatus | null) {
|
||||
reviewState.value = result
|
||||
emit('review-change', result)
|
||||
}
|
||||
|
||||
const props = defineProps<{ prescriptionId: number; initialState?: PrescriptionEsignStatus }>()
|
||||
const emit = defineEmits<{ (e: 'status-change', state: PrescriptionEsignStatus): void }>()
|
||||
function initialStatus(): PrescriptionEsignStatus | null {
|
||||
try {
|
||||
return validateEsignStatus(props.initialState)
|
||||
@@ -61,80 +139,556 @@ function initialStatus(): PrescriptionEsignStatus | null {
|
||||
return null
|
||||
}
|
||||
}
|
||||
const state = ref<PrescriptionEsignStatus | null>(initialStatus())
|
||||
const busy = ref(false)
|
||||
const confirmed = ref(false)
|
||||
const error = ref('')
|
||||
const authUrl = computed(() => safeEsignAuthUrl(state.value?.auth_url))
|
||||
let generation = 0
|
||||
|
||||
async function run(action: 'refresh' | 'start' | 'complete') {
|
||||
if (busy.value || !props.prescriptionId) return
|
||||
if (action !== 'refresh' && (!confirmed.value || state.value?.can_sign !== true)) return
|
||||
const id = props.prescriptionId
|
||||
const current = generation
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const api = action === 'start' ? prescriptionEsignStart : action === 'complete' ? prescriptionEsignComplete : prescriptionEsignStatus
|
||||
const result = validateEsignStatus(await api({ id }))
|
||||
if (id !== props.prescriptionId || current !== generation) return
|
||||
state.value = result
|
||||
confirmed.value = true
|
||||
emit('status-change', result)
|
||||
// A browser visit is never evidence of authentication or signing.
|
||||
if (result.auth_url && !safeEsignAuthUrl(result.auth_url)) {
|
||||
error.value = '核身链接无效,请重新获取或联系管理员'
|
||||
const state = ref<PrescriptionEsignStatus | null>(initialStatus())
|
||||
const work = ref<'status' | 'start' | 'identity' | 'send-sms' | 'verify-sms' | 'sign' | 'verify' | 'download' | null>(null)
|
||||
const busy = computed(() => work.value !== null)
|
||||
const confirmed = ref(false)
|
||||
const showControls = computed(() => !props.audit || !confirmed.value || !canApprovePrescriptionEsign(state.value))
|
||||
const signingTime = computed(() => prescriptionEsignTiming(state.value))
|
||||
const error = ref('')
|
||||
const dialogVisible = ref(false)
|
||||
const readiness = ref<'ready' | 'details' | null>(null)
|
||||
const restartRequired = ref(false)
|
||||
const identityNumber = ref('')
|
||||
const smsCode = ref('')
|
||||
const smsCodeState = ref<'entry' | 'expired' | null>(null)
|
||||
const smsSendCoolingDown = ref(false)
|
||||
const smsProfileReady = ref(false)
|
||||
const identityDetailsRequired = computed(() => readiness.value === 'details')
|
||||
const authUrl = computed(() => safeEsignAuthUrl(state.value?.auth_url))
|
||||
type VerificationMethod = NonNullable<PrescriptionEsignStatus['verification_method']>
|
||||
const verificationMethod = computed(() => state.value?.verification_method)
|
||||
const accountSetupMessage = computed(() => {
|
||||
const current = state.value
|
||||
if (!current?.can_sign || !verificationMethod.value) return ''
|
||||
const settings = '请返回页面右上角账号菜单,在「医生电子签署身份」中处理。完成后回到处方查询签署状态。'
|
||||
if (current.doctor_identity_required && !(verificationMethod.value === 'sms' && smsProfileReady.value)) {
|
||||
return `${current.message || '请先完成医生签署身份认证。'} ${settings}`
|
||||
}
|
||||
if (!current.signing_authorization_required) return ''
|
||||
const reason = current.signing_authorization_reason
|
||||
const authorization = reason === 'exhausted' ? '快捷签授权次数已用完。' : reason === 'expired' ? '快捷签授权已到期。'
|
||||
: reason === 'invalid' ? '快捷签授权已失效。' : '快捷签授权待完成。'
|
||||
return `${authorization}${settings}`
|
||||
})
|
||||
const smsCodeEntry = computed(() => confirmed.value && smsCodeState.value === 'entry'
|
||||
&& canUseMethod(state.value, 'sms') && state.value?.sms_sent === true && !accountSetupMessage.value && !readiness.value)
|
||||
const identityResumable = computed(() => !verificationMethod.value && canCheckEsignIdentity(state.value)
|
||||
&& (state.value?.can_resume_identity === true || Boolean(authUrl.value)))
|
||||
const activeStep = computed(() => {
|
||||
if (state.value?.status === 'signed') return 3
|
||||
if (readiness.value || work.value === 'sign' || work.value === 'verify'
|
||||
|| state.value?.status === 'signing' || state.value?.status === 'uncertain') return 2
|
||||
return 1
|
||||
})
|
||||
const message = computed(() => {
|
||||
if (props.prescriptionId <= 0) return '缺少关联处方,无法核对签署状态。'
|
||||
if (props.audit && work.value === 'status') return '正在查询签署状态…'
|
||||
if (work.value === 'identity' && verificationMethod.value === 'quick') return '正在核对快捷签授权…'
|
||||
if (work.value === 'identity' && verificationMethod.value === 'sms') return '正在查询短信验证状态…'
|
||||
if (work.value === 'send-sms') return '正在向医生绑定的手机号发送验证码…'
|
||||
if (work.value === 'verify-sms') return '正在校验短信验证码…'
|
||||
if (work.value === 'sign') return '正在签署处方…'
|
||||
if (work.value === 'verify') return '正在校验已签文件…'
|
||||
if (!confirmed.value || error.value) return ''
|
||||
if (readiness.value) {
|
||||
if (verificationMethod.value === 'quick') return '快捷签授权已核对。请核对处方内容后确认签名。'
|
||||
if (verificationMethod.value === 'sms') return '短信验证码已通过。请核对处方内容后确认签名。'
|
||||
return '医生身份已验证。'
|
||||
}
|
||||
const current = state.value
|
||||
if (!current) return ''
|
||||
if (current.status === 'legacy' && !current.enabled) return current.message || '此处方使用手写签名。'
|
||||
if (current.status === 'signed') return current.can_download ? '处方已签署。' : '处方已签署,原件暂不可用。'
|
||||
if (current.required && ['pending', 'authenticating', 'failed'].includes(current.status)) {
|
||||
if (accountSetupMessage.value) return accountSetupMessage.value
|
||||
if (canUseMethod(current, 'quick')) {
|
||||
return current.message || '请查询签署状态,核对快捷签授权。'
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (id === props.prescriptionId && current === generation) {
|
||||
confirmed.value = false
|
||||
error.value = e?.msg || e?.message || '签署服务暂时不可用,请刷新状态后重试'
|
||||
if (canUseMethod(current, 'sms')) {
|
||||
if (smsCodeEntry.value) return '请输入医生绑定的手机号收到的验证码。'
|
||||
if (smsCodeState.value === 'expired') return '本次短信验证码已失效,请重新发送。'
|
||||
if (smsProfileReady.value) return '医生签署身份已就绪,请发送本张处方的验证码。'
|
||||
if (current.message) return current.message
|
||||
return current.sms_sent ? '请查询短信验证状态。' : '请将本张处方的验证码发送到医生绑定的手机号。'
|
||||
}
|
||||
} finally {
|
||||
if (current === generation) busy.value = false
|
||||
if (current.message) return current.message
|
||||
if (!current.enabled) return '电子签署暂不可用,请联系管理员。'
|
||||
if (props.audit && !current.can_sign) {
|
||||
return '请等待开方医生完成电子签署后,再审核通过。'
|
||||
}
|
||||
if (props.audit) return '请完成核身及电子签署后,再审核通过。'
|
||||
}
|
||||
return current.message || (current.can_sign ? '' : current.status_label)
|
||||
})
|
||||
const action = computed(() => {
|
||||
if (!confirmed.value) return { label: '查询签署状态', run: refresh }
|
||||
if (state.value?.can_download && (state.value.status === 'signed' || state.value.status === 'voided')) {
|
||||
return { label: '下载已签 PDF', run: download }
|
||||
}
|
||||
if (state.value?.status === 'uncertain' && state.value.can_retry_verify) {
|
||||
return { label: '重试校验已签文件', run: retryVerification }
|
||||
}
|
||||
if (state.value?.can_sign && ['pending', 'authenticating', 'failed'].includes(state.value.status)) {
|
||||
if (accountSetupMessage.value) return { label: '查询签署状态', run: refresh }
|
||||
if (readiness.value) return { label: '确认签名', run: confirmSign }
|
||||
if (verificationMethod.value === 'quick') return { label: '查询签署状态', run: refresh }
|
||||
if (verificationMethod.value === 'sms') {
|
||||
if (smsCodeEntry.value) return { label: '校验验证码', run: verifySms }
|
||||
if (state.value.sms_sent && smsCodeState.value !== 'expired') return { label: '查询签署状态', run: refresh }
|
||||
const label = smsSendCoolingDown.value ? '请稍后重新发送' : state.value.sms_sent ? '重新发送验证码' : '发送验证码'
|
||||
return { label, run: sendSms }
|
||||
}
|
||||
if (restartRequired.value) return { label: '重新验证医生身份', run: () => start(true) }
|
||||
if (identityResumable.value) return { label: '检查身份验证', run: recheckIdentity }
|
||||
return { label: state.value.status === 'failed' ? '重新验证医生身份' : '验证医生身份', run: () => start() }
|
||||
}
|
||||
return { label: '查询签署状态', run: refresh }
|
||||
})
|
||||
|
||||
const pollInterval = 5000
|
||||
const authenticationTimeout = 10 * 60 * 1000
|
||||
const smsSendCooldown = 60 * 1000
|
||||
let operation = 0
|
||||
let disposed = false
|
||||
let pollTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let deadlineTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let identityRequest: AbortController | undefined
|
||||
let resendTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let expiresAt = 0
|
||||
|
||||
function canAct() {
|
||||
return !disposed && !busy.value && props.prescriptionId > 0 && document.visibilityState === 'visible'
|
||||
}
|
||||
|
||||
function isCurrent(current: number, id: number) {
|
||||
return !disposed && current === operation && id === props.prescriptionId && document.visibilityState === 'visible'
|
||||
}
|
||||
|
||||
function canUseMethod(result: PrescriptionEsignStatus | null, method: VerificationMethod): boolean {
|
||||
return result?.verification_method === method && result.enabled && result.required && result.can_sign
|
||||
&& ['pending', 'authenticating', 'failed'].includes(result.status)
|
||||
}
|
||||
|
||||
function accept(result: PrescriptionEsignStatus) {
|
||||
state.value = result
|
||||
confirmed.value = true
|
||||
if (!result.can_sign || !['authenticating', 'failed'].includes(result.status)) restartRequired.value = false
|
||||
emit('status-change', result)
|
||||
}
|
||||
|
||||
function clearVerification() {
|
||||
clearTimeout(pollTimer)
|
||||
clearTimeout(deadlineTimer)
|
||||
pollTimer = undefined
|
||||
deadlineTimer = undefined
|
||||
identityRequest?.abort()
|
||||
identityRequest = undefined
|
||||
dialogVisible.value = false
|
||||
readiness.value = null
|
||||
identityNumber.value = ''
|
||||
smsCode.value = ''
|
||||
smsCodeState.value = null
|
||||
}
|
||||
|
||||
function cancelWork() {
|
||||
operation++
|
||||
work.value = null
|
||||
clearVerification()
|
||||
smsProfileReady.value = false
|
||||
}
|
||||
|
||||
function closeAuthentication() {
|
||||
if (dialogVisible.value || readiness.value) cancelWork()
|
||||
}
|
||||
|
||||
function stopVerification(message: string) {
|
||||
clearVerification()
|
||||
error.value = message
|
||||
}
|
||||
|
||||
function authenticationUnavailable() {
|
||||
if (!dialogVisible.value) return
|
||||
cancelWork()
|
||||
error.value = '验证页面无法加载,请重试或联系管理员。'
|
||||
}
|
||||
|
||||
function beginVerification(current: number, id: number) {
|
||||
expiresAt = Date.now() + authenticationTimeout
|
||||
deadlineTimer = setTimeout(() => {
|
||||
if (!isCurrent(current, id)) return
|
||||
cancelWork()
|
||||
error.value = '等待验证超时,请检查身份验证。'
|
||||
}, authenticationTimeout)
|
||||
}
|
||||
|
||||
function schedulePoll(current: number, id: number) {
|
||||
if (dialogVisible.value && isCurrent(current, id)) {
|
||||
pollTimer = setTimeout(() => void checkIdentity(current, id), pollInterval)
|
||||
}
|
||||
}
|
||||
|
||||
const refresh = () => run('refresh')
|
||||
const start = () => run('start')
|
||||
const complete = () => run('complete')
|
||||
async function requestIdentity<T>(request: (signal: AbortSignal) => Promise<T>): Promise<T> {
|
||||
const controller = new AbortController()
|
||||
identityRequest = controller
|
||||
try {
|
||||
return await request(controller.signal)
|
||||
} finally {
|
||||
if (identityRequest === controller) identityRequest = undefined
|
||||
}
|
||||
}
|
||||
|
||||
async function queryIdentity(id: number) {
|
||||
return validateEsignIdentityStatus(await requestIdentity((signal) => prescriptionEsignIdentityStatus({ id }, signal)))
|
||||
}
|
||||
|
||||
async function checkIdentity(current: number, id: number) {
|
||||
if (!isCurrent(current, id) || identityRequest || (!dialogVisible.value && work.value !== 'identity')) return
|
||||
try {
|
||||
const result = await queryIdentity(id)
|
||||
if (!isCurrent(current, id)) return
|
||||
if (Date.now() >= expiresAt) {
|
||||
stopVerification('等待验证超时,请检查身份验证。')
|
||||
return
|
||||
}
|
||||
accept(result)
|
||||
// Only this read-only server response can unlock the explicit confirmation button.
|
||||
if (result.verification_method) {
|
||||
stopVerification('签署方式已变化,请查询签署状态。')
|
||||
} else if (result.identity_status === 'FAIL' || result.identity_status === 'EXPIRED') {
|
||||
restartRequired.value = result.can_sign && ['authenticating', 'failed'].includes(result.status)
|
||||
stopVerification(result.identity_status === 'EXPIRED' ? '本次身份验证已过期。' : '本次身份验证未通过。')
|
||||
} else if (result.status === 'signed') {
|
||||
clearVerification()
|
||||
} else if (!canCheckEsignIdentity(result) || result.identity_status === 'UNAVAILABLE') {
|
||||
stopVerification(result.message || '暂时无法核对身份验证,请重试。')
|
||||
} else if (result.identity_details_required || result.can_complete) {
|
||||
dialogVisible.value = false
|
||||
readiness.value = result.identity_details_required ? 'details' : 'ready'
|
||||
} else if (authUrl.value) {
|
||||
dialogVisible.value = true
|
||||
} else {
|
||||
stopVerification('验证链接不可用,请重试或联系管理员。')
|
||||
}
|
||||
} catch {
|
||||
if (isCurrent(current, id)) {
|
||||
confirmed.value = false
|
||||
stopVerification('身份验证查询失败,请查询签署状态后重试。')
|
||||
}
|
||||
}
|
||||
schedulePoll(current, id)
|
||||
}
|
||||
|
||||
async function recheckIdentity() {
|
||||
if (!canAct() || !confirmed.value || !identityResumable.value || dialogVisible.value || readiness.value || restartRequired.value) return
|
||||
const id = props.prescriptionId
|
||||
const current = ++operation
|
||||
work.value = 'identity'
|
||||
error.value = ''
|
||||
beginVerification(current, id)
|
||||
try {
|
||||
await checkIdentity(current, id)
|
||||
} finally {
|
||||
if (isCurrent(current, id)) work.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function start(restart = false) {
|
||||
if (!canAct() || !confirmed.value || !state.value?.can_sign || verificationMethod.value || dialogVisible.value || readiness.value
|
||||
|| !['pending', 'authenticating', 'failed'].includes(state.value.status)
|
||||
|| restart !== restartRequired.value || (!restart && identityResumable.value)) return
|
||||
const id = props.prescriptionId
|
||||
const current = ++operation
|
||||
work.value = 'start'
|
||||
confirmed.value = false
|
||||
error.value = ''
|
||||
try {
|
||||
const result = validateEsignStatus(await prescriptionEsignStart(restart ? { id, restart_identity: true } : { id }))
|
||||
if (!isCurrent(current, id)) return
|
||||
accept(result)
|
||||
restartRequired.value = false
|
||||
if (result.status === 'authenticating' && result.can_sign) {
|
||||
if (!authUrl.value) {
|
||||
error.value = '验证链接无效,请重试或联系管理员。'
|
||||
return
|
||||
}
|
||||
dialogVisible.value = true
|
||||
beginVerification(current, id)
|
||||
schedulePoll(current, id)
|
||||
}
|
||||
} catch {
|
||||
if (isCurrent(current, id)) error.value = '验证请求结果待确认,请查询签署状态。'
|
||||
} finally {
|
||||
if (isCurrent(current, id)) work.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function applyMethodIdentity(result: PrescriptionEsignIdentityStatus, method: VerificationMethod, current: number, id: number) {
|
||||
if (result.can_sign && !canUseMethod(result, method)) throw new Error('签署方式已变化')
|
||||
accept(result)
|
||||
if (!canUseMethod(result, method) || accountSetupMessage.value) return
|
||||
if (result.can_complete) {
|
||||
beginVerification(current, id)
|
||||
readiness.value = 'ready'
|
||||
} else if (method === 'sms') {
|
||||
if (result.sms_sent && result.identity_status === 'ING') smsCodeState.value = 'entry'
|
||||
if (result.identity_status === 'EXPIRED' || result.identity_status === 'FAIL') smsCodeState.value = 'expired'
|
||||
}
|
||||
}
|
||||
|
||||
async function readMethodIdentity(current: number, id: number, method: VerificationMethod) {
|
||||
const result = await queryIdentity(id)
|
||||
if (!isCurrent(current, id)) return
|
||||
applyMethodIdentity(result, method, current, id)
|
||||
return result
|
||||
}
|
||||
|
||||
async function prepareQuick(result: PrescriptionEsignStatus, current: number, id: number) {
|
||||
work.value = 'identity'
|
||||
const retained = result.can_resume_identity === true
|
||||
if (retained) {
|
||||
const identity = await readMethodIdentity(current, id, 'quick')
|
||||
if (!identity || identity.identity_status !== 'EXPIRED' || !canUseMethod(identity, 'quick') || accountSetupMessage.value) return
|
||||
}
|
||||
if (!isCurrent(current, id)) return
|
||||
const prepared = validateEsignStatus(await prescriptionEsignStart(retained ? { id, restart_identity: true } : { id }))
|
||||
if (!isCurrent(current, id)) return
|
||||
accept(prepared)
|
||||
if (canUseMethod(prepared, 'quick') && prepared.can_resume_identity && !accountSetupMessage.value) {
|
||||
await readMethodIdentity(current, id, 'quick')
|
||||
}
|
||||
}
|
||||
|
||||
function startSmsCooldown() {
|
||||
clearTimeout(resendTimer)
|
||||
smsSendCoolingDown.value = true
|
||||
resendTimer = setTimeout(() => { smsSendCoolingDown.value = false }, smsSendCooldown)
|
||||
}
|
||||
|
||||
async function sendSms() {
|
||||
if (!canAct() || !confirmed.value || !canUseMethod(state.value, 'sms') || accountSetupMessage.value || readiness.value
|
||||
|| smsSendCoolingDown.value || (state.value?.sms_sent && !smsCodeEntry.value && smsCodeState.value !== 'expired')) return
|
||||
const id = props.prescriptionId
|
||||
const current = ++operation
|
||||
const restart = state.value?.sms_sent === true || state.value?.can_resume_identity === true
|
||||
clearVerification()
|
||||
smsProfileReady.value = false
|
||||
confirmed.value = false
|
||||
work.value = 'send-sms'
|
||||
error.value = ''
|
||||
startSmsCooldown()
|
||||
try {
|
||||
const result = validateEsignStatus(await prescriptionEsignStart(restart ? { id, restart_identity: true } : { id }))
|
||||
if (!isCurrent(current, id)) return
|
||||
accept(result)
|
||||
if (canUseMethod(result, 'sms') && result.sms_sent && result.can_resume_identity && !accountSetupMessage.value) {
|
||||
startSmsCooldown()
|
||||
work.value = 'identity'
|
||||
await readMethodIdentity(current, id, 'sms')
|
||||
}
|
||||
} catch {
|
||||
if (isCurrent(current, id)) {
|
||||
confirmed.value = false
|
||||
error.value = '短信发送状态待确认,请查询签署状态。'
|
||||
}
|
||||
} finally {
|
||||
if (isCurrent(current, id)) work.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function verifySms() {
|
||||
const code = smsCode.value.trim()
|
||||
smsCode.value = ''
|
||||
if (!canAct() || !smsCodeEntry.value) return
|
||||
if (!/^\d{6}$/.test(code)) {
|
||||
error.value = '请输入6位短信验证码。'
|
||||
return
|
||||
}
|
||||
const id = props.prescriptionId
|
||||
const current = ++operation
|
||||
clearVerification()
|
||||
confirmed.value = false
|
||||
work.value = 'verify-sms'
|
||||
error.value = ''
|
||||
try {
|
||||
const result = validateEsignIdentityStatus(await prescriptionEsignVerifyWillingness({ id, auth_code: code }))
|
||||
if (!isCurrent(current, id)) return
|
||||
applyMethodIdentity(result, 'sms', current, id)
|
||||
if (smsCodeEntry.value) error.value = '验证码未通过,请检查后重试。'
|
||||
} catch {
|
||||
if (isCurrent(current, id)) error.value = '短信校验结果待确认,请查询签署状态。'
|
||||
} finally {
|
||||
if (isCurrent(current, id)) work.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmSign() {
|
||||
const number = identityNumber.value.trim().toUpperCase()
|
||||
identityNumber.value = ''
|
||||
if (!canAct() || !confirmed.value || !readiness.value || !canCheckEsignIdentity(state.value)) return
|
||||
if (verificationMethod.value && (!canUseMethod(state.value, verificationMethod.value) || accountSetupMessage.value)) return
|
||||
if (Date.now() >= expiresAt) {
|
||||
stopVerification('等待验证超时,请检查身份验证。')
|
||||
return
|
||||
}
|
||||
if (identityDetailsRequired.value && !/^[1-9]\d{16}[\dX]$/.test(number)) {
|
||||
error.value = '请输入本次验证使用的18位大陆居民身份证号。'
|
||||
return
|
||||
}
|
||||
const id = props.prescriptionId
|
||||
await submitCompletion('sign', identityDetailsRequired.value ? { id, identity_number: number } : { id })
|
||||
}
|
||||
|
||||
async function retryVerification() {
|
||||
if (!canAct() || !confirmed.value || state.value?.status !== 'uncertain' || state.value.can_retry_verify !== true) return
|
||||
await submitCompletion('verify', { id: props.prescriptionId, verify_only: true })
|
||||
}
|
||||
|
||||
async function submitCompletion(kind: 'sign' | 'verify', params: Parameters<typeof prescriptionEsignComplete>[0]) {
|
||||
const current = ++operation
|
||||
const { id } = params
|
||||
// Consume readiness before dispatch. Neither an error nor a late reply replays the POST.
|
||||
clearVerification()
|
||||
confirmed.value = false
|
||||
work.value = kind
|
||||
error.value = ''
|
||||
try {
|
||||
const result = validateEsignStatus(await prescriptionEsignComplete(params))
|
||||
if (isCurrent(current, id)) accept(result)
|
||||
} catch {
|
||||
if (isCurrent(current, id)) {
|
||||
error.value = kind === 'sign' ? '签署结果待确认,请查询签署状态。' : '校验结果待确认,请查询签署状态。'
|
||||
}
|
||||
} finally {
|
||||
if (isCurrent(current, id)) work.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (!canAct()) return
|
||||
const id = props.prescriptionId
|
||||
const current = ++operation
|
||||
clearVerification()
|
||||
smsProfileReady.value = false
|
||||
work.value = 'status'
|
||||
confirmed.value = false
|
||||
error.value = ''
|
||||
try {
|
||||
const result = validateEsignStatus(await prescriptionEsignStatus({ id }))
|
||||
if (!isCurrent(current, id)) return
|
||||
accept(result)
|
||||
// A previous SMS failure can retain the setup flag after the doctor fixes the profile.
|
||||
if (canUseMethod(result, 'sms') && result.doctor_identity_required) {
|
||||
work.value = 'identity'
|
||||
const profile = await requestIdentity(prescriptionEsignDoctorStatus)
|
||||
if (!isCurrent(current, id)) return
|
||||
smsProfileReady.value = profile?.enabled === true && profile.status === 'ready'
|
||||
}
|
||||
if (accountSetupMessage.value) return
|
||||
if (canUseMethod(result, 'quick')) {
|
||||
await prepareQuick(result, current, id)
|
||||
} else if (canUseMethod(result, 'sms') && result.sms_sent && result.can_resume_identity) {
|
||||
work.value = 'identity'
|
||||
await readMethodIdentity(current, id, 'sms')
|
||||
}
|
||||
} catch {
|
||||
if (isCurrent(current, id)) {
|
||||
confirmed.value = false
|
||||
error.value = work.value === 'identity' ? '暂时无法核对签署条件,请查询签署状态后重试。' : '签署状态查询失败,请重试。'
|
||||
}
|
||||
} finally {
|
||||
if (isCurrent(current, id)) work.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function download() {
|
||||
if (busy.value || !confirmed.value || state.value?.can_download !== true) return
|
||||
busy.value = true
|
||||
if (!canAct() || !confirmed.value || !state.value?.can_download
|
||||
|| (state.value.status !== 'signed' && state.value.status !== 'voided')) return
|
||||
const id = props.prescriptionId
|
||||
const current = ++operation
|
||||
work.value = 'download'
|
||||
error.value = ''
|
||||
try {
|
||||
await downloadPrescriptionPdfIfRequired(props.prescriptionId)
|
||||
} catch (e: any) {
|
||||
confirmed.value = false
|
||||
error.value = e?.msg || e?.message || '下载签署文件失败,请重试'
|
||||
const result = validateEsignStatus(await prescriptionEsignStatus({ id }))
|
||||
if (!isCurrent(current, id)) return
|
||||
accept(result)
|
||||
if (result.can_download && (result.status === 'signed' || result.status === 'voided')) {
|
||||
await downloadOriginalEsignPdf(id, () => isCurrent(current, id))
|
||||
} else {
|
||||
error.value = '已签 PDF 暂不可下载。'
|
||||
}
|
||||
} catch {
|
||||
if (isCurrent(current, id)) error.value = '下载已签 PDF 失败,请重试。'
|
||||
} finally {
|
||||
busy.value = false
|
||||
if (isCurrent(current, id)) work.value = null
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.prescriptionId, () => {
|
||||
generation++
|
||||
busy.value = false
|
||||
function onVisibilityChange() {
|
||||
if (document.visibilityState === 'visible') return
|
||||
if (work.value === 'sign') error.value = '签署结果待确认,请查询签署状态。'
|
||||
if (work.value === 'verify') error.value = '校验结果待确认,请查询签署状态。'
|
||||
if (work.value === 'send-sms') error.value = '短信发送状态待确认,请查询签署状态。'
|
||||
if (work.value === 'verify-sms') error.value = '短信校验结果待确认,请查询签署状态。'
|
||||
cancelWork()
|
||||
}
|
||||
|
||||
function resetStatus() {
|
||||
cancelWork()
|
||||
restartRequired.value = false
|
||||
confirmed.value = false
|
||||
error.value = ''
|
||||
state.value = initialStatus()
|
||||
void refresh()
|
||||
}, { immediate: true })
|
||||
}
|
||||
|
||||
watch(() => props.prescriptionId, resetStatus, { immediate: true })
|
||||
watch(() => props.initialState, (value) => {
|
||||
if (value) {
|
||||
state.value = initialStatus()
|
||||
if (!state.value) confirmed.value = false
|
||||
}
|
||||
// An emitted state echoed by the parent preserves this interaction.
|
||||
if (toRaw(value) !== toRaw(state.value)) resetStatus()
|
||||
})
|
||||
|
||||
onMounted(() => document.addEventListener('visibilitychange', onVisibilityChange))
|
||||
onDeactivated(cancelWork)
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
cancelWork()
|
||||
clearTimeout(resendTimer)
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.esign-panel { margin: 12px 0; padding: 14px 16px; border: 1px solid var(--el-border-color-light); border-radius: 6px; background: var(--el-fill-color-light); }
|
||||
.esign-panel__heading, .esign-panel__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||||
.esign-panel__message { margin: 8px 0; color: var(--el-text-color-secondary); font-size: 13px; }
|
||||
.esign-panel__error { color: var(--el-color-danger); font-size: 13px; }
|
||||
.esign-panel {
|
||||
margin: 12px 0;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--el-border-color-light);
|
||||
border-radius: 6px;
|
||||
background: var(--el-bg-color);
|
||||
}
|
||||
.esign-panel__heading, .esign-panel__actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.esign-panel :deep(.el-steps) { margin: 10px 0; padding: 10px 12px; }
|
||||
.esign-panel :deep(.el-step.is-simple .el-step__title) { font-size: 13px; line-height: 1.4; word-break: normal; }
|
||||
.esign-panel__actions { margin-top: 10px; }
|
||||
.esign-panel__actions .el-button + .el-button { margin-left: 0; }
|
||||
.esign-panel__message, .esign-panel__error { margin: 8px 0; font-size: 13px; }
|
||||
.esign-panel__message { color: var(--el-text-color-secondary); }
|
||||
.esign-panel__error { color: var(--el-color-danger); }
|
||||
.esign-panel__identity { display: grid; gap: 6px; max-width: 320px; margin: 10px 0; font-size: 13px; }
|
||||
.esign-panel__frame {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: min(62vh, 620px);
|
||||
min-height: 300px;
|
||||
border: 1px solid var(--el-border-color-light);
|
||||
border-radius: 4px;
|
||||
background: white;
|
||||
}
|
||||
@media print { .esign-panel { display: none; } }
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
<template>
|
||||
<div v-if="state?.required || error" class="esign-review" v-loading="busy" aria-label="处方审核电子签署">
|
||||
<strong>审核电子签署</strong>
|
||||
<p v-if="state?.actor_name">当前审核人 {{ state.actor_name }}</p>
|
||||
<p v-if="state?.state === 'signed'">
|
||||
{{ state.signer_name }} · {{ formatSigningTime(state.signature_time) }}(北京时间 · 可信时间戳)
|
||||
</p>
|
||||
<p v-if="state?.message" aria-live="polite">{{ state.message }}</p>
|
||||
<p v-if="error" class="text-danger" role="alert">{{ error }}</p>
|
||||
<div class="esign-review__actions">
|
||||
<el-button v-if="state?.can_confirm" type="primary" size="small" :disabled="busy" @click="confirm(false)">
|
||||
确认签名
|
||||
</el-button>
|
||||
<el-button v-if="state?.can_retry_verify" type="primary" size="small" :disabled="busy" @click="confirm(true)">
|
||||
重试验签
|
||||
</el-button>
|
||||
<el-button v-if="state?.required && doctorSigned" size="small" :disabled="busy" @click="download">
|
||||
{{ state.state === 'signed' ? '下载双签 PDF' : '下载医生已签 PDF' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="state?.can_setup && state.state !== 'signed'"
|
||||
size="small"
|
||||
:disabled="busy"
|
||||
@click="identityOpen = true"
|
||||
>
|
||||
审核签署身份
|
||||
</el-button>
|
||||
<el-button v-if="state?.required && !state.can_approve" size="small" :disabled="busy" @click="switchReviewer">
|
||||
切换审核账号
|
||||
</el-button>
|
||||
<el-button v-if="error || state?.state !== 'signed'" size="small" :disabled="busy" @click="refresh">
|
||||
刷新签署状态
|
||||
</el-button>
|
||||
</div>
|
||||
<EsignDoctorDialog
|
||||
v-if="identityOpen"
|
||||
reviewer
|
||||
:server-time-offset-ms="userStore.serverTimeOffsetMs"
|
||||
@close="closeIdentity"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import {
|
||||
prescriptionEsignReviewConfirm,
|
||||
prescriptionEsignReviewStatus,
|
||||
type PrescriptionEsignReviewStatus
|
||||
} from '@/api/tcm'
|
||||
import EsignDoctorDialog from '@/components/EsignDoctorDialog.vue'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import feedback from '@/utils/feedback'
|
||||
import { downloadOriginalEsignPdf, formatSigningTime } from '@/utils/prescription-esign'
|
||||
|
||||
const props = defineProps<{ prescriptionId: number; orderId?: number; doctorSigned: boolean }>()
|
||||
const emit = defineEmits<{ (e: 'change', value: PrescriptionEsignReviewStatus | null): void }>()
|
||||
const state = ref<PrescriptionEsignReviewStatus | null>(null)
|
||||
const identityOpen = ref(false)
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const userStore = useUserStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
let generation = 0
|
||||
let statusRequest: AbortController | undefined
|
||||
|
||||
function errorMessage(cause: unknown, fallback: string): string {
|
||||
if (typeof cause === 'object' && cause !== null && 'msg' in cause && typeof cause.msg === 'string') {
|
||||
return cause.msg
|
||||
}
|
||||
return cause instanceof Error ? cause.message : fallback
|
||||
}
|
||||
|
||||
function accept(result: PrescriptionEsignReviewStatus) {
|
||||
if (!result || ['required', 'can_confirm', 'can_approve', 'can_retry_verify'].some((field) => typeof (result as any)[field] !== 'boolean')
|
||||
|| result.actor_id !== Number(userStore.userInfo.id)) {
|
||||
throw new Error('登录账号或审核状态已变化,请刷新页面')
|
||||
}
|
||||
state.value = result
|
||||
emit('change', result)
|
||||
}
|
||||
|
||||
function target() {
|
||||
return { id: props.prescriptionId, ...(props.orderId ? { order_id: props.orderId } : {}) }
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
const ticket = ++generation
|
||||
statusRequest?.abort()
|
||||
statusRequest = new AbortController()
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
emit('change', null)
|
||||
try {
|
||||
const result = await prescriptionEsignReviewStatus(target(), statusRequest.signal)
|
||||
if (ticket === generation) accept(result)
|
||||
} catch (cause) {
|
||||
if (ticket === generation) error.value = errorMessage(cause, '无法查询审核签署状态')
|
||||
} finally {
|
||||
if (ticket === generation) busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function confirm(verifyOnly: boolean) {
|
||||
const actorId = state.value?.actor_id
|
||||
if (busy.value || !actorId || !(verifyOnly ? state.value?.can_retry_verify : state.value?.can_confirm)) return
|
||||
const ticket = ++generation
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await prescriptionEsignReviewConfirm({ ...target(), actor_id: actorId, verify_only: verifyOnly })
|
||||
if (ticket === generation) accept(result)
|
||||
} catch (cause) {
|
||||
if (ticket === generation) {
|
||||
await refresh()
|
||||
if (generation === ticket + 1) {
|
||||
error.value = errorMessage(cause, '请刷新状态或续期本人的快捷签授权后重试')
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (ticket === generation) busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function switchReviewer() {
|
||||
try {
|
||||
await feedback.confirm('当前账号将退出。请所选审核人本人登录。')
|
||||
if (busy.value) return
|
||||
busy.value = true
|
||||
const returnTo = router.resolve({
|
||||
path: route.path,
|
||||
query: props.orderId ? { review_order: props.orderId } : { review_prescription: props.prescriptionId }
|
||||
}).fullPath
|
||||
await userStore.logout(returnTo)
|
||||
} catch {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function download() {
|
||||
if (busy.value || !props.doctorSigned) return
|
||||
const ticket = generation
|
||||
const actor = userStore.userInfo.id
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await downloadOriginalEsignPdf(props.prescriptionId,
|
||||
() => generation === ticket && userStore.userInfo.id === actor)
|
||||
} catch (cause) {
|
||||
if (generation === ticket) error.value = errorMessage(cause, '下载签署原件失败,请重试')
|
||||
} finally {
|
||||
if (generation === ticket) busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function closeIdentity() {
|
||||
identityOpen.value = false
|
||||
void refresh()
|
||||
}
|
||||
|
||||
watch(() => [props.prescriptionId, props.orderId, props.doctorSigned, userStore.userInfo.id],
|
||||
() => { if (props.prescriptionId > 0) void refresh() }, { immediate: true })
|
||||
onBeforeUnmount(() => {
|
||||
generation++
|
||||
statusRequest?.abort()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.esign-review {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
border-top: 1px solid var(--el-border-color-light);
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.esign-review p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.esign-review__actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.esign-review__actions :deep(.el-button + .el-button) {
|
||||
margin-left: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -514,7 +514,7 @@
|
||||
{{ esignError }} <el-button link type="primary" @click="loadEsignConfig">重试</el-button>
|
||||
</el-alert>
|
||||
<el-alert v-else-if="esignEnabled" type="info" :closable="false" class="mb-3"
|
||||
:title="esignConfig?.environment === 'sandbox' ? '沙箱测试:保存处方后,请完成医师核身与电子签署' : '保存处方后,请完成医师核身与电子签署'" />
|
||||
:title="esignConfig?.environment === 'sandbox' ? '沙箱测试。保存草稿后,由开方医生本人确认签署。' : '保存草稿后,由开方医生本人确认签署。'" />
|
||||
<el-form-item v-else-if="esignReady" label="医师签名" prop="doctor_signature" required>
|
||||
<div class="signature-pad-wrap">
|
||||
<canvas
|
||||
@@ -540,6 +540,7 @@
|
||||
|
||||
<div v-else class="rx-wrap">
|
||||
<EsignPrescriptionPanel
|
||||
v-if="visible"
|
||||
:key="savedPrescription.id"
|
||||
:prescription-id="Number(savedPrescription.id)"
|
||||
:initial-state="savedPrescription.esign"
|
||||
@@ -726,7 +727,7 @@
|
||||
<div class="flex justify-end gap-2">
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSave" :loading="saving || esignLoading" :disabled="!esignReady">
|
||||
{{ esignEnabled ? '保存后核身签署' : '保存处方' }}
|
||||
{{ esignEnabled ? '保存处方草稿' : '保存处方' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2133,11 +2134,16 @@ const handleSave = async () => {
|
||||
if (id) {
|
||||
// Keep the saved id even if the follow-up detail request fails; retrying must not add twice.
|
||||
savedPrescription.value = { ...formData, id, audit_status: 0, esign: res.esign }
|
||||
feedback.msgSuccess(res.esign?.required ? '处方已保存,请继续完成核身签署' : '处方已保存')
|
||||
feedback.msgSuccess(res.esign?.required ? '处方草稿已保存' : '处方已保存')
|
||||
try {
|
||||
savedPrescription.value = await prescriptionDetail({ id })
|
||||
const detail = await prescriptionDetail({ id })
|
||||
if (savedPrescription.value?.id === id) {
|
||||
savedPrescription.value = { ...detail, esign: savedPrescription.value.esign ?? detail.esign }
|
||||
}
|
||||
} catch {
|
||||
feedback.msgWarning('处方已保存,详情暂未加载,可从已开处方继续签署')
|
||||
if (savedPrescription.value?.id === id) {
|
||||
feedback.msgWarning(res.esign?.required ? '处方详情暂未加载,可继续操作' : '处方已保存,详情暂未加载,可从已开处方继续签署')
|
||||
}
|
||||
}
|
||||
emit('success')
|
||||
} else {
|
||||
|
||||
@@ -11,24 +11,85 @@
|
||||
<router-link to="/user/setting">
|
||||
<el-dropdown-item>个人设置</el-dropdown-item>
|
||||
</router-link>
|
||||
<el-dropdown-item v-if="canManageDoctorEsign" command="doctor-esign">
|
||||
医生电子签署身份
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-if="canManageReviewEsign" command="review-esign">
|
||||
审核签署身份
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="switch-account">切换账号</el-dropdown-item>
|
||||
<el-dropdown-item command="cache">清除缓存</el-dropdown-item>
|
||||
<el-dropdown-item command="logout">退出登录</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<esign-doctor-dialog
|
||||
v-if="(canManageDoctorEsign && doctorEsignOpen) || (canManageReviewEsign && reviewEsignOpen)"
|
||||
:reviewer="reviewEsignOpen"
|
||||
:server-time-offset-ms="userStore.serverTimeOffsetMs"
|
||||
@close="closeEsign"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import { systemCacheClear } from '@/api/setting/system'
|
||||
import { prescriptionEsignConfig } from '@/api/tcm'
|
||||
import EsignDoctorDialog from '@/components/EsignDoctorDialog.vue'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import feedback from '@/utils/feedback'
|
||||
import { hasPermission } from '@/utils/perm'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const route = useRoute()
|
||||
|
||||
const userInfo = computed(() => userStore.userInfo)
|
||||
const doctorEsignOpen = ref(false)
|
||||
const reviewEsignOpen = ref(false)
|
||||
const reviewEnabled = ref(false)
|
||||
// These are the write grants accepted by the doctor eSign endpoints.
|
||||
const prescriptionWritePermissions = [
|
||||
'tcm.prescription/add', 'tcm.prescription/edit', 'cf.prescription/add', 'cf.prescription/edit',
|
||||
'tcm.diagnosis/chufang', 'tcm.diagnosis/kaifang'
|
||||
]
|
||||
const canManageDoctorEsign = computed(() => {
|
||||
const { role_ids, root } = userInfo.value
|
||||
return Boolean(userStore.token) && Array.isArray(role_ids) && role_ids.some((id) => Number(id) === 1)
|
||||
&& (Number(root) === 1 || prescriptionWritePermissions.some((permission) => hasPermission([permission])))
|
||||
})
|
||||
const canManageReviewEsign = computed(() => Boolean(userStore.token) && reviewEnabled.value
|
||||
&& [ 'tcm.prescriptionOrder/auditPrescription', 'tcm.prescription/audit', 'cf.prescription/audit' ]
|
||||
.some((permission) => hasPermission([permission])))
|
||||
|
||||
function closeEsign() {
|
||||
doctorEsignOpen.value = false
|
||||
reviewEsignOpen.value = false
|
||||
}
|
||||
|
||||
watch([() => userStore.token, () => userInfo.value.id, canManageDoctorEsign, canManageReviewEsign], closeEsign, { flush: 'sync' })
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const config = await prescriptionEsignConfig()
|
||||
reviewEnabled.value = config.enabled && config.review_enabled === true && config.verification_method === 'quick'
|
||||
} catch {
|
||||
reviewEnabled.value = false
|
||||
}
|
||||
})
|
||||
|
||||
const handleCommand = async (command: string) => {
|
||||
switch (command) {
|
||||
case 'doctor-esign':
|
||||
if (canManageDoctorEsign.value) doctorEsignOpen.value = true
|
||||
break
|
||||
case 'review-esign':
|
||||
if (canManageReviewEsign.value) reviewEsignOpen.value = true
|
||||
break
|
||||
case 'switch-account':
|
||||
await feedback.confirm('当前账号将退出。请使用另一个账号登录。')
|
||||
await userStore.logout(route.fullPath)
|
||||
break
|
||||
case 'logout':
|
||||
await feedback.confirm('确定退出登录吗?')
|
||||
userStore.logout()
|
||||
|
||||
@@ -58,13 +58,17 @@ const useUserStore = defineStore({
|
||||
})
|
||||
})
|
||||
},
|
||||
logout() {
|
||||
logout(returnTo?: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout()
|
||||
.then(async (data) => {
|
||||
this.token = ''
|
||||
await router.push(PageEnum.LOGIN)
|
||||
clearAuthInfo()
|
||||
if (returnTo) {
|
||||
window.location.assign(router.resolve({ path: PageEnum.LOGIN, query: { redirect: returnTo, switch_account: '1' } }).href)
|
||||
} else {
|
||||
await router.push(PageEnum.LOGIN)
|
||||
}
|
||||
resolve(data)
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -2,9 +2,39 @@ import {
|
||||
prescriptionEsignDownload,
|
||||
prescriptionEsignStatus,
|
||||
type PrescriptionEsignFile,
|
||||
type PrescriptionEsignIdentityStatus,
|
||||
type PrescriptionEsignStatus
|
||||
} from '@/api/tcm'
|
||||
|
||||
const signingTimeFormatter = new Intl.DateTimeFormat('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hourCycle: 'h23'
|
||||
})
|
||||
|
||||
export function formatSigningTime(seconds: number | undefined): string {
|
||||
if (typeof seconds !== 'number' || !Number.isInteger(seconds) || seconds <= 0 || seconds > 253402300799) return ''
|
||||
return signingTimeFormatter.format(seconds * 1000)
|
||||
}
|
||||
|
||||
export function prescriptionEsignTiming(state?: PrescriptionEsignStatus | null) {
|
||||
if (!state || (state.status !== 'signed' && state.status !== 'voided')) return null
|
||||
|
||||
const source = state.signature_time_source === 'tsa' ? '可信时间戳'
|
||||
: state.signature_time_source === 'local' ? '签名记录时间' : ''
|
||||
const signatureTime = source ? formatSigningTime(state.signature_time) : ''
|
||||
const verifiedTime = formatSigningTime(state.signed_at)
|
||||
const issuedTime = formatSigningTime(state.issued_at)
|
||||
if (state.status === 'voided' && !state.can_download && !signatureTime && !verifiedTime && !issuedTime) return null
|
||||
|
||||
return { issuedTime, signatureTime, source, verifiedTime }
|
||||
}
|
||||
|
||||
export function safeEsignAuthUrl(value: unknown): string {
|
||||
if (typeof value !== 'string' || !value.trim() || /[\u0000-\u001f\\]/.test(value)) return ''
|
||||
try {
|
||||
@@ -22,12 +52,38 @@ export function validateEsignStatus(value: unknown): PrescriptionEsignStatus {
|
||||
const statuses = ['pending', 'authenticating', 'signing', 'signed', 'failed', 'uncertain', 'voided', 'legacy']
|
||||
if (!state || typeof state !== 'object' || !statuses.includes(state.status)
|
||||
|| !['sandbox', 'production'].includes(state.environment)
|
||||
|| ['enabled', 'required', 'can_sign', 'can_download'].some((key) => typeof (state as any)[key] !== 'boolean')) {
|
||||
|| ['enabled', 'required', 'can_sign', 'can_download'].some((key) => typeof (state as any)[key] !== 'boolean')
|
||||
|| (state.verification_method !== undefined && !['quick', 'sms'].includes(state.verification_method))
|
||||
|| [state.can_resume_identity, state.can_retry_verify, state.doctor_identity_required,
|
||||
state.signing_authorization_required, state.sms_sent].some((flag) => flag !== undefined && typeof flag !== 'boolean')) {
|
||||
throw new Error('无法核对处方签署状态,请刷新后重试')
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
export function canCheckEsignIdentity(state: PrescriptionEsignStatus | null): boolean {
|
||||
return state?.can_sign === true && (state.status === 'authenticating'
|
||||
|| (state.status === 'failed' && state.can_resume_identity === true))
|
||||
}
|
||||
|
||||
export function validateEsignIdentityStatus(value: unknown): PrescriptionEsignIdentityStatus {
|
||||
const state = validateEsignStatus(value) as PrescriptionEsignIdentityStatus
|
||||
const detailsRequired = state.identity_details_required ?? false
|
||||
const accountBased = state.verification_method === 'quick' || state.verification_method === 'sms'
|
||||
if (!['INIT', 'ING', 'SUCCESS', 'FAIL', 'EXPIRED', 'UNAVAILABLE'].includes(state.identity_status)
|
||||
|| typeof state.can_complete !== 'boolean'
|
||||
|| (state.identity_details_required !== undefined && typeof state.identity_details_required !== 'boolean')
|
||||
|| (state.can_complete && detailsRequired)
|
||||
|| (accountBased && (detailsRequired || (state.can_complete && (state.can_resume_identity !== true
|
||||
|| state.doctor_identity_required === true || state.signing_authorization_required === true
|
||||
|| (state.verification_method === 'sms' && state.sms_sent !== true)))))
|
||||
|| ((state.can_complete || detailsRequired)
|
||||
&& (state.identity_status !== 'SUCCESS' || !canCheckEsignIdentity(state)))) {
|
||||
throw new Error('无法核对身份验证结果,请刷新状态后重试')
|
||||
}
|
||||
return { ...state, identity_details_required: detailsRequired }
|
||||
}
|
||||
|
||||
export function requiresOriginalEsignPdf(status?: PrescriptionEsignStatus | null): boolean {
|
||||
try {
|
||||
const value = validateEsignStatus(status)
|
||||
@@ -37,6 +93,17 @@ export function requiresOriginalEsignPdf(status?: PrescriptionEsignStatus | null
|
||||
}
|
||||
}
|
||||
|
||||
export function canApprovePrescriptionEsign(status: unknown): boolean {
|
||||
try {
|
||||
const state = validateEsignStatus(status)
|
||||
return state.required
|
||||
? state.status === 'signed' && state.can_download
|
||||
: state.status === 'legacy' && !state.can_download
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify the received bytes before creating a download; never render or alter the signed PDF. */
|
||||
export async function verifyEsignPdf(file: PrescriptionEsignFile): Promise<Uint8Array> {
|
||||
if (!/^[a-f\d]{64}$/i.test(file.sha256 || '')) throw new Error('签署文件缺少有效校验信息')
|
||||
@@ -56,9 +123,11 @@ export async function verifyEsignPdf(file: PrescriptionEsignFile): Promise<Uint8
|
||||
return bytes
|
||||
}
|
||||
|
||||
export async function downloadOriginalEsignPdf(id: number): Promise<void> {
|
||||
export async function downloadOriginalEsignPdf(id: number, isCurrent = () => true): Promise<void> {
|
||||
const file = await prescriptionEsignDownload({ id })
|
||||
if (!isCurrent()) return
|
||||
const bytes = await verifyEsignPdf(file)
|
||||
if (!isCurrent()) return
|
||||
const url = URL.createObjectURL(new Blob([bytes], { type: 'application/pdf' }))
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
|
||||
@@ -39,6 +39,22 @@
|
||||
<template #prepend>
|
||||
<icon name="el-icon-User" size="16" />
|
||||
</template>
|
||||
<template v-if="rememberedAccounts.length" #append>
|
||||
<el-dropdown trigger="click" @command="selectRememberedAccount">
|
||||
<el-button>选择账号</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
v-for="account in rememberedAccounts"
|
||||
:key="account"
|
||||
:command="account"
|
||||
>
|
||||
{{ account }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
@@ -122,6 +138,8 @@ const userStore = useUserStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const remAccount = ref(false)
|
||||
const rememberedAccounts = ref<string[]>([])
|
||||
const switchingAccount = computed(() => route.query.switch_account === '1')
|
||||
const config = computed(() => appStore.config)
|
||||
const formData = reactive({
|
||||
account: '',
|
||||
@@ -214,11 +232,15 @@ const handleEnter = () => {
|
||||
|
||||
const handleLogin = async () => {
|
||||
await formRef.value?.validate()
|
||||
const result: any = await userStore.login(formData)
|
||||
const account = formData.account.trim()
|
||||
const others = rememberedAccounts.value.filter((saved) => saved !== account)
|
||||
rememberedAccounts.value = (remAccount.value ? [account, ...others] : others).slice(0, 15)
|
||||
cache.set(ACCOUNT_KEY, {
|
||||
remember: remAccount.value,
|
||||
account: remAccount.value ? formData.account : ''
|
||||
account: remAccount.value ? account : '',
|
||||
accounts: rememberedAccounts.value
|
||||
})
|
||||
const result: any = await userStore.login(formData)
|
||||
|
||||
// 检查是否需要修改密码
|
||||
if (result.is_paw === 0) {
|
||||
@@ -307,11 +329,21 @@ watch(loginMode, (val) => {
|
||||
}
|
||||
})
|
||||
|
||||
function selectRememberedAccount(account: string) {
|
||||
formData.account = account
|
||||
formData.password = ''
|
||||
remAccount.value = true
|
||||
passwordRef.value?.focus()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 恢复记住账号
|
||||
const value = cache.get(ACCOUNT_KEY)
|
||||
if (value?.remember) {
|
||||
remAccount.value = value.remember
|
||||
const saved: unknown[] = Array.isArray(value?.accounts) ? value.accounts : value?.remember ? [value.account] : []
|
||||
rememberedAccounts.value = [...new Set(saved.filter((account): account is string =>
|
||||
typeof account === 'string' && account.trim().length > 0))].slice(0, 15)
|
||||
if (!switchingAccount.value && value?.remember && rememberedAccounts.value.includes(value.account)) {
|
||||
remAccount.value = true
|
||||
formData.account = value.account
|
||||
}
|
||||
|
||||
@@ -342,7 +374,7 @@ onMounted(async () => {
|
||||
wxWorkConfig.value = { corp_id: res.corp_id, agent_id: res.agent_id }
|
||||
|
||||
// 在企业微信内:自动跳转 OAuth 授权
|
||||
if (isInWxWork() && !hasIamCallback) {
|
||||
if (isInWxWork() && !hasIamCallback && !switchingAccount.value) {
|
||||
const redirectUri = encodeURIComponent(getRedirectUri())
|
||||
const authUrl =
|
||||
`https://open.weixin.qq.com/connect/oauth2/authorize` +
|
||||
|
||||
@@ -169,6 +169,9 @@
|
||||
<el-tag :type="listAuditStatusTagType(row)">
|
||||
{{ listAuditStatusLabel(row) }}
|
||||
</el-tag>
|
||||
<el-tag v-if="pendingEsignAudit(row)" type="warning" size="small" effect="plain">
|
||||
{{ row.esign.status_label }}
|
||||
</el-tag>
|
||||
<span
|
||||
v-if="Number(row.business_prescription_audit_rejected) === 1"
|
||||
class="text-xs text-gray-500"
|
||||
@@ -244,11 +247,11 @@
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="row.audit_status === 0 && row.void_status !== 1"
|
||||
v-if="isPendingPrescriptionAudit(row)"
|
||||
type="warning"
|
||||
link
|
||||
v-perms="['cf.prescription/audit']"
|
||||
@click="openAuditDialog(row)"
|
||||
@click="openAuditDialog(Number(row.id))"
|
||||
>
|
||||
审核
|
||||
</el-button>
|
||||
@@ -279,12 +282,13 @@
|
||||
class="cf-prescription-drawer"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
@close="showEdit = false"
|
||||
@closed="onEditDialogClosed"
|
||||
>
|
||||
<!-- 查看:A4 处方笺(药房联样式) -->
|
||||
<div v-if="editMode === 'view'" v-loading="viewDetailLoading" class="rx-wrap">
|
||||
<EsignPrescriptionPanel
|
||||
v-if="slipView?.id && !viewDetailLoading"
|
||||
v-if="showEdit && slipView?.id && !viewDetailLoading"
|
||||
:key="slipView.id"
|
||||
:prescription-id="Number(slipView.id)"
|
||||
:initial-state="slipView.esign"
|
||||
@@ -315,7 +319,17 @@
|
||||
size="small"
|
||||
>待审核</el-tag>
|
||||
<el-tag v-else-if="slipView" type="danger" size="small">已驳回</el-tag>
|
||||
<el-tag v-if="slipView && pendingEsignAudit(slipView)" type="warning" size="small" effect="plain">
|
||||
{{ slipView.esign.status_label }}
|
||||
</el-tag>
|
||||
<div class="flex-1" />
|
||||
<el-button
|
||||
v-if="slipView && !viewDetailLoading && isPendingPrescriptionAudit(slipView)"
|
||||
v-perms="['cf.prescription/audit']"
|
||||
type="warning"
|
||||
size="small"
|
||||
@click="openAuditDialog(Number(slipView.id))"
|
||||
>审核</el-button>
|
||||
<el-button v-if="!requiresOriginalEsignPdf(slipView?.esign)" :icon="Printer" size="small" @click="handlePrintSlip">打印</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
@@ -996,7 +1010,7 @@
|
||||
{{ esignError }} <el-button link type="primary" @click="loadEsignConfig">重试</el-button>
|
||||
</el-alert>
|
||||
<el-alert v-else-if="esignEnabled" type="info" :closable="false" class="mb-3"
|
||||
:title="esignConfig?.environment === 'sandbox' ? '沙箱测试:保存处方后,请完成医师核身与电子签署' : '保存处方后,请完成医师核身与电子签署'" />
|
||||
:title="esignConfig?.environment === 'sandbox' ? '沙箱测试。保存草稿后,由开方医生本人确认签署。' : '保存草稿后,由开方医生本人确认签署。'" />
|
||||
<el-form-item v-else-if="esignReady" label="医师签名" prop="doctor_signature" required>
|
||||
<div class="signature-pad-wrap">
|
||||
<canvas
|
||||
@@ -1023,7 +1037,7 @@
|
||||
<template v-else>
|
||||
<el-button @click="showEdit = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit" :loading="submitLoading || esignLoading" :disabled="!esignReady">
|
||||
{{ esignEnabled ? '保存后核身签署' : '确定' }}
|
||||
{{ esignEnabled ? '保存处方草稿' : '确定' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</template>
|
||||
@@ -1544,6 +1558,15 @@
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="auditDialogVisible" title="处方审核" width="480px" destroy-on-close @closed="auditRemark = ''">
|
||||
<EsignPrescriptionPanel
|
||||
v-if="auditDialogVisible"
|
||||
:key="auditTargetId"
|
||||
:prescription-id="auditTargetId"
|
||||
audit
|
||||
@review-change="auditReview = $event"
|
||||
class="mb-3"
|
||||
@status-change="onAuditEsignStatusChange"
|
||||
/>
|
||||
<p class="text-sm text-gray-600 mb-3">
|
||||
通过:处方保持有效。驳回:将同时作废此处方(与诊间「驳回/作废处方」一致)。
|
||||
</p>
|
||||
@@ -1561,7 +1584,7 @@
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="auditDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="auditLoading" @click="submitAudit('approve')">审核通过</el-button>
|
||||
<el-button type="primary" :loading="auditLoading" :disabled="!canApproveAudit" @click="submitAudit('approve')">审核通过</el-button>
|
||||
<el-button type="danger" :loading="auditLoading" @click="submitAudit('reject')">驳回处方</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -1599,11 +1622,11 @@ import MedicineNameSelect from '@/components/medicine-name-select/index.vue'
|
||||
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
|
||||
import EsignPrescriptionPanel from '@/components/EsignPrescriptionPanel.vue'
|
||||
import { usePrescriptionEsignConfig } from '@/hooks/usePrescriptionEsignConfig'
|
||||
import { downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf } from '@/utils/prescription-esign'
|
||||
import { canApprovePrescriptionEsign, downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf } from '@/utils/prescription-esign'
|
||||
import type { PrescriptionEsignStatus } from '@/api/tcm'
|
||||
import { Search, Download, Printer, EditPen } from '@element-plus/icons-vue'
|
||||
import { computed, onMounted, onActivated, onDeactivated, reactive, ref, watch, nextTick, defineAsyncComponent } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import html2canvas from 'html2canvas'
|
||||
import jsPDF from 'jspdf'
|
||||
|
||||
@@ -1743,6 +1766,7 @@ const SLIP_ADDRESS_LINE = '地址:四川省成都市双流区黄甲街道黄
|
||||
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
function goBusinessOrderList() {
|
||||
const hit = router.getRoutes().find((r) => r.meta?.perms === 'tcm.prescriptionOrder/lists')
|
||||
@@ -1799,6 +1823,11 @@ const auditDialogVisible = ref(false)
|
||||
const auditTargetId = ref(0)
|
||||
const auditRemark = ref('')
|
||||
const auditLoading = ref(false)
|
||||
const auditEsign = ref<PrescriptionEsignStatus | null>(null)
|
||||
const auditReview = ref<import('@/api/tcm').PrescriptionEsignReviewStatus | null>(null)
|
||||
const canApproveAudit = computed(() => (
|
||||
canApprovePrescriptionEsign(auditEsign.value) && auditReview.value?.can_approve === true
|
||||
))
|
||||
|
||||
/** 修正处方笺显示用姓名 / 手机号 */
|
||||
const patchPatientVisible = ref(false)
|
||||
@@ -3094,6 +3123,14 @@ function isApprovedActivePrescription(row: { audit_status?: number; void_status?
|
||||
return Number(row.audit_status) === 1 && Number(row.void_status) !== 1
|
||||
}
|
||||
|
||||
function isPendingPrescriptionAudit(row: { audit_status?: number | string; void_status?: number | string }) {
|
||||
return (row.audit_status === 0 || row.audit_status === '0') && Number(row.void_status) !== 1
|
||||
}
|
||||
|
||||
function pendingEsignAudit(row: { audit_status?: number | string; void_status?: number | string; esign?: PrescriptionEsignStatus }) {
|
||||
return isPendingPrescriptionAudit(row) && row.esign?.required === true && !canApprovePrescriptionEsign(row.esign)
|
||||
}
|
||||
|
||||
function formatAuditTime(ts: number | null | undefined) {
|
||||
if (!ts) return ''
|
||||
const d = new Date(ts * 1000)
|
||||
@@ -3302,13 +3339,27 @@ function normalizeVisibleRoleIds(row: any): number[] {
|
||||
return []
|
||||
}
|
||||
|
||||
function openAuditDialog(row: any) {
|
||||
auditTargetId.value = row.id
|
||||
function openAuditDialog(id: number) {
|
||||
if (auditLoading.value) return
|
||||
auditTargetId.value = id
|
||||
auditEsign.value = null
|
||||
auditReview.value = null
|
||||
auditRemark.value = ''
|
||||
auditDialogVisible.value = true
|
||||
}
|
||||
|
||||
function onAuditEsignStatusChange(state: PrescriptionEsignStatus) {
|
||||
const justSigned = auditEsign.value && !canApproveAudit.value && state.status === 'signed'
|
||||
&& canApprovePrescriptionEsign(state)
|
||||
auditEsign.value = state
|
||||
if (justSigned) {
|
||||
if (Number(slipView.value?.id) === auditTargetId.value && slipView.value) slipView.value.esign = state
|
||||
else void getLists()
|
||||
}
|
||||
}
|
||||
|
||||
async function submitAudit(action: 'approve' | 'reject') {
|
||||
if (auditLoading.value || (action === 'approve' && !canApproveAudit.value)) return
|
||||
if (action === 'reject' && !auditRemark.value.trim()) {
|
||||
feedback.msgError('驳回时请填写审核意见')
|
||||
return
|
||||
@@ -3325,6 +3376,7 @@ async function submitAudit(action: 'approve' | 'reject') {
|
||||
feedback.msgWarning(auditData.wecom_notify_hint)
|
||||
}
|
||||
auditDialogVisible.value = false
|
||||
if (showEdit.value && Number(slipView.value?.id) === auditTargetId.value) showEdit.value = false
|
||||
getLists()
|
||||
} catch {
|
||||
/* 拦截器已提示 */
|
||||
@@ -3903,7 +3955,7 @@ const handleSubmit = async () => {
|
||||
}
|
||||
if (esignEnabled.value || requiresOriginalEsignPdf(result?.esign)) {
|
||||
const id = Number(result?.id || editForm.id)
|
||||
feedback.msgSuccess(result?.esign?.required ? '处方已保存,请继续完成核身签署' : '处方已保存,请核对电子签署状态')
|
||||
feedback.msgSuccess(result?.esign?.required ? '处方草稿已保存' : '处方已保存,请核对电子签署状态')
|
||||
await handleView({ ...editForm, id, audit_status: 0, esign: result?.esign })
|
||||
} else {
|
||||
feedback.msgSuccess('保存成功,处方已进入待审核')
|
||||
@@ -3955,6 +4007,8 @@ onMounted(async () => {
|
||||
/* 已登录页仍可无用户信息,保持默认筛选 */
|
||||
}
|
||||
getLists()
|
||||
const reviewId = Number(route.query.review_prescription)
|
||||
if (Number.isSafeInteger(reviewId) && reviewId > 0) openAuditDialog(reviewId)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1297,11 +1297,21 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-alert>
|
||||
<EsignPrescriptionPanel
|
||||
v-if="auditVisible && auditKind === 'prescription'"
|
||||
:key="auditTargetId"
|
||||
:prescription-id="Number(auditRowData?.prescription_id) || 0"
|
||||
audit
|
||||
:review-order-id="Number(auditTargetId)"
|
||||
@review-change="auditReview = $event"
|
||||
class="mb-3"
|
||||
@status-change="auditEsign = $event"
|
||||
/>
|
||||
<p class="text-[13px] text-gray-500 mb-3 bg-gray-50/80 border border-gray-100 p-2 rounded">驳回时必须填写意见;通过时意见选填。</p>
|
||||
<el-input v-model="auditRemark" type="textarea" :rows="4" maxlength="500" show-word-limit placeholder="在此输入审核意见..." />
|
||||
<template #footer>
|
||||
<el-button @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" :disabled="!canApproveAudit" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="auditSubmitting" @click="submitAudit('reject')">驳回阻止</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -1778,6 +1788,7 @@
|
||||
v-model="prescriptionViewVisible"
|
||||
size="920px"
|
||||
:close-on-click-modal="false"
|
||||
@close="prescriptionViewVisible = false"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between w-full pr-2 gap-3">
|
||||
@@ -1863,7 +1874,7 @@
|
||||
</div>
|
||||
|
||||
<EsignPrescriptionPanel
|
||||
v-if="prescriptionViewData && !prescriptionViewLoading"
|
||||
v-if="prescriptionViewVisible && prescriptionViewData && !prescriptionViewLoading"
|
||||
:key="prescriptionViewData.id"
|
||||
:prescription-id="Number(prescriptionViewData.id)"
|
||||
:initial-state="prescriptionViewData.esign"
|
||||
@@ -2138,7 +2149,8 @@ import {
|
||||
} from '@/api/tcm'
|
||||
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
|
||||
import EsignPrescriptionPanel from '@/components/EsignPrescriptionPanel.vue'
|
||||
import { downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf } from '@/utils/prescription-esign'
|
||||
import type { PrescriptionEsignStatus } from '@/api/tcm'
|
||||
import { canApprovePrescriptionEsign, downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf } from '@/utils/prescription-esign'
|
||||
import html2canvas from 'html2canvas'
|
||||
import { jsPDF } from 'jspdf'
|
||||
import { getDictData } from '@/api/app'
|
||||
@@ -3705,20 +3717,29 @@ const auditTargetId = ref(0)
|
||||
const auditRowData = ref<any>(null)
|
||||
const auditRemark = ref('')
|
||||
const auditSubmitting = ref(false)
|
||||
const auditEsign = ref<PrescriptionEsignStatus | null>(null)
|
||||
const auditReview = ref<import('@/api/tcm').PrescriptionEsignReviewStatus | null>(null)
|
||||
const canApproveAudit = computed(() => auditKind.value === 'payment' || (
|
||||
canApprovePrescriptionEsign(auditEsign.value) && auditReview.value?.can_approve === true
|
||||
))
|
||||
|
||||
const auditTitle = computed(() =>
|
||||
auditKind.value === 'prescription' ? '处方业务审核' : '关联支付单审核'
|
||||
)
|
||||
|
||||
function openAudit(row: { id: number }, kind: 'prescription' | 'payment') {
|
||||
function openAudit(row: Record<string, any>, kind: 'prescription' | 'payment') {
|
||||
if (auditSubmitting.value) return
|
||||
auditKind.value = kind
|
||||
auditTargetId.value = row.id
|
||||
auditTargetId.value = Number(row.id)
|
||||
auditRowData.value = row
|
||||
auditEsign.value = null
|
||||
auditReview.value = null
|
||||
auditRemark.value = ''
|
||||
auditVisible.value = true
|
||||
}
|
||||
|
||||
async function submitAudit(action: 'approve' | 'reject') {
|
||||
if (auditSubmitting.value || (action === 'approve' && !canApproveAudit.value)) return
|
||||
if (action === 'reject' && !auditRemark.value.trim()) {
|
||||
feedback.msgError('驳回或阻止时必须填写明确的审核意见')
|
||||
return
|
||||
@@ -3939,6 +3960,8 @@ onMounted(async () => {
|
||||
applyRouteQueryToPrescriptionOrderList()
|
||||
await nextTick()
|
||||
getLists()
|
||||
const reviewOrderId = Number(route.query.review_order)
|
||||
if (Number.isSafeInteger(reviewOrderId) && reviewOrderId > 0) await openDetail(reviewOrderId)
|
||||
})
|
||||
|
||||
// ─── 快捷填写快递单号 ────────────────────────────────────────────
|
||||
|
||||
@@ -1865,11 +1865,21 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-alert>
|
||||
<EsignPrescriptionPanel
|
||||
v-if="auditVisible && auditKind === 'prescription'"
|
||||
:key="auditTargetId"
|
||||
:prescription-id="Number(auditRowData?.prescription_id) || 0"
|
||||
audit
|
||||
:review-order-id="Number(auditTargetId)"
|
||||
@review-change="auditReview = $event"
|
||||
class="mb-3"
|
||||
@status-change="auditEsign = $event"
|
||||
/>
|
||||
<p class="text-[13px] text-gray-500 mb-3 bg-gray-50/80 border border-gray-100 p-2 rounded">驳回时必须填写意见;通过时意见选填。</p>
|
||||
<el-input v-model="auditRemark" type="textarea" :rows="4" maxlength="500" show-word-limit placeholder="在此输入审核意见..." />
|
||||
<template #footer>
|
||||
<el-button @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" :disabled="!canApproveAudit" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="auditSubmitting" @click="submitAudit('reject')">驳回阻止</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -2378,6 +2388,7 @@
|
||||
direction="btt"
|
||||
class="po-h5-drawer"
|
||||
:close-on-click-modal="false"
|
||||
@close="prescriptionViewVisible = false"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between w-full pr-2 gap-3">
|
||||
@@ -2463,7 +2474,7 @@
|
||||
</div>
|
||||
|
||||
<EsignPrescriptionPanel
|
||||
v-if="prescriptionViewData && !prescriptionViewLoading"
|
||||
v-if="prescriptionViewVisible && prescriptionViewData && !prescriptionViewLoading"
|
||||
:key="prescriptionViewData.id"
|
||||
:prescription-id="Number(prescriptionViewData.id)"
|
||||
:initial-state="prescriptionViewData.esign"
|
||||
@@ -2642,6 +2653,7 @@
|
||||
|
||||
<script lang="ts" setup name="prescriptionOrderListH5">
|
||||
import { computed, onMounted, reactive, ref, nextTick, watch, defineAsyncComponent } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import {
|
||||
Refresh,
|
||||
Loading,
|
||||
@@ -2701,7 +2713,8 @@ import {
|
||||
} from './components/prescription-order-utils'
|
||||
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
|
||||
import EsignPrescriptionPanel from '@/components/EsignPrescriptionPanel.vue'
|
||||
import { downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf } from '@/utils/prescription-esign'
|
||||
import type { PrescriptionEsignStatus } from '@/api/tcm'
|
||||
import { canApprovePrescriptionEsign, downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf } from '@/utils/prescription-esign'
|
||||
import html2canvas from 'html2canvas'
|
||||
import { jsPDF } from 'jspdf'
|
||||
import { getDictData } from '@/api/app'
|
||||
@@ -4665,25 +4678,35 @@ async function submitEdit() {
|
||||
}
|
||||
|
||||
const auditVisible = ref(false)
|
||||
const route = useRoute()
|
||||
const auditKind = ref<'prescription' | 'payment'>('prescription')
|
||||
const auditTargetId = ref(0)
|
||||
const auditRowData = ref<any>(null)
|
||||
const auditRemark = ref('')
|
||||
const auditSubmitting = ref(false)
|
||||
const auditEsign = ref<PrescriptionEsignStatus | null>(null)
|
||||
const auditReview = ref<import('@/api/tcm').PrescriptionEsignReviewStatus | null>(null)
|
||||
const canApproveAudit = computed(() => auditKind.value === 'payment' || (
|
||||
canApprovePrescriptionEsign(auditEsign.value) && auditReview.value?.can_approve === true
|
||||
))
|
||||
|
||||
const auditTitle = computed(() =>
|
||||
auditKind.value === 'prescription' ? '处方业务审核' : '关联支付单审核'
|
||||
)
|
||||
|
||||
function openAudit(row: { id: number }, kind: 'prescription' | 'payment') {
|
||||
function openAudit(row: Record<string, any>, kind: 'prescription' | 'payment') {
|
||||
if (auditSubmitting.value) return
|
||||
auditKind.value = kind
|
||||
auditTargetId.value = row.id
|
||||
auditTargetId.value = Number(row.id)
|
||||
auditRowData.value = row
|
||||
auditEsign.value = null
|
||||
auditReview.value = null
|
||||
auditRemark.value = ''
|
||||
auditVisible.value = true
|
||||
}
|
||||
|
||||
async function submitAudit(action: 'approve' | 'reject') {
|
||||
if (auditSubmitting.value || (action === 'approve' && !canApproveAudit.value)) return
|
||||
if (action === 'reject' && !auditRemark.value.trim()) {
|
||||
feedback.msgError('驳回或阻止时必须填写明确的审核意见')
|
||||
return
|
||||
@@ -4864,6 +4887,8 @@ onMounted(async () => {
|
||||
await loadServicePackageOptions()
|
||||
await loadDoctorAssistantOptions()
|
||||
getLists()
|
||||
const reviewOrderId = Number(route.query.review_order)
|
||||
if (Number.isSafeInteger(reviewOrderId) && reviewOrderId > 0) await openDetail(reviewOrderId)
|
||||
})
|
||||
|
||||
// ─── 快捷填写快递单号 ────────────────────────────────────────────
|
||||
|
||||
@@ -32,6 +32,16 @@
|
||||
</prescription-order-detail-drawer>
|
||||
|
||||
<el-dialog v-model="auditVisible" :title="auditTitle" width="480px" append-to-body destroy-on-close>
|
||||
<EsignPrescriptionPanel
|
||||
v-if="auditVisible && auditKind === 'prescription'"
|
||||
:key="actionRow.id"
|
||||
:prescription-id="Number(actionRow.prescription_id) || 0"
|
||||
audit
|
||||
:review-order-id="Number(actionRow.id)"
|
||||
@review-change="auditReview = $event"
|
||||
class="mb-3"
|
||||
@status-change="auditEsign = $event"
|
||||
/>
|
||||
<el-alert
|
||||
title="通过时审核意见可不填;驳回时必须填写明确原因。"
|
||||
type="warning"
|
||||
@@ -49,7 +59,7 @@
|
||||
/>
|
||||
<template #footer>
|
||||
<el-button @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="primary" :loading="submitting" :disabled="!canApproveAudit" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="submitting" @click="submitAudit('reject')">驳回</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -243,6 +253,9 @@ import { computed, reactive, ref } from 'vue'
|
||||
import { ArrowDown } from '@element-plus/icons-vue'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import feedback from '@/utils/feedback'
|
||||
import EsignPrescriptionPanel from '@/components/EsignPrescriptionPanel.vue'
|
||||
import type { PrescriptionEsignStatus } from '@/api/tcm'
|
||||
import { canApprovePrescriptionEsign } from '@/utils/prescription-esign'
|
||||
import PrescriptionOrderDetailDrawer from '@/views/consumer/prescription/components/PrescriptionOrderDetailDrawer.vue'
|
||||
import {
|
||||
myPatientOrderAddPayOrder,
|
||||
@@ -299,6 +312,11 @@ const completeOptions = [
|
||||
const auditVisible = ref(false)
|
||||
const auditKind = ref<'prescription' | 'payment'>('prescription')
|
||||
const auditRemark = ref('')
|
||||
const auditEsign = ref<PrescriptionEsignStatus | null>(null)
|
||||
const auditReview = ref<import('@/api/tcm').PrescriptionEsignReviewStatus | null>(null)
|
||||
const canApproveAudit = computed(() => auditKind.value === 'payment' || (
|
||||
canApprovePrescriptionEsign(auditEsign.value) && auditReview.value?.can_approve === true
|
||||
))
|
||||
const auditTitle = computed(() => auditKind.value === 'prescription' ? '处方业务审核' : '关联支付单审核')
|
||||
|
||||
const trackVisible = ref(false)
|
||||
@@ -387,6 +405,7 @@ async function openEdit(row: Record<string, any>) {
|
||||
}
|
||||
|
||||
function openAction(row: Record<string, any>, action: MyPatientOrderAction) {
|
||||
if (submitting.value && (action === 'audit_prescription' || action === 'audit_payment')) return
|
||||
actionRow.value = row
|
||||
switch (action) {
|
||||
case 'edit':
|
||||
@@ -395,6 +414,8 @@ function openAction(row: Record<string, any>, action: MyPatientOrderAction) {
|
||||
case 'audit_prescription':
|
||||
case 'audit_payment':
|
||||
auditKind.value = action === 'audit_prescription' ? 'prescription' : 'payment'
|
||||
auditEsign.value = null
|
||||
auditReview.value = null
|
||||
auditRemark.value = ''
|
||||
auditVisible.value = true
|
||||
break
|
||||
@@ -450,6 +471,7 @@ async function changed(message: string) {
|
||||
}
|
||||
|
||||
async function submitAudit(action: 'approve' | 'reject') {
|
||||
if (submitting.value || (action === 'approve' && !canApproveAudit.value)) return
|
||||
if (action === 'reject' && !auditRemark.value.trim()) {
|
||||
feedback.msgError('驳回时必须填写审核意见')
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user