<template>
  <div style="display: flex">
    <div style="display: flex; flex-wrap: wrap; width: 100%;">
      <div class="query">
        <span>条码号</span>
        <el-input placeholder="条码号" v-model="doctorCheck.prBase.patientRegisterNo" size="small" style="width: 140px"
          clearable @input="onQueryByPatientRegisterNo" />
      </div>
      <div class="query">
        <span>档案号</span>
        <el-input placeholder="档案号" v-model="doctorCheck.prBase.patientNo" size="small" style="width: 130px" clearable
          @input="onQueryByPatientNo" />
      </div>
      <div class="query">
        <span>姓名</span>
        <el-input placeholder="姓名" v-model="doctorCheck.prBase.patientName" size="small" style="width: 100px" clearable
          @blur="onQuery()" />
      </div>
      <div class="query">
        <span>性别</span>
        <el-select v-model="doctorCheck.prBase.sexId" style="width: 80px" size="small" disabled>
          <el-option v-for="item in dict.sex" :key="item.id" :label="item.displayName" :value="item.id" />
        </el-select>
      </div>
      <div class="query">
        <span>体检次数</span>
        <el-input v-model="doctorCheck.prBase.medicalTimes" size="small" style="width: 40px" disabled />
      </div>
      <div class="query">
        <span>婚姻</span>
        <el-select v-model="doctorCheck.prBase.maritalStatusId" style="width: 80px" size="small" disabled>
          <el-option v-for="item in dict.maritalStatus" :key="item.id" :label="item.displayName" :value="item.id" />
        </el-select>
      </div>
      <div class="query">
        <span>体检日期</span>
        <el-input :value="doctorCheck.prBase.creationTime ? lmoment(doctorCheck.prBase.creationTime, 'yyyy-MM-DD') : ''"
          style="width: 100px" size="small" disabled></el-input>
      </div>
      <div class="query">
        <span>单位</span>
        <el-input :value="doctorCheck.prBase.customerOrgParentName" style="width: 120px" size="small" disabled />
      </div>
      <div class="query">
        <span>部门</span>
        <el-input :value="doctorCheck.prBase.customerOrgName" style="width: 120px" size="small" disabled />
      </div>
      <div class="query">
        <span>体检类别</span>
        <el-select v-model="doctorCheck.prBase.medicalTypeId" disabled style="width: 80px" size="small">
          <el-option v-for="item in dict.medicalType" :key="item.id" :label="item.displayName" :value="item.id" />
        </el-select>
      </div>
      <div class="query">
        <span>人员类别</span>
        <el-select v-model="doctorCheck.prBase.personnelTypeId" disabled style="width: 80px" size="small">
          <el-option v-for="item in dict.personnelType" :key="item.id" :label="item.displayName" :value="item.id" />
        </el-select>
      </div>
      <div class="query">
        <span>民族</span>
        <el-select v-model="doctorCheck.prBase.nationId" disabled style="width: 80px" size="small">
          <el-option v-for="item in dict.nation" :key="item.id" :label="item.displayName" :value="item.id" />
        </el-select>
      </div>
      <div class="query">
        <span>手机</span>
        <el-input :value="doctorCheck.prBase.mobileTelephone" style="width: 120px" size="small" disabled />
      </div>
    </div>
  </div>
</template>
<script>
import moment from "moment";
import { mapState, mapMutations} from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { objCopy, opjCopy } from '../../utlis/proFunc'

export default {
  components: {},
  data() {
    return {
      dialogVisible: false,

      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },

  created() { },

  //挂载完成
  mounted() { },

  computed: {
    ...mapState(["dict", "doctorCheck", "patientRegister", "customerOrg"]),    
  },
  methods: {
    ...mapMutations(['doctorCheckPrBaseInit']),
    //按条码号查个人数据
    onQueryByPatientRegisterNo() {
      let val = this.doctorCheck.prBase.patientRegisterNo
      console.log(`/api/app/patient-register/patient-register-or-patient?SType=1&PatientRegisterNo=${val}`)
      getapi(`/api/app/patient-register/patient-register-or-patient?SType=1&PatientRegisterNo=${val}`)
      .then((res) => {
        if (res.code != -1) {
          this.doctorCheckPrBaseInit()
          this.doctorCheck.prBase.patientRegisterNo = val
          objCopy(res.data,this.doctorCheck.prBase)
        }
      });
    },

    //按条码号查个人数据
    onQueryByPatientNo() {
      let val = this.doctorCheck.prBase.patientNo
      console.log(`/api/app/patient-register/patient-register-or-patient?SType=2&PatientNo=${val}`)
      getapi(`/api/app/patient-register/patient-register-or-patient?SType=2&PatientNo=${val}`)
      .then((res) => {
        if (res.code != -1) {
          this.doctorCheckPrBaseInit()
          this.doctorCheck.prBase.patientNo = val
          objCopy(res.data,this.doctorCheck.prBase)
        }
      });
    },

    lmoment(date, forMat) {
      return moment(new Date(date)).format(forMat);
    },

    //查询
    btnQuery() {
      this.doctorCheck.prBase.times++;
      console.log("this.doctorCheck.prBase", this.doctorCheck.prBase);
    },

    //读身份证
    readIdCard() {
      alert("读身份证");
    },
  },
};
</script>
<style scoped>
.query {
  margin-left: 10px;
}
</style>
