更新
This commit is contained in:
@@ -39,6 +39,7 @@ export function myPatientOrderEdit(params: Record<string, unknown>) {
|
||||
export function myPatientOrderAuditPrescription(params: {
|
||||
id: number
|
||||
action: 'approve' | 'reject'
|
||||
signature: string
|
||||
remark?: string
|
||||
}) {
|
||||
return request.post({ url: '/firstvisit.myPatient/orderAuditPrescription', params })
|
||||
|
||||
@@ -404,7 +404,7 @@ export function prescriptionDelete(params: { id: number }) {
|
||||
}
|
||||
|
||||
// 处方详情
|
||||
export function prescriptionDetail(params: { id: number }) {
|
||||
export function prescriptionDetail(params: { id: number; prescription_order_id?: number }) {
|
||||
return request.get({ url: '/tcm.prescription/detail', params })
|
||||
}
|
||||
|
||||
@@ -524,6 +524,7 @@ export function prescriptionOrderPatchPrescriptionUsage(params: {
|
||||
export function prescriptionOrderAuditPrescription(params: {
|
||||
id: number
|
||||
action: 'approve' | 'reject'
|
||||
signature: string
|
||||
remark?: string
|
||||
}) {
|
||||
return request.post({ url: '/tcm.prescriptionOrder/auditPrescription', params })
|
||||
@@ -642,6 +643,7 @@ export function prescriptionOrderAddLog(params: {
|
||||
payment_slip_audit_status?: number | ''
|
||||
prescription_audit_remark?: string
|
||||
payment_slip_audit_remark?: string
|
||||
signature?: string
|
||||
}) {
|
||||
return request.post({ url: '/tcm.prescriptionOrder/addLog', params })
|
||||
}
|
||||
|
||||
@@ -156,17 +156,25 @@
|
||||
<div class="rx-bottom">
|
||||
<div class="rx-bot-row rx-bot-row-1" :class="{ 'rx-bot-row-1--user': !isInternal }">
|
||||
<div class="rx-bot-cell rx-bot-doctor">
|
||||
<div class="rx-bot-label rx-bot-label--doctor">医师</div>
|
||||
<div class="rx-bot-doctor-body">
|
||||
<img
|
||||
v-if="data?.doctor_signature"
|
||||
:src="data.doctor_signature"
|
||||
alt="医师签名"
|
||||
class="rx-bot-sign-img"
|
||||
/>
|
||||
<span v-if="!data?.doctor_signature" class="rx-bot-doctor-name">
|
||||
{{ data?.doctor_name || '—' }}
|
||||
</span>
|
||||
<div class="rx-bot-doctor-line">
|
||||
<div class="rx-bot-label rx-bot-label--doctor">医师</div>
|
||||
<div class="rx-bot-doctor-body">
|
||||
<img
|
||||
v-if="data?.doctor_signature"
|
||||
:src="data.doctor_signature"
|
||||
alt="医师签名"
|
||||
class="rx-bot-sign-img"
|
||||
/>
|
||||
<span v-if="!data?.doctor_signature" class="rx-bot-doctor-name">
|
||||
{{ data?.doctor_name || '—' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="pharmacistSignature" class="rx-bot-pharmacist">
|
||||
<div class="rx-bot-pharmacist-line">
|
||||
<span class="rx-bot-label rx-bot-label--doctor">药师</span>
|
||||
<img :src="pharmacistSignature" alt="药师签名" class="rx-bot-sign-img rx-bot-pharmacist-signature" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="isInternal" class="rx-bot-cell rx-bot-meta">
|
||||
@@ -204,6 +212,7 @@ import {
|
||||
rxOutPelletText,
|
||||
rxPerDoseAmount,
|
||||
rxPharmacyRemarkText,
|
||||
rxPharmacistSignature,
|
||||
rxPrescriptionSnText,
|
||||
rxRecipientText,
|
||||
rxRemarkText,
|
||||
@@ -237,6 +246,7 @@ const props = withDefaults(
|
||||
const paperRef = ref<HTMLElement | null>(null)
|
||||
const isInternal = computed(() => props.variant !== 'user')
|
||||
const slipTitle = computed(() => props.title || '成都双流甄养堂互联网医院 处方笺')
|
||||
const pharmacistSignature = computed(() => rxPharmacistSignature(props.data))
|
||||
|
||||
const dateText = computed(() => rxDateText(props.data))
|
||||
const prescriptionSnText = computed(() => rxPrescriptionSnText(props.data))
|
||||
@@ -671,9 +681,36 @@ defineExpose({
|
||||
}
|
||||
|
||||
.rx-bot-doctor {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
flex-wrap: nowrap;
|
||||
gap: 4px;
|
||||
|
||||
.rx-bot-doctor-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.rx-bot-pharmacist {
|
||||
width: 100%;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.rx-bot-pharmacist-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.rx-bot-pharmacist-signature {
|
||||
min-width: 0;
|
||||
width: 110px;
|
||||
height: 40px;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
|
||||
.rx-bot-doctor-body {
|
||||
flex: 1;
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
|
||||
export type FormulaType = '主方' | '辅方'
|
||||
|
||||
/** 药师身份来自当前业务订单本次有效的签署审核,不回退到开方医生或历史审核人。 */
|
||||
export function rxPharmacistSignature(data: Record<string, any> | null | undefined): string {
|
||||
if (Number(data?.prescription_audit_status) !== 1) return ''
|
||||
return String(data?.prescription_audit_signature || '').trim()
|
||||
}
|
||||
|
||||
export type SlipHerb = {
|
||||
medicine_id?: number
|
||||
name: string
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
<template>
|
||||
<div class="signature-pad" :class="{ 'is-disabled': disabled }">
|
||||
<div class="signature-pad__surface">
|
||||
<canvas
|
||||
ref="canvasRef"
|
||||
class="signature-pad__canvas"
|
||||
aria-label="手写签名区域"
|
||||
:aria-disabled="disabled"
|
||||
@pointerdown.prevent="onPointerDown"
|
||||
@pointermove.prevent="onPointerMove"
|
||||
@pointerup.prevent="onPointerUp"
|
||||
@pointercancel.prevent="onPointerCancel"
|
||||
@lostpointercapture="onPointerCancel"
|
||||
/>
|
||||
<span v-if="!modelValue && !drawing" class="signature-pad__placeholder">请在此手写本人签名</span>
|
||||
</div>
|
||||
<div class="signature-pad__actions">
|
||||
<span>支持鼠标、触屏或手写笔</span>
|
||||
<el-button size="small" :disabled="disabled" @click="clearSignature">清空重签</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{ modelValue: string; disabled?: boolean }>(), { disabled: false })
|
||||
const emit = defineEmits<{ (event: 'update:modelValue', value: string): void }>()
|
||||
const canvasRef = ref<HTMLCanvasElement>()
|
||||
const drawing = ref(false)
|
||||
type Point = { x: number; y: number }
|
||||
// 归一化坐标让窗口旋转/调整尺寸后仍能重画笔迹,不重新使用历史签名图片。
|
||||
let strokes: Point[][] = []
|
||||
let activePointer: number | null = null
|
||||
let cssWidth = 0
|
||||
const cssHeight = 168
|
||||
let lastEmitted = ''
|
||||
let resizeObserver: ResizeObserver | undefined
|
||||
|
||||
function publish(value: string) {
|
||||
lastEmitted = value
|
||||
emit('update:modelValue', value)
|
||||
}
|
||||
|
||||
function localPoint(event: PointerEvent): Point | null {
|
||||
const rect = canvasRef.value?.getBoundingClientRect()
|
||||
if (!rect || rect.width <= 0 || rect.height <= 0) return null
|
||||
return {
|
||||
x: Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width)),
|
||||
y: Math.max(0, Math.min(1, (event.clientY - rect.top) / rect.height))
|
||||
}
|
||||
}
|
||||
|
||||
function drawSegment(from: Point, to: Point) {
|
||||
const ctx = canvasRef.value?.getContext('2d')
|
||||
if (!ctx) return
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(from.x * cssWidth, from.y * cssHeight)
|
||||
ctx.lineTo(to.x * cssWidth, to.y * cssHeight)
|
||||
ctx.stroke()
|
||||
}
|
||||
|
||||
function redraw() {
|
||||
const canvas = canvasRef.value
|
||||
const width = canvas?.getBoundingClientRect().width || 0
|
||||
if (!canvas || width <= 0) return
|
||||
cssWidth = width
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, 2.5)
|
||||
canvas.width = Math.round(width * dpr)
|
||||
canvas.height = Math.round(cssHeight * dpr)
|
||||
const ctx = canvas.getContext('2d')
|
||||
if (!ctx) return
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
||||
ctx.fillStyle = '#fff'
|
||||
ctx.fillRect(0, 0, width, cssHeight)
|
||||
ctx.strokeStyle = '#303133'
|
||||
ctx.lineWidth = 2.5
|
||||
ctx.lineCap = 'round'
|
||||
ctx.lineJoin = 'round'
|
||||
for (const stroke of strokes) {
|
||||
for (let index = 1; index < stroke.length; index++) drawSegment(stroke[index - 1], stroke[index])
|
||||
}
|
||||
}
|
||||
|
||||
function commitSignature() {
|
||||
let length = 0
|
||||
for (const stroke of strokes) {
|
||||
for (let index = 1; index < stroke.length; index++) {
|
||||
length += Math.hypot(
|
||||
(stroke[index].x - stroke[index - 1].x) * cssWidth,
|
||||
(stroke[index].y - stroke[index - 1].y) * cssHeight
|
||||
)
|
||||
}
|
||||
}
|
||||
// 点按、抖动、空白画布都不能作为签名提交。
|
||||
publish(length >= 12 && canvasRef.value ? canvasRef.value.toDataURL('image/png') : '')
|
||||
}
|
||||
|
||||
function onPointerDown(event: PointerEvent) {
|
||||
if (props.disabled || activePointer !== null || (event.pointerType === 'mouse' && event.button !== 0)) return
|
||||
const point = localPoint(event)
|
||||
if (!point || !canvasRef.value?.getContext('2d')) return
|
||||
if (!cssWidth) redraw()
|
||||
activePointer = event.pointerId
|
||||
drawing.value = true
|
||||
strokes.push([point])
|
||||
canvasRef.value.setPointerCapture(event.pointerId)
|
||||
// 尚未结束的笔画不参与审核;抬笔后发布完整签名。
|
||||
publish('')
|
||||
}
|
||||
|
||||
function onPointerMove(event: PointerEvent) {
|
||||
if (props.disabled || event.pointerId !== activePointer) return
|
||||
const point = localPoint(event)
|
||||
const stroke = strokes[strokes.length - 1]
|
||||
if (!point || !stroke) return
|
||||
const previous = stroke[stroke.length - 1]
|
||||
if (Math.hypot((point.x - previous.x) * cssWidth, (point.y - previous.y) * cssHeight) < 0.75) return
|
||||
stroke.push(point)
|
||||
drawSegment(previous, point)
|
||||
}
|
||||
|
||||
function releasePointer() {
|
||||
const pointer = activePointer
|
||||
activePointer = null
|
||||
drawing.value = false
|
||||
if (pointer !== null && canvasRef.value?.hasPointerCapture(pointer)) canvasRef.value.releasePointerCapture(pointer)
|
||||
}
|
||||
|
||||
function onPointerUp(event: PointerEvent) {
|
||||
if (event.pointerId !== activePointer) return
|
||||
onPointerMove(event)
|
||||
releasePointer()
|
||||
commitSignature()
|
||||
}
|
||||
|
||||
function onPointerCancel(event: PointerEvent) {
|
||||
if (event.pointerId !== activePointer) return
|
||||
strokes.pop()
|
||||
releasePointer()
|
||||
redraw()
|
||||
commitSignature()
|
||||
}
|
||||
|
||||
function clearSignature() {
|
||||
if (props.disabled) return
|
||||
releasePointer()
|
||||
strokes = []
|
||||
redraw()
|
||||
publish('')
|
||||
}
|
||||
|
||||
watch(() => props.modelValue, (value) => {
|
||||
if (value === lastEmitted) return
|
||||
if (!value) clearSignature()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
redraw()
|
||||
resizeObserver = new ResizeObserver(redraw)
|
||||
if (canvasRef.value) resizeObserver.observe(canvasRef.value)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
resizeObserver?.disconnect()
|
||||
releasePointer()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.signature-pad { width: 100%; overflow: hidden; border: 1px solid #dcdfe6; border-radius: 6px; background: #fff; }
|
||||
.signature-pad__surface { position: relative; }
|
||||
.signature-pad__canvas { display: block; width: 100%; height: 168px; touch-action: none; cursor: crosshair; }
|
||||
.signature-pad__placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #a8abb2; font-size: 14px; pointer-events: none; }
|
||||
.signature-pad__actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid #ebeef5; color: #909399; font-size: 12px; }
|
||||
.signature-pad.is-disabled { opacity: 0.65; }
|
||||
.is-disabled .signature-pad__canvas { cursor: not-allowed; }
|
||||
</style>
|
||||
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<div v-if="signature" class="audit-signature-record">
|
||||
<el-image
|
||||
:src="signature"
|
||||
:preview-src-list="[signature]"
|
||||
preview-teleported
|
||||
fit="contain"
|
||||
class="audit-signature-record__image"
|
||||
alt="审核人手写签名"
|
||||
/>
|
||||
<div class="audit-signature-record__meta">
|
||||
签署人:{{ signedName || (signedBy ? `#${signedBy}` : '—') }}
|
||||
<span class="ml-3">签署时间:{{ formatTime(signedAt) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { formatTime } from './prescription-order-utils'
|
||||
defineProps<{
|
||||
signature?: string
|
||||
signedBy?: number | string
|
||||
signedName?: string
|
||||
signedAt?: number | string | null
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.audit-signature-record { margin-top: 8px; }
|
||||
.audit-signature-record__image { display: block; width: 240px; max-width: 100%; height: 80px; border: 1px solid #ebeef5; border-radius: 4px; background: #fff; }
|
||||
.audit-signature-record__meta { display: flex; flex-wrap: wrap; gap: 4px 0; margin-top: 4px; color: #606266; font-size: 12px; }
|
||||
</style>
|
||||
+55
-10
@@ -709,6 +709,14 @@
|
||||
<el-descriptions-item label="处方审核意见" :span="3">
|
||||
<span class="po-audit-remark">{{ detailData.prescription_audit_remark || '—' }}</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item v-if="detailData.prescription_audit_signature" label="审核人签名" :span="3">
|
||||
<AuditSignatureRecord
|
||||
:signature="detailData.prescription_audit_signature"
|
||||
:signed-by="detailData.prescription_audit_signed_by"
|
||||
:signed-name="detailData.prescription_audit_signed_name"
|
||||
:signed-at="detailData.prescription_audit_signed_at"
|
||||
/>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="支付审核意见" :span="3">
|
||||
<span class="po-audit-remark">{{ detailData.payment_slip_audit_remark || '—' }}</span>
|
||||
</el-descriptions-item>
|
||||
@@ -870,6 +878,13 @@
|
||||
<el-tag size="small" type="info">{{ logActionText(log.action) }}</el-tag>
|
||||
</div>
|
||||
<span :class="idx === 0 ? 'text-gray-800 font-medium' : 'text-gray-500'">{{ log.summary }}</span>
|
||||
<AuditSignatureRecord
|
||||
v-if="log.audit_signature"
|
||||
:signature="log.audit_signature"
|
||||
:signed-by="log.admin_id"
|
||||
:signed-name="log.admin_name"
|
||||
:signed-at="log.create_time"
|
||||
/>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
<el-empty v-else description="暂无操作日志" :image-size="64" />
|
||||
@@ -883,9 +898,11 @@
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
append-to-body
|
||||
:close-on-press-escape="!addLogSaving"
|
||||
:show-close="!addLogSaving"
|
||||
@closed="resetAddLogForm"
|
||||
>
|
||||
<el-form ref="addLogFormRef" :model="addLogForm" :rules="addLogRules" label-width="108px">
|
||||
<el-form ref="addLogFormRef" :model="addLogForm" :rules="addLogRules" :disabled="addLogSaving" label-width="108px">
|
||||
<el-form-item label="日志内容" prop="summary">
|
||||
<el-input
|
||||
v-model="addLogForm.summary"
|
||||
@@ -942,10 +959,14 @@
|
||||
placeholder="选填"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="requiresAddLogSignature" label="审核人签名" required>
|
||||
<SignaturePad :key="addLogSession" v-model="addLogSignature" :disabled="addLogSaving" />
|
||||
<div class="text-xs text-gray-500 mt-1">设为已通过或已驳回需重新手写签名。</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="addLogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="addLogSaving" @click="submitAddLog">保存</el-button>
|
||||
<el-button :disabled="addLogSaving" @click="addLogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="addLogSaving" :disabled="requiresAddLogSignature && !addLogSignature" @click="submitAddLog">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
@@ -1057,7 +1078,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="PrescriptionOrderDetailDrawer">
|
||||
import { computed, nextTick, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
||||
import SignaturePad from '@/components/signature-pad/index.vue'
|
||||
import AuditSignatureRecord from './AuditSignatureRecord.vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { Refresh, Loading, Search, Van } from '@element-plus/icons-vue'
|
||||
import {
|
||||
@@ -1457,6 +1480,8 @@ const canSetPayAuditOnAddLog = computed(() => {
|
||||
const addLogVisible = ref(false)
|
||||
const addLogSaving = ref(false)
|
||||
const addLogFormRef = ref<FormInstance>()
|
||||
const addLogSignature = ref('')
|
||||
const addLogSession = ref(0)
|
||||
const addLogForm = reactive({
|
||||
summary: '',
|
||||
prescription_audit_status: '' as number | '',
|
||||
@@ -1467,6 +1492,13 @@ const addLogForm = reactive({
|
||||
const addLogRules: FormRules = {
|
||||
summary: [{ required: true, message: '请填写日志内容', trigger: 'blur' }]
|
||||
}
|
||||
const requiresAddLogSignature = computed(() =>
|
||||
canSetRxAuditOnAddLog.value && [1, 2].includes(Number(addLogForm.prescription_audit_status))
|
||||
)
|
||||
watch(() => addLogForm.prescription_audit_status, () => {
|
||||
addLogSignature.value = ''
|
||||
addLogSession.value++
|
||||
})
|
||||
|
||||
const patchUsageVisible = ref(false)
|
||||
const patchUsageSaving = ref(false)
|
||||
@@ -1584,16 +1616,19 @@ async function submitPatchUsage() {
|
||||
}
|
||||
|
||||
function resetAddLogForm() {
|
||||
if (addLogSaving.value) return
|
||||
addLogForm.summary = ''
|
||||
addLogForm.prescription_audit_status = ''
|
||||
addLogForm.payment_slip_audit_status = ''
|
||||
addLogForm.prescription_audit_remark = ''
|
||||
addLogForm.payment_slip_audit_remark = ''
|
||||
addLogSignature.value = ''
|
||||
addLogSession.value++
|
||||
addLogFormRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
function openAddLogDialog() {
|
||||
if (!detailData.value?.id) return
|
||||
if (addLogSaving.value || !detailData.value?.id) return
|
||||
resetAddLogForm()
|
||||
const d = detailData.value
|
||||
addLogForm.prescription_audit_remark = String(d.prescription_audit_remark || '')
|
||||
@@ -1602,12 +1637,17 @@ function openAddLogDialog() {
|
||||
}
|
||||
|
||||
async function submitAddLog() {
|
||||
if (!addLogFormRef.value || !detailData.value?.id) return
|
||||
await addLogFormRef.value.validate()
|
||||
if (addLogSaving.value || !addLogVisible.value || !addLogFormRef.value || !detailData.value?.id) return
|
||||
if (requiresAddLogSignature.value && !addLogSignature.value.trim()) {
|
||||
feedback.msgError('请先手写审核人签名')
|
||||
return
|
||||
}
|
||||
const targetId = Number(detailData.value.id)
|
||||
addLogSaving.value = true
|
||||
try {
|
||||
const payload: Record<string, unknown> = {
|
||||
id: detailData.value.id,
|
||||
if (!(await addLogFormRef.value.validate().catch(() => false))) return
|
||||
const payload: Parameters<typeof prescriptionOrderAddLog>[0] = {
|
||||
id: targetId,
|
||||
summary: addLogForm.summary.trim()
|
||||
}
|
||||
if (
|
||||
@@ -1618,6 +1658,7 @@ async function submitAddLog() {
|
||||
) {
|
||||
payload.prescription_audit_status = addLogForm.prescription_audit_status
|
||||
payload.prescription_audit_remark = addLogForm.prescription_audit_remark
|
||||
if (requiresAddLogSignature.value) payload.signature = addLogSignature.value
|
||||
}
|
||||
if (
|
||||
canSetPayAuditOnAddLog.value &&
|
||||
@@ -1628,9 +1669,10 @@ async function submitAddLog() {
|
||||
payload.payment_slip_audit_status = addLogForm.payment_slip_audit_status
|
||||
payload.payment_slip_audit_remark = addLogForm.payment_slip_audit_remark
|
||||
}
|
||||
await prescriptionOrderAddLog(payload as any)
|
||||
await prescriptionOrderAddLog(payload)
|
||||
feedback.msgSuccess('日志已添加')
|
||||
addLogVisible.value = false
|
||||
addLogSignature.value = ''
|
||||
await refresh()
|
||||
emit('detail-changed')
|
||||
} catch {
|
||||
@@ -1768,6 +1810,9 @@ function requestDetail(id: number) {
|
||||
}
|
||||
|
||||
async function open(id: number) {
|
||||
if (addLogSaving.value) return
|
||||
addLogVisible.value = false
|
||||
resetAddLogForm()
|
||||
// 页面级同参数字典请求会取消抽屉挂载时的那次(axios 去重取消),打开时兜底重试
|
||||
void loadServicePackageOptions()
|
||||
// 显式彻底清空缓存,防止前一次弹窗的数据残留
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { prescriptionDetail, prescriptionOrderDetail } from '@/api/tcm'
|
||||
|
||||
/**
|
||||
* 查看业务订单处方时,以该订单的新详情为签署事实来源。
|
||||
* 处方接口可能尚未返回签署字段,也可能返回另一笔订单的历史字段,不能据此推断本单审核人。
|
||||
*/
|
||||
export async function loadOrderPrescriptionSlip(orderId: number, prescriptionIdHint?: number) {
|
||||
if (!(orderId > 0)) throw new Error('缺少业务订单信息,请重新打开订单详情')
|
||||
|
||||
async function freshOrder() {
|
||||
const response: any = await prescriptionOrderDetail({ id: orderId })
|
||||
const order = response?.data ?? response
|
||||
if (!order || Number(order.id) !== orderId) throw new Error('业务订单详情不匹配,请重新打开')
|
||||
if (!(Number(order.prescription_id) > 0)) throw new Error('该订单未关联处方')
|
||||
return order as Record<string, any>
|
||||
}
|
||||
|
||||
let prescriptionId = Number(prescriptionIdHint) || 0
|
||||
if (!prescriptionId) prescriptionId = Number((await freshOrder()).prescription_id)
|
||||
// 通常两次请求;若旧页面里的处方关联已改变,则按新关联重取一次。
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
let response: any
|
||||
try {
|
||||
response = await prescriptionDetail({ id: prescriptionId, prescription_order_id: orderId })
|
||||
} catch (error) {
|
||||
// 服务端会拒绝已过期的订单-处方关联,只能使用该订单最新关联重试。
|
||||
const order = await freshOrder()
|
||||
if (Number(order.prescription_id) !== prescriptionId) {
|
||||
prescriptionId = Number(order.prescription_id)
|
||||
continue
|
||||
}
|
||||
throw error
|
||||
}
|
||||
const base = response?.data ?? response
|
||||
if (!base || Number(base.id) !== prescriptionId) throw new Error('处方详情不匹配,请重新打开')
|
||||
// 放在处方请求之后读取,避免慢处方响应将已撤回的审核重新带回预览。
|
||||
const order = await freshOrder()
|
||||
if (Number(order.prescription_id) !== prescriptionId) {
|
||||
prescriptionId = Number(order.prescription_id)
|
||||
continue
|
||||
}
|
||||
const status = Number(order.prescription_audit_status) || 0
|
||||
const signedApproval = status === 1 && ![4, 10].includes(Number(order.fulfillment_status))
|
||||
const signature = signedApproval ? String(order.prescription_audit_signature || '').trim() : ''
|
||||
return {
|
||||
order,
|
||||
prescription: {
|
||||
...base,
|
||||
prescription_order_id: orderId,
|
||||
prescription_audit_status: status,
|
||||
prescription_audit_signature: signature,
|
||||
prescription_audit_signed_name: signature ? String(order.prescription_audit_signed_name || '').trim() : '',
|
||||
prescription_audit_signed_by: signature ? Number(order.prescription_audit_signed_by) || 0 : 0,
|
||||
prescription_audit_signed_at: signature ? order.prescription_audit_signed_at || 0 : 0,
|
||||
business_prescription_audit_rejected: status === 2 ? 1 : 0,
|
||||
business_prescription_audit_remark: String(order.prescription_audit_remark || '')
|
||||
} as Record<string, any>
|
||||
}
|
||||
}
|
||||
throw new Error('订单关联处方正在变更,请稍后重新打开')
|
||||
}
|
||||
@@ -629,7 +629,7 @@
|
||||
@view-prescription="detailData && openPrescriptionView(detailData)"
|
||||
@test-gancao-preview="testGancaoPreviewFromDetail"
|
||||
@view-patient="openDiagnosisPatientDetailFromOrder"
|
||||
@detail-changed="getLists"
|
||||
@detail-changed="onOrderDetailChanged"
|
||||
>
|
||||
<template #header-extra="{ detail }">
|
||||
<div class="flex items-center gap-2 ml-4 shrink-0">
|
||||
@@ -1273,9 +1273,12 @@
|
||||
<el-dialog
|
||||
v-model="auditVisible"
|
||||
:title="auditTitle"
|
||||
width="480px"
|
||||
width="min(480px, 94vw)"
|
||||
destroy-on-close
|
||||
@closed="auditRemark = ''"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!auditSubmitting"
|
||||
:show-close="!auditSubmitting"
|
||||
@closed="resetAuditInput"
|
||||
>
|
||||
<el-alert
|
||||
v-if="auditRowData && auditRowData.completion_request === 1"
|
||||
@@ -1298,11 +1301,16 @@
|
||||
</template>
|
||||
</el-alert>
|
||||
<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="在此输入审核意见..." />
|
||||
<el-input v-model="auditRemark" :disabled="auditSubmitting" type="textarea" :rows="4" maxlength="500" show-word-limit placeholder="在此输入审核意见..." />
|
||||
<div v-if="auditKind === 'prescription'" class="mt-4">
|
||||
<p class="text-sm font-medium mb-2">审核人签名 <span class="text-red-500">*</span></p>
|
||||
<SignaturePad :key="auditSession" v-model="auditSignature" :disabled="auditSubmitting" />
|
||||
<p class="text-xs text-gray-500 mt-2">请本人签名后再通过或驳回,每次审核均需重新签署。</p>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="auditSubmitting" @click="submitAudit('reject')">驳回阻止</el-button>
|
||||
<el-button :disabled="auditSubmitting" @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" :disabled="auditKind === 'prescription' && !auditSignature" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="auditSubmitting" :disabled="auditKind === 'prescription' && !auditSignature" @click="submitAudit('reject')">驳回阻止</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
@@ -1778,6 +1786,7 @@
|
||||
v-model="prescriptionViewVisible"
|
||||
size="920px"
|
||||
:close-on-click-modal="false"
|
||||
@close="resetPrescriptionView"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between w-full pr-2 gap-3">
|
||||
@@ -2062,6 +2071,8 @@ import { computed, onMounted, reactive, ref, nextTick, watch, defineAsyncCompone
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ArrowDown, InfoFilled, QuestionFilled, Search, Calendar, Document, Link as LinkIcon, Wallet } from '@element-plus/icons-vue'
|
||||
import ListTimeFilter from '@/components/list-time-filter/index.vue'
|
||||
import SignaturePad from '@/components/signature-pad/index.vue'
|
||||
import { loadOrderPrescriptionSlip } from './components/order-prescription-slip'
|
||||
import PrescriptionOrderDetailDrawer from './components/PrescriptionOrderDetailDrawer.vue'
|
||||
import PrescriptionOrderTimeDialog from './components/PrescriptionOrderTimeDialog.vue'
|
||||
import GancaoSubmissionReconcileButton from './components/GancaoSubmissionReconcileButton.vue'
|
||||
@@ -2122,7 +2133,6 @@ import {
|
||||
prescriptionOrderLinkPayOrder,
|
||||
prescriptionOrderUploadToPharmacy,
|
||||
prescriptionOrderPreviewGancaoRecipel,
|
||||
prescriptionDetail,
|
||||
prescriptionLibraryLists,
|
||||
getDoctors,
|
||||
getAssistants
|
||||
@@ -3136,6 +3146,11 @@ async function onOrderTimeSaved(id: number) {
|
||||
/** 当前详情数据(组件内部 ref 的桥接;可原地修改属性,整体刷新请用 detailDrawerRef.refresh()) */
|
||||
const detailData = computed(() => (detailDrawerRef.value?.detail ?? null) as Record<string, any> | null)
|
||||
|
||||
async function onOrderDetailChanged() {
|
||||
getLists()
|
||||
if (detailData.value?.id) await refreshOpenPrescriptionView(Number(detailData.value.id))
|
||||
}
|
||||
|
||||
const detailPrescription = computed(() => {
|
||||
const p = detailData.value?.prescription
|
||||
return p && typeof p === 'object' ? p : null
|
||||
@@ -3693,42 +3708,60 @@ const auditKind = ref<'prescription' | 'payment'>('prescription')
|
||||
const auditTargetId = ref(0)
|
||||
const auditRowData = ref<any>(null)
|
||||
const auditRemark = ref('')
|
||||
const auditSignature = ref('')
|
||||
const auditSession = ref(0)
|
||||
const auditSubmitting = ref(false)
|
||||
|
||||
const auditTitle = computed(() =>
|
||||
auditKind.value === 'prescription' ? '处方业务审核' : '关联支付单审核'
|
||||
)
|
||||
|
||||
function resetAuditInput() {
|
||||
if (auditSubmitting.value) return
|
||||
auditRemark.value = ''
|
||||
auditSignature.value = ''
|
||||
auditSession.value++
|
||||
}
|
||||
|
||||
function openAudit(row: { id: number }, kind: 'prescription' | 'payment') {
|
||||
if (auditSubmitting.value || !Number(row.id)) return
|
||||
auditKind.value = kind
|
||||
auditTargetId.value = row.id
|
||||
auditRowData.value = row
|
||||
auditRemark.value = ''
|
||||
resetAuditInput()
|
||||
auditVisible.value = true
|
||||
}
|
||||
|
||||
async function submitAudit(action: 'approve' | 'reject') {
|
||||
if (auditSubmitting.value || !auditVisible.value || !auditTargetId.value) return
|
||||
if (auditKind.value === 'prescription' && !auditSignature.value.trim()) {
|
||||
feedback.msgError('请先手写审核人签名')
|
||||
return
|
||||
}
|
||||
if (action === 'reject' && !auditRemark.value.trim()) {
|
||||
feedback.msgError('驳回或阻止时必须填写明确的审核意见')
|
||||
return
|
||||
}
|
||||
auditSubmitting.value = true
|
||||
const targetId = auditTargetId.value
|
||||
try {
|
||||
const params = {
|
||||
id: auditTargetId.value,
|
||||
id: targetId,
|
||||
action,
|
||||
remark: auditRemark.value.trim()
|
||||
}
|
||||
if (auditKind.value === 'prescription') {
|
||||
await prescriptionOrderAuditPrescription(params)
|
||||
await prescriptionOrderAuditPrescription({ ...params, signature: auditSignature.value })
|
||||
} else {
|
||||
await prescriptionOrderAuditPayment(params)
|
||||
}
|
||||
feedback.msgSuccess(action === 'approve' ? '审核通过成功' : '已成功驳回该单')
|
||||
auditVisible.value = false
|
||||
auditSignature.value = ''
|
||||
getLists()
|
||||
// 若详情 Drawer 正在打开,同步刷新详情数据
|
||||
await detailDrawerRef.value?.refreshIfCurrent(auditTargetId.value)
|
||||
await detailDrawerRef.value?.refreshIfCurrent(targetId)
|
||||
await refreshOpenPrescriptionView(targetId)
|
||||
} catch {
|
||||
/* 拦截器已提示 */
|
||||
} finally {
|
||||
@@ -4508,6 +4541,7 @@ async function confirmRevokeRxAudit(row: { id: number }) {
|
||||
feedback.msgSuccess('处方审核已撤回')
|
||||
getLists()
|
||||
await detailDrawerRef.value?.refreshIfCurrent(row.id)
|
||||
await refreshOpenPrescriptionView(row.id)
|
||||
} catch (e: any) {
|
||||
if (e !== 'cancel' && e !== 'close') {
|
||||
/* 拦截器已提示 */
|
||||
@@ -4544,6 +4578,8 @@ const SLIP_ADDRESS_LINE = '地址:四川省成都市双流区黄甲街道黄
|
||||
const prescriptionViewVisible = ref(false)
|
||||
const prescriptionViewLoading = ref(false)
|
||||
const prescriptionViewData = ref<any>(null)
|
||||
const prescriptionViewOrderId = ref(0)
|
||||
let prescriptionViewRequestId = 0
|
||||
/** 药房联辅方标题:处方库中该辅方模板的 prescription_name(导入或药材匹配解析) */
|
||||
const slipAuxLibraryName = ref('')
|
||||
/** 查看处方联次:药房联 / 处方联 */
|
||||
@@ -4936,21 +4972,35 @@ async function resolveSlipAuxLibraryName(data: Record<string, unknown>): Promise
|
||||
return ''
|
||||
}
|
||||
|
||||
async function openPrescriptionView(row: any) {
|
||||
if (!row.prescription_id) {
|
||||
feedback.msgWarning('该订单未关联处方')
|
||||
function resetPrescriptionView() {
|
||||
prescriptionViewRequestId++
|
||||
prescriptionViewOrderId.value = 0
|
||||
prescriptionViewData.value = null
|
||||
prescriptionViewLoading.value = false
|
||||
}
|
||||
|
||||
async function refreshOpenPrescriptionView(orderId: number) {
|
||||
if (!prescriptionViewVisible.value || prescriptionViewOrderId.value !== Number(orderId)) return
|
||||
await openPrescriptionView({ id: orderId, prescription_id: prescriptionViewData.value?.id }, true)
|
||||
}
|
||||
|
||||
async function openPrescriptionView(orderRow: any, preserveTab = false) {
|
||||
const orderId = Number(orderRow?.id)
|
||||
if (!(orderId > 0)) {
|
||||
feedback.msgWarning('缺少业务订单信息,请重新打开订单详情')
|
||||
return
|
||||
}
|
||||
|
||||
const requestId = ++prescriptionViewRequestId
|
||||
prescriptionViewOrderId.value = orderId
|
||||
prescriptionViewVisible.value = true
|
||||
prescriptionViewLoading.value = true
|
||||
prescriptionViewData.value = null
|
||||
slipAuxLibraryName.value = ''
|
||||
prescriptionTabType.value = 'internal'
|
||||
if (!preserveTab) prescriptionTabType.value = 'internal'
|
||||
|
||||
try {
|
||||
const res: any = await prescriptionDetail({ id: row.prescription_id })
|
||||
const base = res?.data ?? res ?? null
|
||||
const { order: row, prescription: base } = await loadOrderPrescriptionSlip(orderId, Number(orderRow.prescription_id))
|
||||
if (requestId !== prescriptionViewRequestId) return
|
||||
if (base) {
|
||||
const md = row.medication_days
|
||||
const merged: Record<string, unknown> = { ...base }
|
||||
@@ -4980,17 +5030,19 @@ async function openPrescriptionView(row: any) {
|
||||
merged.appointment_id = Number(linkedAp.id)
|
||||
}
|
||||
prescriptionViewData.value = merged
|
||||
slipAuxLibraryName.value = await resolveSlipAuxLibraryName(merged)
|
||||
const auxLibraryName = await resolveSlipAuxLibraryName(merged)
|
||||
if (requestId === prescriptionViewRequestId) slipAuxLibraryName.value = auxLibraryName
|
||||
} else {
|
||||
prescriptionViewData.value = null
|
||||
slipAuxLibraryName.value = ''
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (requestId !== prescriptionViewRequestId) return
|
||||
feedback.msgError(e?.message || '加载处方详情失败')
|
||||
prescriptionViewVisible.value = false
|
||||
slipAuxLibraryName.value = ''
|
||||
} finally {
|
||||
prescriptionViewLoading.value = false
|
||||
if (requestId === prescriptionViewRequestId) prescriptionViewLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1258,6 +1258,14 @@
|
||||
<el-descriptions-item label="处方审核意见" :span="3">
|
||||
<span class="po-audit-remark">{{ detailData.prescription_audit_remark || '—' }}</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item v-if="detailData.prescription_audit_signature" label="审核人签名" :span="3">
|
||||
<AuditSignatureRecord
|
||||
:signature="detailData.prescription_audit_signature"
|
||||
:signed-by="detailData.prescription_audit_signed_by"
|
||||
:signed-name="detailData.prescription_audit_signed_name"
|
||||
:signed-at="detailData.prescription_audit_signed_at"
|
||||
/>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="支付审核意见" :span="3">
|
||||
<span class="po-audit-remark">{{ detailData.payment_slip_audit_remark || '—' }}</span>
|
||||
</el-descriptions-item>
|
||||
@@ -1373,6 +1381,13 @@
|
||||
<el-tag size="small" type="info">{{ logActionText(log.action) }}</el-tag>
|
||||
</div>
|
||||
<span :class="idx === 0 ? 'text-gray-800 font-medium' : 'text-gray-500'">{{ log.summary }}</span>
|
||||
<AuditSignatureRecord
|
||||
v-if="log.audit_signature"
|
||||
:signature="log.audit_signature"
|
||||
:signed-by="log.admin_id"
|
||||
:signed-name="log.admin_name"
|
||||
:signed-at="log.create_time"
|
||||
/>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
<el-empty v-else description="暂无操作日志" :image-size="64" />
|
||||
@@ -1843,7 +1858,10 @@
|
||||
width="92%"
|
||||
destroy-on-close
|
||||
class="po-h5-dialog"
|
||||
@closed="auditRemark = ''"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!auditSubmitting"
|
||||
:show-close="!auditSubmitting"
|
||||
@closed="resetAuditInput"
|
||||
>
|
||||
<el-alert
|
||||
v-if="auditRowData && auditRowData.completion_request === 1"
|
||||
@@ -1866,11 +1884,16 @@
|
||||
</template>
|
||||
</el-alert>
|
||||
<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="在此输入审核意见..." />
|
||||
<el-input v-model="auditRemark" :disabled="auditSubmitting" type="textarea" :rows="4" maxlength="500" show-word-limit placeholder="在此输入审核意见..." />
|
||||
<div v-if="auditKind === 'prescription'" class="mt-4">
|
||||
<p class="text-sm font-medium mb-2">审核人签名 <span class="text-red-500">*</span></p>
|
||||
<SignaturePad :key="auditSession" v-model="auditSignature" :disabled="auditSubmitting" />
|
||||
<p class="text-xs text-gray-500 mt-2">请本人签名后再通过或驳回,每次审核均需重新签署。</p>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="auditSubmitting" @click="submitAudit('reject')">驳回阻止</el-button>
|
||||
<el-button :disabled="auditSubmitting" @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="auditSubmitting" :disabled="auditKind === 'prescription' && !auditSignature" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="auditSubmitting" :disabled="auditKind === 'prescription' && !auditSignature" @click="submitAudit('reject')">驳回阻止</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
@@ -2376,6 +2399,7 @@
|
||||
v-model="prescriptionViewVisible"
|
||||
size="100%"
|
||||
direction="btt"
|
||||
@close="resetPrescriptionView"
|
||||
class="po-h5-drawer"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
@@ -2646,6 +2670,9 @@ import {
|
||||
User
|
||||
} from '@element-plus/icons-vue'
|
||||
import ListTimeFilter from '@/components/list-time-filter/index.vue'
|
||||
import SignaturePad from '@/components/signature-pad/index.vue'
|
||||
import { loadOrderPrescriptionSlip } from './components/order-prescription-slip'
|
||||
import AuditSignatureRecord from './components/AuditSignatureRecord.vue'
|
||||
import PrescriptionOrderTimeDialog from './components/PrescriptionOrderTimeDialog.vue'
|
||||
import GancaoSubmissionReconcileButton from './components/GancaoSubmissionReconcileButton.vue'
|
||||
import { useListTimeFilter } from '@/hooks/useListTimeFilter'
|
||||
@@ -2673,7 +2700,6 @@ import {
|
||||
prescriptionOrderRequestCompletion,
|
||||
prescriptionOrderUploadToPharmacy,
|
||||
prescriptionOrderPreviewGancaoRecipel,
|
||||
prescriptionDetail,
|
||||
getDoctors,
|
||||
getAssistants
|
||||
} from '@/api/tcm'
|
||||
@@ -4658,48 +4684,69 @@ const auditKind = ref<'prescription' | 'payment'>('prescription')
|
||||
const auditTargetId = ref(0)
|
||||
const auditRowData = ref<any>(null)
|
||||
const auditRemark = ref('')
|
||||
const auditSignature = ref('')
|
||||
const auditSession = ref(0)
|
||||
const auditSubmitting = ref(false)
|
||||
|
||||
const auditTitle = computed(() =>
|
||||
auditKind.value === 'prescription' ? '处方业务审核' : '关联支付单审核'
|
||||
)
|
||||
|
||||
function resetAuditInput() {
|
||||
if (auditSubmitting.value) return
|
||||
auditRemark.value = ''
|
||||
auditSignature.value = ''
|
||||
auditSession.value++
|
||||
}
|
||||
|
||||
function openAudit(row: { id: number }, kind: 'prescription' | 'payment') {
|
||||
if (auditSubmitting.value || !Number(row.id)) return
|
||||
auditKind.value = kind
|
||||
auditTargetId.value = row.id
|
||||
auditRowData.value = row
|
||||
auditRemark.value = ''
|
||||
resetAuditInput()
|
||||
auditVisible.value = true
|
||||
}
|
||||
|
||||
async function submitAudit(action: 'approve' | 'reject') {
|
||||
if (auditSubmitting.value || !auditVisible.value || !auditTargetId.value) return
|
||||
if (auditKind.value === 'prescription' && !auditSignature.value.trim()) {
|
||||
feedback.msgError('请先手写审核人签名')
|
||||
return
|
||||
}
|
||||
if (action === 'reject' && !auditRemark.value.trim()) {
|
||||
feedback.msgError('驳回或阻止时必须填写明确的审核意见')
|
||||
return
|
||||
}
|
||||
auditSubmitting.value = true
|
||||
const targetId = auditTargetId.value
|
||||
try {
|
||||
const params = {
|
||||
id: auditTargetId.value,
|
||||
id: targetId,
|
||||
action,
|
||||
remark: auditRemark.value.trim()
|
||||
}
|
||||
if (auditKind.value === 'prescription') {
|
||||
await prescriptionOrderAuditPrescription(params)
|
||||
await prescriptionOrderAuditPrescription({ ...params, signature: auditSignature.value })
|
||||
} else {
|
||||
await prescriptionOrderAuditPayment(params)
|
||||
}
|
||||
feedback.msgSuccess(action === 'approve' ? '审核通过成功' : '已成功驳回该单')
|
||||
auditVisible.value = false
|
||||
auditSignature.value = ''
|
||||
getLists()
|
||||
// 若详情 Drawer 正在打开,同步刷新详情数据
|
||||
if (detailVisible.value && auditTargetId.value) {
|
||||
if (detailVisible.value && Number(detailData.value?.id) === Number(targetId)) {
|
||||
try {
|
||||
const res: any = await prescriptionOrderDetail({ id: auditTargetId.value })
|
||||
const res: any = await prescriptionOrderDetail({ id: targetId })
|
||||
const d = res?.data ?? res ?? null
|
||||
if (d) detailData.value = d
|
||||
if (d && Number(detailData.value?.id) === Number(targetId)) {
|
||||
detailData.value = d
|
||||
await fetchLogs(targetId)
|
||||
}
|
||||
} catch { /* 静默忽略 */ }
|
||||
}
|
||||
await refreshOpenPrescriptionView(targetId)
|
||||
} catch {
|
||||
/* 拦截器已提示 */
|
||||
} finally {
|
||||
@@ -5386,6 +5433,7 @@ async function confirmRevokeRxAudit(row: { id: number }) {
|
||||
if (nd) detailData.value = nd
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
await refreshOpenPrescriptionView(row.id)
|
||||
} catch (e: any) {
|
||||
if (e !== 'cancel' && e !== 'close') {
|
||||
/* 拦截器已提示 */
|
||||
@@ -5428,6 +5476,8 @@ const SLIP_ADDRESS_LINE = '地址:四川省成都市双流区黄甲街道黄
|
||||
const prescriptionViewVisible = ref(false)
|
||||
const prescriptionViewLoading = ref(false)
|
||||
const prescriptionViewData = ref<any>(null)
|
||||
const prescriptionViewOrderId = ref(0)
|
||||
let prescriptionViewRequestId = 0
|
||||
/** 查看处方联次:药房联 / 处方联 */
|
||||
const prescriptionTabType = ref<'internal' | 'user'>('internal')
|
||||
const rxSlipRef = ref<InstanceType<typeof PrescriptionSlip> | null>(null)
|
||||
@@ -5688,20 +5738,34 @@ function openPrescriptionViewFromEdit() {
|
||||
openPrescriptionView(editForm)
|
||||
}
|
||||
|
||||
async function openPrescriptionView(row: any) {
|
||||
if (!row.prescription_id) {
|
||||
feedback.msgWarning('该订单未关联处方')
|
||||
function resetPrescriptionView() {
|
||||
prescriptionViewRequestId++
|
||||
prescriptionViewOrderId.value = 0
|
||||
prescriptionViewData.value = null
|
||||
prescriptionViewLoading.value = false
|
||||
}
|
||||
|
||||
async function refreshOpenPrescriptionView(orderId: number) {
|
||||
if (!prescriptionViewVisible.value || prescriptionViewOrderId.value !== Number(orderId)) return
|
||||
await openPrescriptionView({ id: orderId, prescription_id: prescriptionViewData.value?.id }, true)
|
||||
}
|
||||
|
||||
async function openPrescriptionView(orderRow: any, preserveTab = false) {
|
||||
const orderId = Number(orderRow?.id)
|
||||
if (!(orderId > 0)) {
|
||||
feedback.msgWarning('缺少业务订单信息,请重新打开订单详情')
|
||||
return
|
||||
}
|
||||
|
||||
const requestId = ++prescriptionViewRequestId
|
||||
prescriptionViewOrderId.value = orderId
|
||||
prescriptionViewVisible.value = true
|
||||
prescriptionViewLoading.value = true
|
||||
prescriptionViewData.value = null
|
||||
prescriptionTabType.value = 'internal'
|
||||
if (!preserveTab) prescriptionTabType.value = 'internal'
|
||||
|
||||
try {
|
||||
const res: any = await prescriptionDetail({ id: row.prescription_id })
|
||||
const base = res?.data ?? res ?? null
|
||||
const { order: row, prescription: base } = await loadOrderPrescriptionSlip(orderId, Number(orderRow.prescription_id))
|
||||
if (requestId !== prescriptionViewRequestId) return
|
||||
if (base) {
|
||||
const md = row.medication_days
|
||||
const merged: Record<string, unknown> = { ...base }
|
||||
@@ -5735,10 +5799,11 @@ async function openPrescriptionView(row: any) {
|
||||
prescriptionViewData.value = null
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (requestId !== prescriptionViewRequestId) return
|
||||
feedback.msgError(e?.message || '加载处方详情失败')
|
||||
prescriptionViewVisible.value = false
|
||||
} finally {
|
||||
prescriptionViewLoading.value = false
|
||||
if (requestId === prescriptionViewRequestId) prescriptionViewLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<el-dropdown
|
||||
v-if="myPatientOrderActions(detail).length"
|
||||
trigger="click"
|
||||
@command="(command) => openAction(detail, command as MyPatientOrderAction)"
|
||||
@command="(command: unknown) => openAction(detail, command as MyPatientOrderAction)"
|
||||
>
|
||||
<el-button type="primary" size="small" plain>
|
||||
订单操作<el-icon class="el-icon--right"><ArrowDown /></el-icon>
|
||||
@@ -31,7 +31,17 @@
|
||||
</template>
|
||||
</prescription-order-detail-drawer>
|
||||
|
||||
<el-dialog v-model="auditVisible" :title="auditTitle" width="480px" append-to-body destroy-on-close>
|
||||
<el-dialog
|
||||
v-model="auditVisible"
|
||||
:title="auditTitle"
|
||||
width="min(480px, 94vw)"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!submitting"
|
||||
:show-close="!submitting"
|
||||
@closed="resetAuditInput"
|
||||
>
|
||||
<el-alert
|
||||
title="通过时审核意见可不填;驳回时必须填写明确原因。"
|
||||
type="warning"
|
||||
@@ -41,16 +51,22 @@
|
||||
/>
|
||||
<el-input
|
||||
v-model="auditRemark"
|
||||
:disabled="submitting"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
maxlength="500"
|
||||
show-word-limit
|
||||
placeholder="请输入审核意见"
|
||||
/>
|
||||
<div v-if="auditKind === 'prescription'" class="mt-4">
|
||||
<p class="text-sm font-medium mb-2">审核人签名 <span class="text-red-500">*</span></p>
|
||||
<SignaturePad :key="auditSession" v-model="auditSignature" :disabled="submitting" />
|
||||
<p class="text-xs text-gray-500 mt-2">请本人签名后再通过或驳回,每次审核均需重新签署。</p>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="submitting" @click="submitAudit('reject')">驳回</el-button>
|
||||
<el-button :disabled="submitting" @click="auditVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" :disabled="auditKind === 'prescription' && !auditSignature" @click="submitAudit('approve')">同意通过</el-button>
|
||||
<el-button type="danger" :loading="submitting" :disabled="auditKind === 'prescription' && !auditSignature" @click="submitAudit('reject')">驳回</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
@@ -243,6 +259,7 @@ import { computed, reactive, ref } from 'vue'
|
||||
import { ArrowDown } from '@element-plus/icons-vue'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import feedback from '@/utils/feedback'
|
||||
import SignaturePad from '@/components/signature-pad/index.vue'
|
||||
import PrescriptionOrderDetailDrawer from '@/views/consumer/prescription/components/PrescriptionOrderDetailDrawer.vue'
|
||||
import {
|
||||
myPatientOrderAddPayOrder,
|
||||
@@ -299,6 +316,8 @@ const completeOptions = [
|
||||
const auditVisible = ref(false)
|
||||
const auditKind = ref<'prescription' | 'payment'>('prescription')
|
||||
const auditRemark = ref('')
|
||||
const auditSignature = ref('')
|
||||
const auditSession = ref(0)
|
||||
const auditTitle = computed(() => auditKind.value === 'prescription' ? '处方业务审核' : '关联支付单审核')
|
||||
|
||||
const trackVisible = ref(false)
|
||||
@@ -386,7 +405,15 @@ async function openEdit(row: Record<string, any>) {
|
||||
}
|
||||
}
|
||||
|
||||
function resetAuditInput() {
|
||||
if (submitting.value) return
|
||||
auditRemark.value = ''
|
||||
auditSignature.value = ''
|
||||
auditSession.value++
|
||||
}
|
||||
|
||||
function openAction(row: Record<string, any>, action: MyPatientOrderAction) {
|
||||
if (submitting.value) return
|
||||
actionRow.value = row
|
||||
switch (action) {
|
||||
case 'edit':
|
||||
@@ -395,7 +422,7 @@ function openAction(row: Record<string, any>, action: MyPatientOrderAction) {
|
||||
case 'audit_prescription':
|
||||
case 'audit_payment':
|
||||
auditKind.value = action === 'audit_prescription' ? 'prescription' : 'payment'
|
||||
auditRemark.value = ''
|
||||
resetAuditInput()
|
||||
auditVisible.value = true
|
||||
break
|
||||
case 'revoke_rx_audit':
|
||||
@@ -443,24 +470,31 @@ function openAction(row: Record<string, any>, action: MyPatientOrderAction) {
|
||||
}
|
||||
}
|
||||
|
||||
async function changed(message: string) {
|
||||
async function changed(message: string, orderId = Number(actionRow.value.id)) {
|
||||
feedback.msgSuccess(message)
|
||||
emit('changed')
|
||||
await detailDrawerRef.value?.refreshIfCurrent(actionRow.value.id)
|
||||
await detailDrawerRef.value?.refreshIfCurrent(orderId)
|
||||
}
|
||||
|
||||
async function submitAudit(action: 'approve' | 'reject') {
|
||||
if (submitting.value || !auditVisible.value || !Number(actionRow.value.id)) return
|
||||
if (auditKind.value === 'prescription' && !auditSignature.value.trim()) {
|
||||
feedback.msgError('请先手写审核人签名')
|
||||
return
|
||||
}
|
||||
if (action === 'reject' && !auditRemark.value.trim()) {
|
||||
feedback.msgError('驳回时必须填写审核意见')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
const targetId = Number(actionRow.value.id)
|
||||
try {
|
||||
const params = { id: Number(actionRow.value.id), action, remark: auditRemark.value.trim() }
|
||||
if (auditKind.value === 'prescription') await myPatientOrderAuditPrescription(params)
|
||||
const params = { id: targetId, action, remark: auditRemark.value.trim() }
|
||||
if (auditKind.value === 'prescription') await myPatientOrderAuditPrescription({ ...params, signature: auditSignature.value })
|
||||
else await myPatientOrderAuditPayment(params)
|
||||
auditVisible.value = false
|
||||
await changed(action === 'approve' ? '审核通过成功' : '订单已驳回')
|
||||
auditSignature.value = ''
|
||||
await changed(action === 'approve' ? '审核通过成功' : '订单已驳回', targetId)
|
||||
} catch {
|
||||
// 请求拦截器已提示
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const test = require('node:test')
|
||||
const ts = require('typescript')
|
||||
const vue = require('vue')
|
||||
const { renderToString } = require('@vue/server-renderer')
|
||||
const { parse, compileScript, compileTemplate } = require('@vue/compiler-sfc')
|
||||
|
||||
const root = path.resolve(__dirname, '../src')
|
||||
const signature = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIHWP4z8DwHwAFgAI/ScLbtAAAAABJRU5ErkJggg=='
|
||||
const oldSignature = 'data:image/png;base64,old-order-signature'
|
||||
const signedOrder = () => ({
|
||||
id: 42, prescription_id: 8, fulfillment_status: 1, prescription_audit_status: 1,
|
||||
prescription_audit_signature: signature, prescription_audit_signed_name: '本单药师',
|
||||
prescription_audit_signed_by: 7, prescription_audit_signed_at: 1794553200
|
||||
})
|
||||
const basePrescription = () => ({ id: 8, doctor_name: '开方医师', patient_name: '张某', herbs: [], prescription_type: '饮片' })
|
||||
const deferred = () => {
|
||||
let resolve
|
||||
const promise = new Promise(yes => { resolve = yes })
|
||||
return { promise, resolve }
|
||||
}
|
||||
|
||||
function loadModule(source, imports) {
|
||||
const output = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS, esModuleInterop: true } }).outputText
|
||||
const module = { exports: {} }
|
||||
new Function('require', 'module', 'exports', output)(imports, module, module.exports)
|
||||
return module.exports
|
||||
}
|
||||
|
||||
const utils = loadModule(fs.readFileSync(path.join(root, 'components/prescription-slip/utils.ts'), 'utf8'), () => { throw new Error('unexpected dependency') })
|
||||
const slipFile = path.join(root, 'components/prescription-slip/index.vue')
|
||||
const slipDescriptor = parse(fs.readFileSync(slipFile, 'utf8'), { filename: slipFile }).descriptor
|
||||
const slipScript = compileScript(slipDescriptor, { id: 'signature-slip-render', inlineTemplate: true })
|
||||
const Slip = loadModule(slipScript.content, name => {
|
||||
if (name === 'vue') return vue
|
||||
if (name === './utils') return utils
|
||||
throw new Error(`unexpected dependency: ${name}`)
|
||||
}).default
|
||||
|
||||
async function renderedSlip(data, variant) {
|
||||
// 真正执行 PrescriptionSlip.vue 的编译 render;两个联次均使用该 DOM 导出图片/PDF。
|
||||
return renderToString(vue.createSSRApp({ render: () => vue.h(Slip, { data, variant }) }))
|
||||
}
|
||||
|
||||
function preview(page, options = {}) {
|
||||
const calls = [], errors = []
|
||||
let order = options.order ?? signedOrder()
|
||||
let prescription = options.prescription ?? basePrescription()
|
||||
const request = {
|
||||
async get({ url, params }) {
|
||||
calls.push({ url, params })
|
||||
if (url === '/tcm.prescription/detail') return typeof prescription === 'function' ? prescription(params) : { data: prescription }
|
||||
if (url === '/tcm.prescriptionOrder/detail') return typeof order === 'function' ? order(params) : { data: order }
|
||||
throw new Error(`Unexpected URL ${url}`)
|
||||
},
|
||||
async post({ url, params }) {
|
||||
calls.push({ url, params })
|
||||
if (url === '/tcm.prescriptionOrder/auditPrescription') {
|
||||
order = { ...signedOrder(), prescription_audit_status: params.action === 'approve' ? 1 : 2, prescription_audit_signature: params.signature }
|
||||
return {}
|
||||
}
|
||||
if (url === '/tcm.prescriptionOrder/revokeRxAudit') {
|
||||
order = { ...signedOrder(), prescription_audit_status: 0, prescription_audit_signature: '', prescription_audit_signed_name: '' }
|
||||
return {}
|
||||
}
|
||||
throw new Error(`Unexpected URL ${url}`)
|
||||
}
|
||||
}
|
||||
// 使用真实 API functions 和真实共享 loader,只有最底层网络 transport 被替换。
|
||||
const api = loadModule(fs.readFileSync(path.join(root, 'api/tcm.ts'), 'utf8'), name => {
|
||||
assert.equal(name, '@/utils/request')
|
||||
return request
|
||||
})
|
||||
const loader = loadModule(fs.readFileSync(path.join(root, 'views/consumer/prescription/components/order-prescription-slip.ts'), 'utf8'), name => {
|
||||
assert.equal(name, '@/api/tcm')
|
||||
return api
|
||||
})
|
||||
const filename = path.join(root, 'views/consumer/prescription', page)
|
||||
const { descriptor, errors: parseErrors } = parse(fs.readFileSync(filename, 'utf8'), { filename })
|
||||
assert.deepEqual(parseErrors, [])
|
||||
const script = compileScript(descriptor, { id: page })
|
||||
const template = compileTemplate({ source: descriptor.template.content, filename, id: page, compilerOptions: { bindingMetadata: script.bindings } })
|
||||
assert.deepEqual(template.errors, [])
|
||||
const ast = ts.createSourceFile(filename + '.ts', descriptor.scriptSetup.content, ts.ScriptTarget.Latest, true)
|
||||
const declarations = new Map()
|
||||
for (const node of ast.statements) {
|
||||
if (ts.isFunctionDeclaration(node) && node.name) declarations.set(node.name.text, node.getText(ast))
|
||||
if (ts.isVariableStatement(node)) {
|
||||
for (const declaration of node.declarationList.declarations) declarations.set(declaration.name.getText(ast), `${node.declarationList.flags & ts.NodeFlags.Const ? 'const' : 'let'} ${declaration.getText(ast)}`)
|
||||
}
|
||||
}
|
||||
const names = [
|
||||
'prescriptionViewVisible', 'prescriptionViewLoading', 'prescriptionViewData', 'prescriptionViewOrderId', 'prescriptionViewRequestId',
|
||||
'prescriptionTabType', 'openPrescriptionView', 'resetPrescriptionView', 'refreshOpenPrescriptionView',
|
||||
'auditVisible', 'auditKind', 'auditTargetId', 'auditRowData', 'auditRemark', 'auditSignature', 'auditSession', 'auditSubmitting',
|
||||
'openAudit', 'resetAuditInput', 'submitAudit', 'confirmRevokeRxAudit'
|
||||
]
|
||||
const globals = {
|
||||
ref: vue.ref, ...loader,
|
||||
prescriptionOrderAuditPrescription: api.prescriptionOrderAuditPrescription,
|
||||
prescriptionOrderAuditPayment: api.prescriptionOrderAuditPayment,
|
||||
prescriptionOrderRevokeRxAudit: api.prescriptionOrderRevokeRxAudit,
|
||||
prescriptionOrderDetail: api.prescriptionOrderDetail,
|
||||
detailDrawerRef: vue.ref({ refreshIfCurrent: async () => {} }),
|
||||
// 父详情/列表故意保持旧快照,验证预览不从它恢复签名。
|
||||
detailData: vue.ref({ id: 42, prescription_id: 8, prescription_audit_status: 0 }), detailVisible: vue.ref(false),
|
||||
slipAuxLibraryName: vue.ref(''), resolveSlipAuxLibraryName: async () => '',
|
||||
ElMessageBox: { confirm: async () => {} }, getLists() {}, fetchLogs: async () => {},
|
||||
feedback: { msgWarning: message => errors.push(message), msgError: message => errors.push(message), msgSuccess() {} }
|
||||
}
|
||||
for (const name of names) assert.ok(declarations.has(name), `${page}: missing ${name}`)
|
||||
const output = ts.transpileModule(names.map(name => declarations.get(name)).join('\n'), { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS } }).outputText
|
||||
const state = new Function(...Object.keys(globals), `${output}\nreturn { ${names.join(', ')} }`)(...Object.values(globals))
|
||||
return { state, calls, errors, setOrder: value => { order = value }, setPrescription: value => { prescription = value } }
|
||||
}
|
||||
|
||||
for (const page of ['order_list.vue', 'order_list_h5.vue']) {
|
||||
test(`${page}: real API -> preview -> both rendered slips show order signature when prescription response has no audit fields`, async () => {
|
||||
const { state, calls } = preview(page)
|
||||
await state.openPrescriptionView({ id: 42, prescription_id: 8, prescription_audit_status: 0 })
|
||||
assert.deepEqual(calls, [
|
||||
{ url: '/tcm.prescription/detail', params: { id: 8, prescription_order_id: 42 } },
|
||||
{ url: '/tcm.prescriptionOrder/detail', params: { id: 42 } }
|
||||
])
|
||||
for (const variant of ['internal', 'user']) {
|
||||
const html = await renderedSlip(state.prescriptionViewData.value, variant)
|
||||
assert.match(html, /<img[^>]*alt="药师签名"/)
|
||||
assert.ok(html.includes(`src="${signature}"`))
|
||||
assert.equal(html.includes('本单药师'), false)
|
||||
assert.ok(html.indexOf('开方医师') < html.indexOf('药师签名'))
|
||||
}
|
||||
})
|
||||
|
||||
test(`${page}: fresh order replaces missing or wrong signature fields from prescription and list snapshots`, async () => {
|
||||
const stale = { ...basePrescription(), prescription_audit_status: 1, prescription_audit_signature: oldSignature, prescription_audit_signed_name: '别单旧药师', prescription_audit_signed_by: 99 }
|
||||
const { state } = preview(page, { prescription: stale })
|
||||
await state.openPrescriptionView({ ...stale, id: 42, prescription_id: 8 })
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signature, signature)
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signed_by, 7)
|
||||
const html = await renderedSlip(state.prescriptionViewData.value, 'internal')
|
||||
assert.equal(html.includes('本单药师'), false)
|
||||
assert.equal(html.includes('别单旧药师'), false)
|
||||
assert.equal(html.includes(oldSignature), false)
|
||||
})
|
||||
|
||||
test(`${page}: pending, rejected, cancelled and refunded fresh orders remove stale pharmacist images from both slips`, async () => {
|
||||
const stale = { ...basePrescription(), ...signedOrder(), id: 8 }
|
||||
for (const order of [
|
||||
{ ...signedOrder(), prescription_audit_status: 0 },
|
||||
{ ...signedOrder(), prescription_audit_status: 2 },
|
||||
{ ...signedOrder(), fulfillment_status: 4 },
|
||||
{ ...signedOrder(), fulfillment_status: 10 },
|
||||
{ ...signedOrder(), prescription_audit_signature: '' }
|
||||
]) {
|
||||
const { state } = preview(page, { order, prescription: stale })
|
||||
await state.openPrescriptionView({ ...signedOrder(), prescription_id: 8 })
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signature, '')
|
||||
for (const variant of ['internal', 'user']) {
|
||||
const html = await renderedSlip(state.prescriptionViewData.value, variant)
|
||||
assert.equal(html.includes('alt="药师签名"'), false)
|
||||
assert.equal(html.includes('本单药师'), false)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test(`${page}: completing an audit and revoking it refresh an already-open prescription preview`, async () => {
|
||||
const { state, setPrescription } = preview(page, { order: { ...signedOrder(), prescription_audit_status: 0, prescription_audit_signature: '' } })
|
||||
await state.openPrescriptionView({ id: 42, prescription_id: 8 })
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signature, '')
|
||||
state.prescriptionTabType.value = 'user'
|
||||
state.openAudit({ id: 42 }, 'prescription')
|
||||
state.auditSignature.value = signature
|
||||
await state.submitAudit('approve')
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signature, signature)
|
||||
assert.equal(state.prescriptionTabType.value, 'user')
|
||||
assert.match(await renderedSlip(state.prescriptionViewData.value, 'user'), /<img[^>]*alt="药师签名"/)
|
||||
setPrescription({ ...basePrescription(), ...signedOrder(), id: 8 })
|
||||
await state.confirmRevokeRxAudit({ id: 42 })
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signature, '')
|
||||
assert.equal((await renderedSlip(state.prescriptionViewData.value, 'user')).includes('alt="药师签名"'), false)
|
||||
})
|
||||
|
||||
test(`${page}: another order's detail and failed detail loads cannot borrow a cached signature`, async () => {
|
||||
for (const order of [{ ...signedOrder(), id: 99 }, async () => { throw new Error('订单加载失败') }]) {
|
||||
const { state, errors } = preview(page, { order, prescription: { ...basePrescription(), ...signedOrder(), id: 8 } })
|
||||
state.prescriptionViewData.value = { ...basePrescription(), ...signedOrder(), id: 8 }
|
||||
await state.openPrescriptionView({ id: 42, prescription_id: 8 })
|
||||
assert.equal(state.prescriptionViewData.value, null)
|
||||
assert.equal(state.prescriptionViewVisible.value, false)
|
||||
assert.equal(errors.length, 1)
|
||||
}
|
||||
})
|
||||
|
||||
test(`${page}: a slower previous order response cannot overwrite the newly opened or closed preview`, async () => {
|
||||
const slow = deferred()
|
||||
const { state } = preview(page, {
|
||||
prescription: params => params.id === 8 ? slow.promise : { ...basePrescription(), id: params.id },
|
||||
order: params => ({ ...signedOrder(), id: params.id, prescription_id: params.id === 42 ? 8 : 9, prescription_audit_signed_name: `药师${params.id}` })
|
||||
})
|
||||
const first = state.openPrescriptionView({ id: 42, prescription_id: 8 })
|
||||
await state.openPrescriptionView({ id: 43, prescription_id: 9 })
|
||||
slow.resolve(basePrescription())
|
||||
await first
|
||||
assert.equal(state.prescriptionViewData.value.prescription_order_id, 43)
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signed_name, '药师43')
|
||||
const pending = state.openPrescriptionView({ id: 43, prescription_id: 9 })
|
||||
state.resetPrescriptionView()
|
||||
await pending
|
||||
assert.equal(state.prescriptionViewData.value, null)
|
||||
})
|
||||
|
||||
test(`${page}: changed prescription association reloads the actual current prescription`, async () => {
|
||||
const { state, calls } = preview(page, {
|
||||
order: { ...signedOrder(), prescription_id: 9 },
|
||||
prescription: params => {
|
||||
if (params.id === 8) throw new Error('处方与订单关联不匹配')
|
||||
return { ...basePrescription(), id: params.id }
|
||||
}
|
||||
})
|
||||
await state.openPrescriptionView({ id: 42, prescription_id: 8 })
|
||||
assert.equal(state.prescriptionViewData.value.id, 9)
|
||||
assert.equal(state.prescriptionViewData.value.prescription_audit_signature, signature)
|
||||
assert.deepEqual(calls.filter(call => call.url === '/tcm.prescription/detail').map(call => call.params.id), [8, 9])
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const test = require('node:test')
|
||||
const ts = require('typescript')
|
||||
const vue = require('vue')
|
||||
const { parse, compileScript, compileTemplate } = require('@vue/compiler-sfc')
|
||||
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const signature = 'data:image/png;base64,c2lnbmF0dXJl'
|
||||
const deferred = () => {
|
||||
let resolve, reject
|
||||
const promise = new Promise((yes, no) => { resolve = yes; reject = no })
|
||||
return { promise, resolve, reject }
|
||||
}
|
||||
|
||||
function component(relative) {
|
||||
const filename = path.join(root, 'src', relative)
|
||||
const { descriptor, errors } = parse(fs.readFileSync(filename, 'utf8'), { filename })
|
||||
assert.deepEqual(errors, [])
|
||||
const script = compileScript(descriptor, { id: relative })
|
||||
const template = compileTemplate({ source: descriptor.template.content, filename, id: relative, compilerOptions: { bindingMetadata: script.bindings } })
|
||||
assert.deepEqual(template.errors, [])
|
||||
return { filename, descriptor, script }
|
||||
}
|
||||
|
||||
function handlers(relative, names, globals, watches = '') {
|
||||
const { filename, descriptor } = component(relative)
|
||||
const ast = ts.createSourceFile(filename + '.ts', descriptor.scriptSetup.content, ts.ScriptTarget.Latest, true)
|
||||
const declarations = new Map()
|
||||
for (const node of ast.statements) {
|
||||
if (ts.isFunctionDeclaration(node) && node.name) declarations.set(node.name.text, node.getText(ast))
|
||||
if (ts.isVariableStatement(node)) {
|
||||
for (const declaration of node.declarationList.declarations) declarations.set(declaration.name.getText(ast), `${node.declarationList.flags & ts.NodeFlags.Const ? 'const' : 'let'} ${declaration.getText(ast)}`)
|
||||
}
|
||||
}
|
||||
for (const name of names) assert.ok(declarations.has(name), `${relative}: missing ${name}`)
|
||||
const expressions = watches ? ast.statements.filter(node => ts.isExpressionStatement(node) && node.getText(ast).startsWith('watch(') && node.getText(ast).includes(watches)).map(node => node.getText(ast)) : []
|
||||
const compiled = ts.transpileModule([...names.map(name => declarations.get(name)), ...expressions].join('\n'), { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS } }).outputText
|
||||
return new Function(...Object.keys(globals), `${compiled}\nreturn { ${names.join(', ')} }`)(...Object.values(globals))
|
||||
}
|
||||
|
||||
for (const page of ['views/consumer/prescription/order_list.vue', 'views/consumer/prescription/order_list_h5.vue', 'views/first_visit/my_patients/components/OrderActionHost.vue']) {
|
||||
const host = page.includes('OrderActionHost')
|
||||
function setup(save = async () => {}) {
|
||||
const calls = [], errors = [], refreshed = []
|
||||
const names = ['auditVisible', 'auditKind', 'auditRemark', 'auditSignature', 'auditSession', 'resetAuditInput', 'submitAudit']
|
||||
names.push(...(host ? ['actionRow', 'submitting', 'openAction', 'changed'] : ['auditTargetId', 'auditRowData', 'auditSubmitting', 'openAudit']))
|
||||
const rx = async payload => { calls.push(['rx', payload]); await save(payload) }
|
||||
const pay = async payload => { calls.push(['pay', payload]); await save(payload) }
|
||||
const state = handlers(page, names, {
|
||||
ref: vue.ref,
|
||||
feedback: { msgError: message => errors.push(message), msgSuccess() {} },
|
||||
prescriptionOrderAuditPrescription: rx, prescriptionOrderAuditPayment: pay,
|
||||
myPatientOrderAuditPrescription: rx, myPatientOrderAuditPayment: pay,
|
||||
detailDrawerRef: vue.ref({ refreshIfCurrent: async id => refreshed.push(id) }),
|
||||
detailVisible: vue.ref(false), detailData: vue.ref(null), getLists() {}, emit() {}, refreshOpenPrescriptionView: async () => {}
|
||||
})
|
||||
const open = (id = 42, kind = 'prescription') => host ? state.openAction({ id }, `audit_${kind}`) : state.openAudit({ id }, kind)
|
||||
return { state, calls, errors, refreshed, open }
|
||||
}
|
||||
|
||||
test(`${page}: blank signature blocks approve and reject even via direct handler`, async () => {
|
||||
const { state, calls, open } = setup()
|
||||
open()
|
||||
state.auditRemark.value = '原因'
|
||||
for (const blank of ['', ' ']) {
|
||||
state.auditSignature.value = blank
|
||||
await state.submitAudit('approve')
|
||||
await state.submitAudit('reject')
|
||||
}
|
||||
assert.deepEqual(calls, [])
|
||||
assert.equal(state.auditVisible.value, true)
|
||||
})
|
||||
|
||||
test(`${page}: both audit results carry a fresh signature; reject still needs a reason`, async () => {
|
||||
const { state, calls, refreshed, open } = setup()
|
||||
open()
|
||||
state.auditSignature.value = signature
|
||||
await state.submitAudit('reject')
|
||||
assert.deepEqual(calls, [])
|
||||
state.auditRemark.value = ' 需重新核对 '
|
||||
await state.submitAudit('reject')
|
||||
assert.deepEqual(calls[0], ['rx', { id: 42, action: 'reject', remark: '需重新核对', signature }])
|
||||
assert.equal(state.auditSignature.value, '')
|
||||
open(43)
|
||||
assert.equal(state.auditSignature.value, '')
|
||||
state.auditSignature.value = signature
|
||||
await state.submitAudit('approve')
|
||||
assert.deepEqual(calls[1], ['rx', { id: 43, action: 'approve', remark: '', signature }])
|
||||
if (!page.includes('h5')) assert.deepEqual(refreshed, [42, 43])
|
||||
})
|
||||
|
||||
test(`${page}: payment auditing neither requires nor sends a signature`, async () => {
|
||||
const { state, calls, open } = setup()
|
||||
open(4, 'payment')
|
||||
state.auditSignature.value = signature
|
||||
await state.submitAudit('approve')
|
||||
open(5, 'payment')
|
||||
state.auditRemark.value = '支付信息不符'
|
||||
await state.submitAudit('reject')
|
||||
assert.deepEqual(calls, [
|
||||
['pay', { id: 4, action: 'approve', remark: '' }],
|
||||
['pay', { id: 5, action: 'reject', remark: '支付信息不符' }]
|
||||
])
|
||||
})
|
||||
|
||||
test(`${page}: closing, reopening and switching orders discard the prior signature`, () => {
|
||||
const { state, open } = setup()
|
||||
open()
|
||||
state.auditSignature.value = signature
|
||||
const firstSession = state.auditSession.value
|
||||
open(43)
|
||||
assert.equal(state.auditSignature.value, '')
|
||||
assert.ok(state.auditSession.value > firstSession)
|
||||
state.auditSignature.value = signature
|
||||
state.auditVisible.value = false
|
||||
state.resetAuditInput()
|
||||
assert.equal(state.auditSignature.value, '')
|
||||
open(42)
|
||||
assert.equal(state.auditSignature.value, '')
|
||||
})
|
||||
|
||||
test(`${page}: a pending audit cannot duplicate or change target; failure retains the signature`, async () => {
|
||||
const saving = deferred()
|
||||
const { state, calls, open } = setup(() => saving.promise)
|
||||
open()
|
||||
state.auditSignature.value = signature
|
||||
const submission = state.submitAudit('approve')
|
||||
await state.submitAudit('approve')
|
||||
open(99, 'payment')
|
||||
state.resetAuditInput()
|
||||
assert.equal(calls.length, 1)
|
||||
assert.equal(state.auditKind.value, 'prescription')
|
||||
assert.equal(host ? state.actionRow.value.id : state.auditTargetId.value, 42)
|
||||
saving.reject(new Error('network'))
|
||||
await submission
|
||||
assert.equal(state.auditSignature.value, signature)
|
||||
assert.equal(state.auditVisible.value, true)
|
||||
assert.equal(host ? state.submitting.value : state.auditSubmitting.value, false)
|
||||
})
|
||||
}
|
||||
|
||||
function logSetup(save = async () => {}) {
|
||||
const calls = [], errors = []
|
||||
const state = handlers('views/consumer/prescription/components/PrescriptionOrderDetailDrawer.vue', [
|
||||
'addLogVisible', 'addLogSaving', 'addLogFormRef', 'addLogSignature', 'addLogSession', 'addLogForm',
|
||||
'requiresAddLogSignature', 'resetAddLogForm', 'openAddLogDialog', 'submitAddLog'
|
||||
], {
|
||||
ref: vue.ref, reactive: vue.reactive, computed: vue.computed, watch: vue.watch,
|
||||
detailData: vue.ref({ id: 42, prescription_audit_status: 1, prescription_audit_signature: signature }),
|
||||
canSetRxAuditOnAddLog: vue.ref(true), canSetPayAuditOnAddLog: vue.ref(true),
|
||||
feedback: { msgError: message => errors.push(message), msgSuccess() {} },
|
||||
prescriptionOrderAddLog: async payload => { calls.push(payload); await save() },
|
||||
refresh: async () => {}, emit() {}
|
||||
}, 'addLogForm.prescription_audit_status')
|
||||
state.addLogFormRef.value = { validate: async () => true, clearValidate() {} }
|
||||
state.openAddLogDialog()
|
||||
state.addLogForm.summary = '补充说明'
|
||||
return { state, calls, errors }
|
||||
}
|
||||
|
||||
test('manual log explicitly setting either terminal status requires a new signature, including unchanged approval', async () => {
|
||||
for (const status of [1, 2]) {
|
||||
const { state, calls } = logSetup()
|
||||
state.addLogForm.prescription_audit_status = status
|
||||
await vue.nextTick()
|
||||
await state.submitAddLog()
|
||||
assert.deepEqual(calls, [])
|
||||
state.addLogSignature.value = signature
|
||||
await state.submitAddLog()
|
||||
assert.equal(calls[0].signature, signature)
|
||||
assert.equal(calls[0].prescription_audit_status, status)
|
||||
}
|
||||
})
|
||||
|
||||
test('plain logs, payment-only changes and reset to pending do not require or send signatures', async () => {
|
||||
for (const status of ['', 0]) {
|
||||
const { state, calls } = logSetup()
|
||||
state.addLogForm.prescription_audit_status = status
|
||||
state.addLogForm.payment_slip_audit_status = 1
|
||||
await state.submitAddLog()
|
||||
assert.equal(calls.length, 1)
|
||||
assert.equal('signature' in calls[0], false)
|
||||
}
|
||||
})
|
||||
|
||||
test('manual log cannot reuse a signature after status change or reopen; failed saves retain it', async () => {
|
||||
const { state, calls } = logSetup(async () => { throw new Error('network') })
|
||||
state.addLogForm.prescription_audit_status = 1
|
||||
await vue.nextTick()
|
||||
state.addLogSignature.value = signature
|
||||
state.addLogForm.prescription_audit_status = 2
|
||||
await vue.nextTick()
|
||||
assert.equal(state.addLogSignature.value, '')
|
||||
state.addLogSignature.value = signature
|
||||
await state.submitAddLog()
|
||||
assert.equal(calls.length, 1)
|
||||
assert.equal(state.addLogSignature.value, signature)
|
||||
assert.equal(state.addLogVisible.value, true)
|
||||
state.openAddLogDialog()
|
||||
assert.equal(state.addLogSignature.value, '')
|
||||
})
|
||||
|
||||
test('manual log locks submission before async form validation, preventing duplicates', async () => {
|
||||
const validation = deferred()
|
||||
const { state, calls } = logSetup()
|
||||
state.addLogFormRef.value.validate = () => validation.promise
|
||||
const submit = state.submitAddLog()
|
||||
await state.submitAddLog()
|
||||
state.openAddLogDialog()
|
||||
assert.equal(state.addLogSaving.value, true)
|
||||
validation.resolve(true)
|
||||
await submit
|
||||
assert.equal(calls.length, 1)
|
||||
})
|
||||
|
||||
function loadModule(source, imports, globals = {}) {
|
||||
const compiled = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS, esModuleInterop: true } }).outputText
|
||||
const module = { exports: {} }
|
||||
new Function('require', 'module', 'exports', ...Object.keys(globals), compiled)(imports, module, module.exports, ...Object.values(globals))
|
||||
return module.exports
|
||||
}
|
||||
|
||||
function padSetup() {
|
||||
const { script } = component('components/signature-pad/index.vue')
|
||||
const mounted = [], output = [], paths = []
|
||||
let observer
|
||||
const props = vue.reactive({ modelValue: '', disabled: false })
|
||||
const componentModule = loadModule(script.content, name => {
|
||||
assert.equal(name, 'vue')
|
||||
return { ...vue, onMounted: fn => mounted.push(fn), onBeforeUnmount() {} }
|
||||
}, { window: { devicePixelRatio: 2 }, ResizeObserver: class { constructor(fn) { observer = fn } observe() {} disconnect() {} } })
|
||||
const state = componentModule.default.setup(props, { expose() {}, emit(_event, value) { props.modelValue = value; output.push(value) } })
|
||||
let width = 400
|
||||
const captures = new Set()
|
||||
const context = { beginPath() {}, moveTo(x, y) { paths.push(['move', x, y]) }, lineTo(x, y) { paths.push(['line', x, y]) }, stroke() {}, setTransform(...values) { paths.push(['transform', ...values]) }, fillRect() {} }
|
||||
const canvas = {
|
||||
getBoundingClientRect: () => ({ left: 10, top: 20, width, height: 168 }),
|
||||
getContext: () => context, toDataURL: () => signature,
|
||||
setPointerCapture: id => captures.add(id), hasPointerCapture: id => captures.has(id), releasePointerCapture: id => captures.delete(id)
|
||||
}
|
||||
state.canvasRef.value = canvas
|
||||
mounted.forEach(fn => fn())
|
||||
const point = (x, y, extra = {}) => ({ pointerId: 1, pointerType: 'touch', button: 0, clientX: x + 10, clientY: y + 20, ...extra })
|
||||
const draw = () => { state.onPointerDown(point(20, 30)); state.onPointerMove(point(80, 60)); state.onPointerUp(point(100, 70)) }
|
||||
return { state, props, output, paths, canvas, point, draw, resize: newWidth => { width = newWidth; observer() } }
|
||||
}
|
||||
|
||||
test('signature pad rejects blank clicks and tiny motion, then emits only completed ink', async () => {
|
||||
const { state, props, point, draw } = padSetup()
|
||||
state.onPointerDown(point(20, 20))
|
||||
state.onPointerUp(point(20, 20))
|
||||
assert.equal(props.modelValue, '')
|
||||
state.onPointerDown(point(20, 20))
|
||||
state.onPointerMove(point(21, 21))
|
||||
state.onPointerUp(point(21, 21))
|
||||
assert.equal(props.modelValue, '')
|
||||
draw()
|
||||
await vue.nextTick()
|
||||
assert.equal(props.modelValue, signature)
|
||||
state.clearSignature()
|
||||
await vue.nextTick()
|
||||
assert.equal(props.modelValue, '')
|
||||
state.onPointerDown(point(20, 20))
|
||||
state.onPointerUp(point(20, 20))
|
||||
assert.equal(props.modelValue, '')
|
||||
})
|
||||
|
||||
test('signature pad ignores secondary pointers, cancels interrupted ink and respects disabled state', () => {
|
||||
const { state, props, point, draw } = padSetup()
|
||||
state.onPointerDown(point(20, 20))
|
||||
state.onPointerMove(point(100, 100, { pointerId: 2 }))
|
||||
state.onPointerUp(point(100, 100, { pointerId: 2 }))
|
||||
state.onPointerCancel(point(20, 20))
|
||||
assert.equal(props.modelValue, '')
|
||||
draw()
|
||||
props.disabled = true
|
||||
state.clearSignature()
|
||||
state.onPointerDown(point(20, 20))
|
||||
assert.equal(props.modelValue, signature)
|
||||
assert.equal(state.drawing.value, false)
|
||||
})
|
||||
|
||||
test('signature pad maps CSS coordinates once at high DPR and preserves strokes on resize', () => {
|
||||
const { canvas, paths, draw, resize, props } = padSetup()
|
||||
draw()
|
||||
assert.equal(canvas.width, 800)
|
||||
assert.equal(canvas.height, 336)
|
||||
assert.ok(paths.some(parts => parts[0] === 'line' && parts[1] === 80 && parts[2] === 60))
|
||||
resize(200)
|
||||
assert.equal(canvas.width, 400)
|
||||
assert.ok(paths.some(parts => parts[0] === 'line' && parts[1] === 40 && parts[2] === 60))
|
||||
assert.equal(props.modelValue, signature)
|
||||
})
|
||||
|
||||
test('prescription slip only displays the pharmacist signature for the current signed approval', () => {
|
||||
const source = fs.readFileSync(path.join(root, 'src/components/prescription-slip/utils.ts'), 'utf8')
|
||||
const { rxPharmacistSignature } = loadModule(source, () => { throw new Error('unexpected import') })
|
||||
const signed = { prescription_audit_status: 1, prescription_audit_signature: signature, prescription_audit_signed_name: ' 李药师 ', doctor_name: '王医生' }
|
||||
assert.equal(rxPharmacistSignature(signed), signature)
|
||||
assert.equal(rxPharmacistSignature({ ...signed, prescription_audit_status: '1' }), signature)
|
||||
for (const status of [0, 2, null, undefined]) assert.equal(rxPharmacistSignature({ ...signed, prescription_audit_status: status }), '')
|
||||
assert.equal(rxPharmacistSignature({ ...signed, prescription_audit_signature: '' }), '')
|
||||
assert.equal(rxPharmacistSignature({ ...signed, prescription_audit_signed_name: '' }), signature)
|
||||
assert.equal(rxPharmacistSignature({ doctor_name: '王医生' }), '')
|
||||
component('components/prescription-slip/index.vue')
|
||||
component('views/consumer/prescription/components/AuditSignatureRecord.vue')
|
||||
})
|
||||
|
||||
// 处方预览的 API -> handler -> 实际 Vue 图片渲染回归见 prescription-audit-signature-display.test.cjs。
|
||||
Reference in New Issue
Block a user