<template>
  <div>    
    <div> 
      <el-table :data="patientRegisters" border width="800" height="480" highlight-current-row
        @row-click="registerRowClick"  @row-dblclick="rowDblclick"  size="small">  
        <el-table-column prop="completeFlag" label="体检进度">
          <template slot-scope="scope">
            <div>{{ dddw(dict.completeFlag, "id", scope.row.completeFlag, "displayName") }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="guidePrintTimes" label="打印" width="50">
          <template slot-scope="scope">
            <i class="el-icon-printer" v-if="scope.row.guidePrintTimes > 0" style="font-size: 24px;color: green;"></i>
          </template>
        </el-table-column>
        <el-table-column prop="isLock" label="锁住">
          <template slot-scope="scope">
            <div>{{ scope.row.isLock == "Y" ? "是" : "否" }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="customerOrgParentName" label="单位" width="180">
          <template slot-scope="scope">
            <div>{{ scope.row.customerOrgParentName ? scope.row.customerOrgParentName : scope.row.customerOrgName }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="customerOrgName" label="部门" width="180">
          <template slot-scope="scope">
            <div>{{ scope.row.customerOrgParentName ? scope.row.customerOrgName : "" }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="patientName" label="姓名" />
        <el-table-column prop="sexId" label="性别">
          <template slot-scope="scope">
            <div>{{ dddw(dict.sex, "id", scope.row.sexId, "displayName") }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="age" label="年龄" />
        <el-table-column prop="patientRegisterNo" label="条码号" width="150" />
        <el-table-column prop="patientNo" label="档案号" />
        <el-table-column prop="medicalTimes" label="体检次数"></el-table-column>
        <el-table-column label="分组/套餐" width="150">
          <template slot-scope="scope">
            <div v-if="scope.row.medicalPackageId !== dict.personOrgId && scope.row.customerOrgId === dict.personOrgId">
              {{ dddw(dict.medicalPackage, "id", scope.row.medicalPackageId, "displayName") }}
            </div>
            <div v-if="scope.row.medicalPackageId !== dict.personOrgId && scope.row.customerOrgId !== dict.personOrgId">
              {{ dddw(dict.customerOrgGroupAll, "id", scope.row.customerOrgGroupId, "displayName") }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="nationId" label="民族">
          <template slot-scope="scope">
            <div>
              {{ dddw(dict.nation, "nationId", scope.row.nationId, "displayName") }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="idNo" label="身份证" width="150" />
        <el-table-column prop="birthDate" label="出生日期" width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.birthDate">
              {{ moment(scope.row.birthDate).format("yyyy-MM-DD") }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="email" label="邮箱" width="180" />
        <el-table-column prop="mobileTelephone" label="手机" width="100" />
        <el-table-column prop="telephone" label="电话" width="100" />
        <el-table-column prop="address" label="地址" width="300" />
        <el-table-column prop="medicalCardNo" label="体检卡号" />
        <el-table-column prop="jobCardNo" label="工卡号" />
        <el-table-column prop="maritalStatusId" label="婚姻状况">
          <template slot-scope="scope">
            <div>
              {{ dddw(dict.maritalStatus, "id", scope.row.maritalStatusId, "displayName") }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="medicalTypeId" label="体检类别">
          <template slot-scope="scope">
            <div v-if="scope.row.medicalTypeId !== dict.personOrgId">
              {{ dddw(dict.medicalType, "id", scope.row.medicalTypeId, "displayName") }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="personnelTypeId" label="人员类别">
          <template slot-scope="scope">
            <div v-if="scope.row.personnelTypeId !== dict.personOrgId">
              {{ dddw(dict.personnelType, "id", scope.row.personnelTypeId, "displayName") }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="jobPost" label="职务" />
        <el-table-column prop="jobTitle" label="职称" />
        <el-table-column prop="salesman" label="介绍人" />
        <el-table-column prop="isVip" label="是否VIP">
          <template slot-scope="scope">
            <div>{{ scope.row.isVip == "Y" ? "是" : "否" }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="creatorName" label="登记人" />
        <el-table-column prop="creationTime" label="登记日期" width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.creationTime">{{ moment(scope.row.creationTime).format("yyyy-MM-DD") }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="isUpload" label="是否上传">
          <template slot-scope="scope">
            <div>{{ scope.row.isUpload == "Y" ? "是" : "否" }}</div>
          </template>
        </el-table-column>

        <!--
        "sexHormoneTermId": "00000000-0000-0000-0000-000000000000",
        "interposeMeasure": null,
        "medicalConclusionId": "00000000-0000-0000-0000-000000000000",
        "reportPrintTimes": 0,        
        "isMedicalStart": "N",
        "medicalStartDate": "6/28/2023",
        "isRecoverGuide": "N",
        "summaryDate": "",
        "summaryDoctor": null,
        "isAudit": "N",
        "auditDoctor": null,
        "auditDate": "",        
        "isNameHide": "N",
        "isPhoneFollow": "N",
        "thirdInfo": null,
        "guidePrintTimes": null,
        "remark": null,
        "organizationUnitId": "00000000-0000-0000-0000-000000000000",
        "customerOrgRegisterId": "00000000-0000-0000-0000-000000000000",
        "lastModifierName": "",
        "lastModificationTime": null,
        "lastModifierId": null,
        "creatorId": null,
        "id": "3a0c196d-a6d0-37fe-5c32-4806bdc4530f"
        -->
      </el-table>
      <div style="display: flex;margin-top: 5px;justify-content:space-between;">
        <div></div>
        <div style="display: flex;">
          <el-button @click="dialogWin.PatientRegisterForChoose = false" style="width:90px;">取消</el-button>
          <el-button type="primary" @click="btnOk" style="width:90px;">确定</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import moment from "moment";
import { mapState, mapActions } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import Sortable from "sortablejs";
import FileSaver from 'file-saver';
import html2canvas from 'html2canvas';

import {
  dddw,
  objCopy,
  arrayReduce,
  arrayExistObj,
  deepCopy,
} from "../../utlis/proFunc";

import ElProgressOCX from "../report/ElProgressOCX.vue";

export default {
  components: { 
    ElProgressOCX,
  },
  props:["params"], // params 
  data() {
    return {
      patientRegisterId:'',   // 选中的体检人员ID
      patientRegisters:[],    //体检人员列表信息
    };
  },

  created() {

  },

  //挂载完成
  mounted() {
    
  },
  computed: {
    ...mapState([
      "window",
      "dataTransOpts",
      "dialogWin",
      "dict",
      "elProgress",
      "patientRegister",
      "customerOrg",
    ]),
  },
  methods: {
    moment,dddw,deepCopy,

    getPatientregisterList(){
      this.patientRegisterId = "" //先清除选择的体检人员ID
      // params = {
      //   patientName:v,
      //   isFilterPreRegistration:'Y' //是否需要过滤预登记数据 Y=过滤预登记数据 N=不过滤 默认为N (备注：只有CompleteFlag参数的值不为0的情况才有效，null值也有效)
      // }
      postapi('/api/app/patientregister/getlistinfilter', this.params).then(res => {
        if (res.code != -1) {          
          if(res.data.items.length == 0){
            this.dataTransOpts.tableS.patient_register.id = ''
            setTimeout(() => {
              this.dataTransOpts.refresh.patient_register.S++
            }, 20);
            this.dialogWin.PatientRegisterForChoose = false
            this.$message.warning('未找到相关信息')
          }else if(res.data.items.length == 1){
            this.rowDblclick(res.data.items[0]) 
          }else{            
            this.patientRegisters = res.data.items
          }
        }
      })

    },
    

    // 选中记录
    registerRowClick(row){
      this.patientRegisterId = row.id      
    },

    // 双击 选中记录 并关闭窗口
    rowDblclick(row){
      this.registerRowClick(row)
      this.btnOk()      
    },

    btnOk(){
      if(!this.patientRegisterId){
        this.$message.warning("请选择体检人员！")
        return
      }
      this.dataTransOpts.tableS.patient_register.id = this.patientRegisterId
      setTimeout(() => {
        this.dataTransOpts.refresh.patient_register.S++
      }, 20);   
      this.dialogWin.PatientRegisterForChoose = false
    },
  
  },

  //监听事件
  watch: {
    // 刷新体检人员登记列表
    "dataTransOpts.refresh.patient_register.M":{
      immediate: true, // 立即执行
      // deep: true, // 深度监听复杂类型内变化
      handler(newVal,oldVal){        
        console.log(`watch: 刷新体检人员列表 newVal: ${newVal} oldVal:${oldVal}`)
        this.getPatientregisterList()
      }
    },
  },
};
</script>
<style scoped>
@import "../../assets/css/global_input.css";
@import "../../assets/css/global_table.css";
@import "../../assets/css/global.css";


.box {
  display: flex;
}

.listBtn {
  margin-top: 5px;
  text-align: center;
}

.btnClass {
  width: 100px;
}

</style>
