Selaa lähdekoodia

待完善用户新增患者信息编辑

cgp 1 viikko sitten
vanhempi
commit
a120937c38

+ 80 - 30
src/views/qw/collectionPendingSales/completeCollectionInfoDialog.vue

@@ -151,39 +151,58 @@ export default {
       return true;
     },
 
-    // 患者切换时构建 patientInfo
+// 修改 onPatientChange 方法,添加调试日志
     onPatientChange(patientId) {
       if (patientId) {
-        const patient = this.patientList.find(p => p.patientId === patientId);
-        if (patient) {
-          // 构建与后端 PatientInfo 结构一致的对象
-          this.form.patientInfo = {
-            patientId: patient.patientId,
-            patientName: patient.patientName || patient.name || '',
-            mobile: patient.mobile || patient.phone || patient.tel || '',
-            sex: String(patient.sex ?? ''),
-            birthday: patient.birthday || null
-          };
+        // 每次选择时都从服务器获取最新的患者信息,而不是依赖本地缓存
+        getUndeletedUserInfoByUserId(this.userId).then(response => {
+          const updatedPatientList = response.data || [];
 
-          // 同时设置 selectedPatientId
-          this.form.selectedPatientId = patientId;
+          const patient = updatedPatientList.find(p => p.patientId === patientId);
 
-          // 如果患者名称是"默认就诊人",提示完善信息并清空选择
-          if (patient.patientName === '默认就诊人') {
-            this.$confirm('当前选择的患者信息为默认值,请完善患者信息后再提交!', '提示', {
-              type: 'warning'
-            }).then(() => {
-              // 清空当前选择
-              this.form.selectedPatientId = null;
-              this.form.patientInfo = null;
+          if (patient) {
+            // 构建与后端 PatientInfo 结构一致的对象
+            const newPatientInfo = {
+              patientId: patient.patientId,
+              patientName: patient.patientName || patient.name || '',
+              mobile: patient.mobile || patient.phone || patient.tel || '',
+              sex: String(patient.sex ?? ''),
+              birthday: patient.birthday || null
+            };
 
-            }).catch(() => {
-              // 用户点击取消,清空选择
-              this.form.selectedPatientId = null;
-              this.form.patientInfo = null;
-            });
+            // 同时设置 selectedPatientId
+            this.form.selectedPatientId = patientId;
+
+            // 如果患者名称是"默认就诊人",提示完善信息并清空选择
+            if (patient.patientName === '默认就诊人') {
+              this.$confirm('当前选择的患者信息为默认值,请完善患者信息后再提交!', '提示', {
+                type: 'warning'
+              }).then(() => {
+                // 清空当前选择
+                this.form.selectedPatientId = null;
+                this.form.patientInfo = null;
+              }).catch(() => {
+                // 用户点击取消,清空选择
+                this.form.selectedPatientId = null;
+                this.form.patientInfo = null;
+              });
+            } else {
+              // 只有不是"默认就诊人"时才设置 patientInfo
+              this.form.patientInfo = newPatientInfo;
+            }
+          } else {
+            // 如果在新列表中找不到该患者,清空选择
+            this.form.selectedPatientId = null;
+            this.form.patientInfo = null;
+            this.$message.warning('该患者信息已不存在');
           }
-        }
+        }).catch((error) => {
+          console.error('获取患者信息失败:', error);
+          this.$message.error('获取患者信息失败');
+          // 获取失败时也清空选择
+          this.form.selectedPatientId = null;
+          this.form.patientInfo = null;
+        });
       } else {
         // 如果清空了选择,也要清空 patientInfo
         this.form.patientInfo = null;
@@ -301,13 +320,44 @@ export default {
       });
     },
 
-    submitForm() {
+    async submitForm() {
+      // 在验证通过后,提交前重新获取最新的患者信息
+      if (this.form.selectedPatientId) {
+        try {
+          const response = await getUndeletedUserInfoByUserId(this.userId);
+          const latestPatientList = response.data || [];
+          const latestPatient = latestPatientList.find(p => p.patientId === this.form.selectedPatientId);
+
+          if (latestPatient) {
+            // 更新 form 表单中的患者信息
+            this.form.patientInfo = {
+              patientId: latestPatient.patientId,
+              patientName: latestPatient.patientName || latestPatient.name || '',
+              mobile: latestPatient.mobile || latestPatient.phone || latestPatient.tel || '',
+              sex: String(latestPatient.sex ?? ''),
+              birthday: latestPatient.birthday || null
+            };
+
+            // 同时更新 select 中显示的患者列表(可选)
+            this.patientList = latestPatientList;
+          } else {
+            console.warn(`未找到 patientId 为 ${this.form.selectedPatientId} 的患者`);
+            this.$message.warning('所选患者信息已不存在,请重新选择');
+            return;
+          }
+        } catch (error) {
+          this.$message.error('获取最新患者信息失败');
+          return;
+        }
+      }
+
       this.$refs["form"].validate(valid => {
         if (valid) {
           if (!this.validateRequiredRemarks()) {
             this.$message.error('请填写必填的备注信息');
             return;
           }
+
           const answersForSubmit = this.form.answers.map(answer => {
             const remarks = [];
             answer.options.forEach(option => {
@@ -319,13 +369,13 @@ export default {
             return { ...answer, remarksList: remarks, options: cleanOptions };
           });
 
-          // 构建提交数据,去掉 selectedPatientId 和 patientInfo 中的临时字段,保证结构清晰
+          // 构建提交数据
           const { selectedPatientId, patientInfo, ...restForm } = this.form;
           const submitData = {
             ...restForm,
             id: this.id,
             answers: answersForSubmit,
-            patientInfo: patientInfo || null   // 提交完整的患者信息对象
+            patientInfo: patientInfo || null
           };
 
           submitSalesInfo(submitData).then(res => {