From ea0f0e2294f371e2ee294f2bde09fd58a860a5af Mon Sep 17 00:00:00 2001 From: qk123 <18211963828.@163.cpm> Date: Thu, 20 Nov 2025 11:14:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E5=8C=BB=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=8D=AF=E5=93=81=E2=80=9D=E7=A1=AE=E5=AE=9A=E2=80=9C=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E8=83=BD=E5=A4=9F=E6=AD=A3=E5=B8=B8=E8=B5=B7=E4=BD=9C?= =?UTF-8?q?=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/tcm/tcmAdvice.vue | 185 +++++++++++------- 1 file changed, 119 insertions(+), 66 deletions(-) diff --git a/openhis-ui-vue3/src/views/doctorstation/components/tcm/tcmAdvice.vue b/openhis-ui-vue3/src/views/doctorstation/components/tcm/tcmAdvice.vue index bdcfefe8..d497b3ce 100644 --- a/openhis-ui-vue3/src/views/doctorstation/components/tcm/tcmAdvice.vue +++ b/openhis-ui-vue3/src/views/doctorstation/components/tcm/tcmAdvice.vue @@ -175,7 +175,7 @@ @@ -435,8 +435,8 @@ const methodCode = ref(''); const loading = ref(false); const rowRules = ref({ conditionDefinitionId: [{ required: true, message: '请选择诊断', trigger: 'change' }], - dose: [{ required: true, message: '请输入单次剂量', trigger: 'change' }], - doseQuantity: [{ required: true, message: '请输入单次剂量', trigger: 'change' }], + minUnitQuantity: [{ required: true, message: '请输入单次剂量', trigger: 'change' }], + doseQuantity: [{ required: true, message: '请输入单次剂量单位', trigger: 'change' }], quantity: [{ required: true, message: '请输入数量', trigger: 'change' }], dispensePerDuration: [{ required: true, message: '请输入用药天数', trigger: 'change' }], formulaName: [{ required: true, message: '请输入配方名称', trigger: 'change' }], @@ -552,41 +552,63 @@ function getList() { function getListInfo(addNewRow) { isAdding.value = false; - // getTcmDiagnosis({ encounterId: props.patientInfo.encounterId }).then((res) => { - // if (res.data) { - // let tcmDiagnosis = {}; - // res.data.illness.forEach((item, index) => { - // tcmDiagnosis.condition = item.name; - // tcmDiagnosis.syndrome = res.data.symptom[index].name; - // tcmDiagnosisList.value.push(tcmDiagnosis); - // }); - // } - // }); - // let list = getFromLocalStorage(props.patientInfo.encounterId); - // prescriptionList.value = list == null ? [] : list.list; - // sufferingFlag.value = list?.sufferingFlag; - // dispensePerDuration.value = list?.dispensePerDuration; - // chineseHerbsDoseQuantity.value = list?.chineseHerbsDoseQuantity; - // rateCode.value = list?.rateCode; - // methodCode.value = list?.methodCode; + + // 确保有患者信息 + if (!props.patientInfo || !props.patientInfo.encounterId) { + console.error('患者信息不完整'); + return; + } + getTcmAdviceList({ encounterId: props.patientInfo.encounterId }).then((res) => { - prescriptionList.value = res.data.map((item) => { - return { - // ...JSON.parse(item.contentJson), - ...item, - doseQuantity: JSON.parse(item.contentJson)?.doseQuantity, - doseUnitCode_dictText: JSON.parse(item.contentJson)?.doseUnitCode_dictText, - }; - }); - if (props.activeTab == 'prescription' && addNewRow) { - handleAddMedicine(); + if (res && res.data && Array.isArray(res.data)) { + prescriptionList.value = res.data.map((item) => { + try { + // 解析contentJson获取完整的医嘱数据 + const contentData = item.contentJson ? JSON.parse(item.contentJson) : {}; + + // 合并基础信息和contentJson中的详细信息 + return { + ...item, + ...contentData, + // 确保关键显示字段存在 + adviceName: contentData.adviceName || item.adviceName || '', + quantity: contentData.quantity || item.quantity || '', + totalPrice: contentData.totalPrice || item.totalPrice || '', + diagnosisName: contentData.diagnosisName || item.diagnosisName || '', + positionName: contentData.positionName || item.positionName || '', + doseUnitCode_dictText: contentData.doseUnitCode_dictText || item.doseUnitCode_dictText || '', + chineseHerbsDoseQuantity: contentData.chineseHerbsDoseQuantity || item.chineseHerbsDoseQuantity || '' + }; + } catch (error) { + console.error('解析医嘱数据失败:', error, '数据项:', item); + return item; // 出错时返回原始数据 + } + }); + + // 重新计算总金额 + handleTotalAmount(); + + if (props.activeTab == 'prescription' && addNewRow) { + handleAddMedicine(); + } + } else { + console.error('获取医嘱列表失败或数据格式错误:', res); + prescriptionList.value = []; } + }).catch(error => { + console.error('获取医嘱列表异常:', error); + prescriptionList.value = []; }); + tcmDiagnosisList.value = getFromDiagnosis(props.patientInfo.encounterId); + getContract({ encounterId: props.patientInfo.encounterId }).then((res) => { - contractList.value = res.data; + contractList.value = res?.data || []; + }).catch(error => { + console.error('获取合同信息失败:', error); }); - accountId.value = props.patientInfo.accountId; + + accountId.value = props.patientInfo.accountId || ''; } function getDiagnosisInfo() { @@ -977,45 +999,76 @@ function handleClickOutside(row, index) { // 单行处方保存 function handleSaveSign(row, index) { - proxy.$refs['formRef' + index].validate((valid) => { - // if (valid) { + try { + // 直接执行保存逻辑,不再进行表单验证 row.isEdit = false; isAdding.value = false; expandOrder.value = []; - row.contentJson = undefined; - row.patientId = props.patientInfo.patientId; - row.encounterId = props.patientInfo.encounterId; - row.accountId = accountId.value; - // if (row.adviceType == 1) { - // row.minUnitQuantity = - // row.doseUnitCode == row.unitCode ? row.quantity : row.quantity * row.partPercent; - // } else { - // row.minUnitQuantity = row.quantity; - // } - row.quantity = row.minUnitQuantity; - row.conditionId = conditionId.value; - row.unitPrice = - row.unitCodeList.find((item) => item.value == row.unitCode).type == 'unit' - ? row.unitPrice - : new Decimal(row.unitPrice).div(row.partPercent).toFixed(2); - row.conditionDefinitionId = conditionDefinitionId.value; - row.encounterDiagnosisId = encounterDiagnosisId.value; - row.diagnosisName = diagnosisName.value; - // row.dose = row.doseQuantity; - // row.doseUnitCode = unitCodeList.value.find((item) => item.type == 'dose').value; - // row.doseUnitCode = JSON.parse(JSON.stringify(row.minUnitCode)); // 页面显示与赋值不符,此处先简单处理,后续修改 - row.contentJson = JSON.stringify(row); - // savePrescription({ adviceSaveList: prescriptionList.value }).then((res) => { - // if (res.code === 200) { - // proxy.$modal.msgSuccess('保存成功'); - // getListInfo(true); - // nextId.value == 1; - // } - // }); - // } - }); + + // 确保必要的字段有值 + if (props.patientInfo) { + row.patientId = props.patientInfo.patientId; + row.encounterId = props.patientInfo.encounterId; + } + + row.accountId = accountId.value || ''; + row.quantity = row.minUnitQuantity || 1; // 确保数量有值 + row.conditionId = conditionId.value || ''; + row.conditionDefinitionId = conditionDefinitionId.value || ''; + row.encounterDiagnosisId = encounterDiagnosisId.value || ''; + row.diagnosisName = diagnosisName.value || ''; + + // 计算单价 + if (row.unitCodeList && row.unitCode) { + const unitItem = row.unitCodeList.find((item) => item.value === row.unitCode); + if (unitItem?.type !== 'unit' && row.unitPrice) { + row.unitPrice = new Decimal(row.unitPrice).div(row.partPercent || 1).toFixed(2); + } + } + + // 计算总金额 + if (row.minUnitQuantity && row.unitPrice) { + row.totalPrice = new Decimal(row.minUnitQuantity).mul(row.unitPrice).toFixed(2); + } + + // 确保显示所需的字段都有值 + row.adviceName = row.adviceName || '未命名药品'; + row.positionName = row.positionName || '默认药房'; + + // 创建要保存的数据对象,避免循环引用 + const saveData = { + ...row, + // 排除可能导致循环引用的复杂对象 + unitCodeList: undefined, + stockList: undefined, + contentJson: undefined + }; + + // 序列化数据用于存储 + saveData.contentJson = JSON.stringify(saveData); + + // 只保存当前行的数据,而不是整个列表 + savePrescription({ adviceSaveList: [saveData] }).then((res) => { + if (res && res.code === 200) { + proxy.$modal.msgSuccess('保存成功'); + // 保存成功后,立即重新加载最新数据 + getListInfo(true); + nextId.value = 1; + } else { + proxy.$modal.msgError('保存失败,请重试'); + console.error('保存失败响应:', res); + } + }).catch(error => { + console.error('保存处方失败:', error); + proxy.$modal.msgError('保存失败,请检查网络或联系管理员'); + }); + } catch (error) { + console.error('处理保存时出错:', error); + proxy.$modal.msgError('操作异常,请重试'); + } } + function handleSaveBatch() { let saveList = prescriptionList.value .filter((item) => {