预包装处方模板数据未回显 (2025-08-07 01:59Z)
User
@/patients @/enteralNutrition 添加预包装处方时,点击处方模板选中想要的模板点击确认以后,只提示成功,但是数据未能回显到营养产品的表格当中
Assistant
我来帮您分析肠内营养预包装处方模板数据未回显的问题。让我先了解一下相关组件的结构和数据流。
Read file: src/views/patients/enteralNutrition/components/table/PackageTable.vue
Read file: src/views/patients/enteralNutrition/components/table/PackageTable.vue
Read file: src/views/patients/enteralNutrition/components/table/PackageTable.vue
Read file: src/views/patients/enteralNutrition/components/table/PackageTable.vue
Read file: src/views/patients/enteralNutrition/components/table/PackageTable.vue
现在我已经了解了问题所在。让我分析一下问题的原因:
Todo List
通过分析代码,我发现了预包装处方模板数据未回显的问题。问题主要出现在以下几个地方:
- 处方类型值不匹配: 在
LeftCard.vue
中,prescriptionType
使用的是字符串 '2'
,但在 handleTemplateSelected
函数中检查的是 'package'
- 数据处理逻辑错误: 预包装处方的数据处理走错了分支
让我修复这个问题:
Todo List
Edit file: src/views/patients/enteralNutrition/components/LeftCard.vue
undefined
**Chunk 1**
Lines added: 1, lines removed: 1
```diff
@@ -195,5 +195,5 @@
// 根据处方类型处理模板数据
- if (prescriptionType.value === 'package') {
+ if (prescriptionType.value === '2') {
// 预包装处方:直接更新packageData
handlePackageTemplateData(contentData);
```
现在我需要检查 submitForm
函数中的处方类型判断逻辑也需要修正:
Edit file: src/views/patients/enteralNutrition/components/LeftCard.vue
undefined
**Chunk 1**
Lines added: 1, lines removed: 1
```diff
@@ -380,5 +380,5 @@
param.value.status = status;
- if (prescriptionType.value == 'normal') {
+ if (prescriptionType.value == '3') {
param.value.chargeType = '3';
if (!configData.value || configData.value.length == 0) {
```
**Chunk 2**
Lines added: 1, lines removed: 1
```diff
@@ -393,5 +393,5 @@
}
param.value.consumableList = JSON.parse(materialData.value);
- } else if (prescriptionType.value == 'package') {
+ } else if (prescriptionType.value == '2') {
param.value.chargeType = '2';
if (!packageData.value || packageData.value.length == 0) {
```
现在我需要检查 handlePackageTemplateData
函数,确保它正确处理预包装模板数据的格式:
Todo List
The model made no changes to the file.
让我检查一下数据更新后的调试日志,看看是否需要进一步调整:
Edit file: src/views/patients/enteralNutrition/components/LeftCard.vue
undefined
**Chunk 1**
Lines added: 4, lines removed: 1
```diff
@@ -174,7 +174,10 @@
console.log('转换后的预包装数据:', packageTableData);
- // 更新packageData
+ // 更新packageData - 确保立即触发响应式更新
packageData.value = JSON.stringify(packageTableData);
console.log('更新packageData.value:', packageData.value);
+
+ // 手动触发更新事件确保数据同步
+ updatePackageData(packageData.value);
proxy?.$modal.msgSuccess('预包装处方模板导入成功');
```
现在让我再次检查一下 PackageTable 组件中对于 modelValue 的监听是否正确响应了这个变化。我发现问题可能还在于数据的处理时机。让我添加一些额外的调试信息:
Edit file: src/views/patients/enteralNutrition/components/LeftCard.vue
undefined
**Chunk 1**
Lines added: 1, lines removed: undefined
```diff
@@ -118,4 +118,5 @@
const updatePackageData = (val: string) => {
+ console.log('LeftCard updatePackageData 被调用,数据:', val);
packageData.value = val;
};
```
现在让我检查一下 nextTick
的使用,确保数据更新的时机正确:
Edit file: src/views/patients/enteralNutrition/components/LeftCard.vue
undefined
**Chunk 1**
Lines added: 4, lines removed: 3
```diff
@@ -179,8 +179,9 @@
console.log('更新packageData.value:', packageData.value);
- // 手动触发更新事件确保数据同步
- updatePackageData(packageData.value);
-
+ // 使用nextTick确保数据更新完成后再触发成功提示
+ nextTick(() => {
+ console.log('nextTick后,packageData.value:', packageData.value);
proxy?.$modal.msgSuccess('预包装处方模板导入成功');
+ });
} catch (error) {
console.error('处理预包装处方模板数据失败:', error);
```
现在让我也检查一下模板选择后是否需要强制重新渲染 PackageTable 组件。让我查看一下 PackageTable 的 watch 监听器,确保它能正确处理数据更新:
Edit file: src/views/patients/enteralNutrition/components/table/PackageTable.vue
undefined
**Chunk 1**
Lines added: 6, lines removed: undefined
```diff
@@ -389,12 +389,18 @@
() => prop.modelValue,
(val: string) => {
+ console.log('PackageTable watch触发,接收到modelValue:', val);
+
if (!val || val.trim().length == 0) {
+ console.log('PackageTable modelValue为空,跳过处理');
return;
}
try {
let arr = JSON.parse(val);
+ console.log('PackageTable解析数据成功:', arr);
+
if (Array.isArray(arr)) {
if (arr.length == 0) {
+ console.log('PackageTable数组为空,创建默认行');
tableData.value = [createDefaultRow()];
} else {
```
**Chunk 2**
Lines added: 2, lines removed: 2
```diff
@@ -408,9 +414,9 @@
tableData.value = processedData;
- console.log('PackageTable设置表格数据:', tableData.value);
+ console.log('PackageTable设置表格数据完成:', tableData.value);
}
}
} catch (error) {
- console.error('PackageTable解析数据失败:', error);
+ console.error('PackageTable解析数据失败:', error, '原始数据:', val);
}
},
```
现在让我完成最后的修复,添加缺失的 Vue imports 和组合式 API 函数:
Todo List
Edit file: src/views/patients/enteralNutrition/components/LeftCard.vue
undefined
**Chunk 1**
Lines added: 1, lines removed: 1
```diff
@@ -76,5 +76,5 @@