@@ -300,6 +302,7 @@
             
             性别:
             
+              
               
             
           
@@ -545,6 +548,7 @@ export default {
       excelCols: [{ dispLabel: '', val: '', dataLabel: '' }],    //excel数据列名 {dispLabel:'',val:'',dataLabel:''}
       importCols: [], //实际导入的列(即有设置与 dataCols 匹配的列)
       excelData: [],   //excel表格数据 
+      choosedData: [],  // 选中的待导入的数据
 
       dataCols: [
         { dispLabel: '不设置', val: '' },
@@ -696,6 +700,9 @@ export default {
     //清空进度数据数据
     clearProcess() {
 
+      let elo = document.getElementById('fileNames')
+      if(elo) elo.value = ''; // 清空选择的文件
+
       this.workBook = null //EXCEL 工作薄
       this.sheetNames = [] //EXCEL 工作薄中的表单 {sheetName:}
 
@@ -963,7 +970,7 @@ export default {
       columns.forEach((column, index) => {
         //显示合计列
         if (index === 1) {
-          sums[index] = "合计";
+          sums[index] = "导入合计";
           return;
         }
 
@@ -974,15 +981,16 @@ export default {
         }
 
         data.forEach((item) => {
-          if (item[column.property] == '导入成功') {
-            success++
+          console.log('item,column.property',item,column.property)
+          if (item[column.property]) {
+            fail++ 
           } else {
-            fail++
+            success++
           }
         });
 
       });
-      sums[2] = `导入 成功:${success} 条,失败:${fail} 条。`
+      sums[2] = `成功:${success} 条,失败:${fail} 条。`
 
       return sums;
     },
@@ -1221,7 +1229,7 @@ export default {
       }
     },
 
-    // 导入后,批量分析Excel列 与 数据字段 的匹配关系
+    // 选择EXCEL文件后,批量分析Excel列 与 数据字段 的匹配关系
     parseExcelData() {
       let lfind = -1
       this.excelCols.forEach((e, i) => {
@@ -1251,61 +1259,155 @@ export default {
           this.importCols.push(e)
         }
       })
-      this.tableData = []
+      this.tableData = []  // 记录导入后结果状态
+      this.choosedData = []  //选中待导入的数据
+      this.excelData.forEach(e => {
+        if (e.choosed) this.choosedData.push(e)
+      });
 
       //导入进行中
       this.importing(this.dataImportOpts.startRow, this.dataImportOpts.nameType)
+      // 开始导入时,清除选择的 文件
+      document.getElementById('fileNames').value = '';
 
     },
 
     //导入进行时
     // startRow : 从第几行开始导入,同名判断交互时,续接导入
-    // startRowNameType : 续接导入的第1行,执行 同名判断模式, 3.不提示,按新人导入
+    // startRowNameType : 续接导入的第1行,执行 同名判断模式, 3.不提示,按新人导入(前端不用管)
     async importing(startRow, startRowNameType) {
       let body = {}
-      for (let i = startRow; i < this.excelData.length; i++) {
+      for (let i = startRow; i < this.choosedData.length; i++) {
         this.elProgress.percentage = Math.floor(
-          ((i + 1) * 100) / this.excelData.length
+          ((i + 1) * 100) / this.choosedData.length
         );
 
-        if (this.excelData[i].choosed) {
-          body = this.excelDataToApiBody(this.excelData[i])
-          if (i == startRow) body.nameType = startRowNameType
-          if (this.choosedSameMan.patientId) {
-            body.patientId = this.choosedSameMan.patientId
-            this.choosedSameMan = {} // 清除选择
-          }
 
-          console.log('this.excelData[i]', i, body)
-          try {
-            let res = await postapi('/api/app/patientregister/createpatientregisterexcel', body)
-            if (res.code != -1) {
-              if (res.data.code == 1) {
-                this.tableData.push(Object.assign({ importState: '导入成功' }, this.excelData[i]))
-              } else if (res.data.code == -2) {
-                this.sameMans = res.data.details
-                this.dialogSameMan = true
-                this.dataImportOpts.startRow = i
-                break;
-              } else {
-                this.tableData.push(Object.assign({ importState: '导入失败', importDes: res.data.msg }, this.excelData[i]))
+        // 将Excel的数据转换成接口的数据
+        body = this.excelDataToApiBody(this.choosedData[i])
+        if (i == startRow) body.nameType = startRowNameType
+        console.log(`this.choosedData[${i}],startRowNameType,body`)
+
+        try {
+          // 同一人判断
+          if (this.choosedSameMan.patientNo) {
+            // 上一次循环已经判断是否同一人,此次循环不需再判断了
+            if (this.choosedSameMan.patientNo == '$newPatient$') {
+              body.nameType = '3'
+            } else {
+              body.patientNo = this.choosedSameMan.patientNo
+            }
+          } else if (startRowNameType != '3') {
+            let result = await this.isSamePatient(startRowNameType, body)
+            if (result.isContinue) {
+              if (result.err) {
+                this.tableData.push(Object.assign({ importState: '导入失败', importDes: result.err }, this.choosedData[i]))
+                continue
               }
             } else {
-              this.tableData.push(Object.assign({ importState: '导入失败', importDes: res.message }, this.excelData[i]))
+              this.dataImportOpts.startRow = i
+              break; // 跳出循环,重新从 i 开执行 this.importing
             }
-          } catch (error) {
-            break;
           }
+
+          // 旧接口:/api/app/patientregister/createpatientregisterexcel                                 
+          let res = await postapi('/api/app/patientregister/CreatePatientRegisterFromExcel', body)
+          this.choosedSameMan = {}  // 清除选择同一人员的记录
+          if (res.code >= 0) {
+            this.tableData.push(Object.assign({ importState: '导入成功' }, this.choosedData[i]))
+          } else {
+            this.tableData.push(Object.assign({ importState: '导入失败', importDes: res.message }, this.choosedData[i]))
+          }
+        } catch (error) {
+          this.tableData.push(Object.assign({ importState: '导入失败', importDes: `${error}` }, this.choosedData[i]))
         }
 
+
         // 结束导入
-        if (i == this.excelData.length - 1) {
+        if (i == this.choosedData.length - 1) {
           this.elProgress.display = false;
           this.seq = -1
         }
       }
     },
 
+    // 同一人判断
+    async isSamePatient(startRowNameType, body) {
+      console.log('isSamePatient', startRowNameType, body)
+      let result = {
+        isContinue: true,
+        err: ''
+      }
+      let res
+      if (body.idNo) {
+        try {
+          res = await postapi('/api/app/patient/GetByIdNo', { idNo: body.idNo })
+          if (res.code < 0) {
+            result.err = `身份证号查重错误,原因:${res.message}`
+            return result
+          } else if (res.code == 1) {
+            body.patientNo = res.data.patientNo
+            return result
+          }
+        } catch (error) {
+          result.err = `身份证号查重错误,原因:${error}`
+          return result
+        }
+      }
+
+      // 没有身份证号或身份证号未找到同名人员时,按姓名查重
+      let url, localBody = {
+        customerOrgId: body.customerOrgId,
+        name: body.patientName
+      }
+      switch (startRowNameType) {
+        case '1':
+        case '2':
+          if (startRowNameType == '1') url = '/api/app/patientregister/GetSameNamePatient'
+          if (startRowNameType == '2') url = '/api/app/patientregister/GetCustomerOrgSameNamePatient'
+          res = await postapi(url, localBody)
+          if (res.code >= 0) {
+            if (res.data.length > 0) {
+              result.isContinue = false
+              this.sameMans = res.data
+              this.dialogSameMan = true
+            }
+          } else {
+            result.err = `${startRowNameType == '2' ? '同单位内' : ''}同名查重错误,原因:${res.message}`
+          }
+          break;
+        default:
+          break;
+      }
+      return result
+
+      // if (this.choosedSameMan.patientNo) {
+      //   body.patientNo = this.choosedSameMan.patientNo
+      //   // body.patientId = this.choosedSameMan.patientId
+      //   this.choosedSameMan = {} // 清除选择人员
+      // }
+      // try {
+      //   switch (key) {
+      //     case value:
+
+      //       break;
+
+      //     default:
+      //       break;
+      //   }
+
+      //   { dispLabel: '姓名', val: 'patientName' },
+      //   { dispLabel: '性别', val: 'sexName' },
+      //   { dispLabel: '年龄', val: 'age' },
+      //   { dispLabel: '出生日期', val: 'birthDate' },
+      //   { dispLabel: '婚姻状况', val: 'maritalStatusName' },
+      //   { dispLabel: '民族', val: 'nationName' },
+      //   { dispLabel: '身份证号', val: 'idNo' },
+    },
+
+
+
+
     //将Excel的数据转换成接口的数据
     excelDataToApiBody(ExcelData) {
       let body = {
@@ -1340,22 +1442,22 @@ export default {
 
     //选中同名人员档案
     rowClickSameMan(row) {
-      this.choosedSameMan = Object.assign({}, row)
+      this.choosedSameMan = deepCopy(row)
     },
     // 同名人员,按档案人员导入
     btnOldMan() {
-      if (!this.choosedSameMan.patientId) {
+      if (!this.choosedSameMan.patientNo) {
         this.$message.warning("请选择要导入的档案人员")
         return
       }
-      this.importing(this.dataImportOpts.startRow)
+      this.importing(this.dataImportOpts.startRow, this.dataImportOpts.nameType)
       this.dialogSameMan = false
     },
 
     // 同名人员,按新人方式导入
     btnNewMan() {
-      this.choosedSameMan = {}
-      this.importing(this.dataImportOpts.startRow, '3')
+      this.choosedSameMan = { patientNo: '$newPatient$' } // 约定按新人导入 
+      this.importing(this.dataImportOpts.startRow, this.dataImportOpts.nameType)
       this.dialogSameMan = false
     },
 
@@ -1520,7 +1622,8 @@ export default {
         payTypeFlag: this.payTypeFlag,
         medicalCenterId: this.peisid,
       }
-      // {
+
+      //{
       //   "patientRegisterId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
       //   "customerOrgId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
       //   "customerOrgRegisterId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
@@ -1529,6 +1632,7 @@ export default {
       //   "payTypeFlag": "string",
       //   "medicalCenterId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
       // }
+
       this.elProgress.display = true
       this.elProgress.percentage = 0
       for (let i = 0; i < this.prList.length; i++) {
@@ -1539,20 +1643,16 @@ export default {
         body.customerOrgId = this.newCustomerOrgFlag ? customerOrgId : this.prList[i].customerOrgId
 
         try {
-          let res = await postapi('/api/app/patientregister/createpatientregisterhistory', body)
-          if (res.code != -1) {
-            if (res.data.code != -1) {
-              this.tableData.push(Object.assign({ importState: '导入成功' }, this.prList[i]))
-            } else {
-              this.tableData.push(Object.assign({ importState: '导入失败', importDes: res.data.msg }, this.prList[i]))
-            }
+          // 旧接口:/api/app/patientregister/createpatientregisterhistory
+          let res = await postapi('/api/app/patientregister/CreatePatientRegisterFromHistory', body)
+          if (res.code >= 0) {            
+            this.tableData.push(Object.assign({ importState: '导入成功' }, this.prList[i]))            
           } else {
             this.tableData.push(Object.assign({ importState: '导入失败', importDes: res.message }, this.prList[i]))
           }
         } catch (error) {
           this.tableData.push(Object.assign({ importState: '导入失败', importDes: res.message }, this.prList[i]))
         }
-
       }
 
       this.elProgress.display = false
diff --git a/src/views/customerOrg/patientRegisterImport240409.vue b/src/views/customerOrg/patientRegisterImport240409.vue
new file mode 100644
index 0000000..abc4c68
--- /dev/null
+++ b/src/views/customerOrg/patientRegisterImport240409.vue
@@ -0,0 +1,1658 @@
+
+  
+    
+    
+      
+      
+        
+        
+          
+          
+            导入
+          
+          
+            导入后结果状态导出
+          
+        
+      
+      
+        
+          
+          
+          
+          
+        
+        
+          
+          
+          
+          
+          
+          
+          
+            
+              {{ dddw(dict.sex, "id", scope.row.sexId, "displayName") }}
+            
+          
+          
+            
+              {{ scope.row.birthDate ? moment(new Date(scope.row.birthDate)).format('yyyy-MM-DD') : '' }}
+            
+          
+          
+          
+          
+          
+          
+          
+          
+            
+              {{ scope.row.birthDate ? moment(new Date(scope.row.creationTime)).format('yyyy-MM-DD') : '' }}
+            
+          
+        
+      
+    
+
+    
+    
+      
+        
+          
从Excle导入
+          
+          
从以往体检资料中导入
+        
+        
+      
+
+      
+        
+          
导入Excel时,Excel的格式必须符合一定规范,该格式的模板文件放在程序的执行目录下,文件名为:"单位体检人员名单导入模板.xls"
+          
注意事项如下:
+          
+          
1、姓名不能为空,其余数据可根据实际情况选择是否填写。
+            
2、部门、单位分组、性别、婚姻状况、人员类别、体检类别、民族必须与本软件系统中的名称完全一致。
+            
3、年龄和出生日期可以只填一栏,系统将自动对年龄和出生日期进行相互转换。
+            
4、Excel中标题列不能有单元格合并。
+          
+        
 
+        
+      
+
+      
+        
+          
+          
+          
+          
+            
+              
+            
+          
+          
+            标题行: 第
+            
+            行
+          
+        
 
+        
+      
+
+      
 
+        
+          
+            1、按住 Ctr1 或 Shift 键可进行多选,在标题列右击鼠标可设置列名,即:标题列有√;
+            2、身份证号有值且合法时,将以身份证号为主自动换算性别、出生日期及年龄;
+          
+          
 
+            
+              
+              
+              
+
+            
+          
+        
 
+        
+      
+
+      
 
+        
+          
+            选择的人员信息必须直接属于该单位或者是该单位的一级部门,如果人员信息直接属于该单位请将Exce1文件中该人员信息的部门名称设为空
+          
+          
+            
+              体检单位:
+              
+              
+            
+            
+              单位体检次数:
+              
+                
+              
+            
+          
+          
+            
相同姓名的人员:
+            
+              同名病人提示
+              本单位同名提示
+              不提示
+            
+          
+          
+            
登记状态:
+            
+              预登记
+              正式登记
+            
+          
+          
+            
工卡号:
+            
+              
+                
+                工卡号作为档案号
+              
+              
+                工卡号开始位置:
+                
+                长度:
+                
+                 不足长度时,前面补0
+              
+            
+          
+          
+            是否自动创建部门:
+            
+          
+        
 
+        
+      
+
+      
 
+         
+          
+            
+            
+            
+            
+            
+            
+            
+            
+          
+        
+        
+      
+
+      
+      
 
+        
+          
+            选择单位时必须选择其体检次数
+          
+          
+            
体检单位:
+            
+            
+            
+              单位体检次数:
+              
+                
+              
+            
+          
+          
+
+            登记日期:
+            
+
+            至
+            
+
+          
+          
+
+            档案号:
+            
+
+            至
+            
+
+          
+          
+            姓名:
+            
+            性别:
+            
+              
+            
+          
+          
+            状态:
+            
+              
+            
+          
+        
 
+        
+      
+
+      
+      
 
+        
+          
+            按住 Ctr1 或 Shift 键可进行多选
+          
+          
 
+            
+              
+              
+              
+              
+              
+                
+                  {{ dddw(dict.sex, "id", scope.row.sexId, "displayName") }}
+                
+              
+              
+                
+                  {{ scope.row.birthDate ? moment(new Date(scope.row.birthDate)).format('yyyy-MM-DD') : '' }}
+                
+              
+              
+              
+              
+              
+              
+              
+              
+                
+                  {{ scope.row.birthDate ? moment(new Date(scope.row.creationTime)).format('yyyy-MM-DD') : '' }}
+                  
+                
+              
+
+              
+            
+          
+        
 
+        
+      
+
+      
 
+        
+          
+            如果是新单位或部门,选择的病人将直接导入该单位而不是其子单位
+          
+          
+            
+              单位或部门不变
+              新单位或部门
+            
+            
+              
+              
+            
+          
+          
+            单位体检次数:
+            
+              
+            
+          
+          
+            单位体检分组:
+            
+              
+            
+          
+          
+            登记状态:
+            预登记
+            正式登记
+          
+          
+            支付方式:
+            
+              
+            
+          
+        
 
+        
+      
+      
+      
+        
+      
+    
+  
 
+
+
+