<template>
  <!-- <div class="app-container"> -->
    <div class="basicInfo">
      <!-- <div class="headline">基本资料</div> -->
      <div class="information">
        <div class="row">
          <div class="rowOne">
            <p class="rowName">首次诊治时间:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.first_treatment_date"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.first_treatment_date"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.first_treatment_date"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName1">首次肾脏替代治疗时间 :</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.firstDialysisDate"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.firstDialysisDate"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.firstDialysisDate"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName">创建者:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.registrars"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.registrars"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.registrars"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName">创建日期:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.create_time"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.create_time"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.create_time"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
        </div>
        <div class="row">
          <div class="rowOne">
            <p class="rowName">姓名:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.name"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.name"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.name"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName">性别:</p>
            <div class="radioOne">
              <template>
                <el-radio v-model="form.gender" label="1">男</el-radio>
                <el-radio v-model="form.gender" label="2">女</el-radio>
              </template>
            </div>
          </div>
          <div class="rowOne">
            <p class="rowName">证件类型:</p>
            <el-input
              placeholder="请输入内容"
              :disabled="true"
              v-model="form.id_type"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.id_type"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.id_type"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
        </div>
        <div class="row">
          <div class="rowOne">
            <p class="rowName">身份证号:</p>
            <el-input
              placeholder="请输入内容"
              style="width: 200px;"
              v-model="form.idCardNo"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.idCardNo"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.idCardNo"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
        </div>
        <div class="row">
          <div class="rowOne">
            <p class="rowName">民族:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.nation"
              :disabled="true"
            ></el-input>
          </div>
          <div class="rowOne">
            <p class="rowName">婚姻状况:</p>
            <el-input
              placeholder="请输入内容"
              :disabled="true"
              v-model="form.maritalStatus"
            ></el-input>
          </div>
          <div class="rowOne">
            <p class="rowName">年龄:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.age"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.age"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.age"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName">出生日期:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.birth"
              :disabled="true"
            ></el-input>
          </div>
        </div>
        <div class="row">
          <div class="rowOne">
            <p class="rowName">教育程度:</p>
            <el-input
              placeholder="请输入内容"
              style="width: 270px;"
              v-model="form.education"
              :disabled="true"
            ></el-input>
          </div>
          <div class="rowOne">
            <p class="rowName">职业:</p>
            <el-input
              placeholder="请输入内容"
              style="width: 270px;"
              v-model="form.profession"
              :disabled="true"
            ></el-input>
          </div>
        </div>
        <div class="row">
          <div class="rowOne">
            <p class="rowName">门诊号:</p>
            <el-input
              placeholder="请输入内容"
              v-if="form.source == 1"
              v-model="form.admissionNumber"
              :disabled="true"
            ></el-input>
            <el-input
              placeholder="请输入内容"
              v-if="form.source == 2"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.admissionNumber"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.admissionNumber"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName">住院号:</p>
            <el-input
              placeholder="请输入内容"
              v-if="form.source == 2"
              v-model="form.admissionNumber"
              :disabled="true"
            ></el-input>
            <el-input
              placeholder="请输入内容"
              v-if="form.source == 1"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.admissionNumber"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.admissionNumber"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName">透析病案号:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.dialysisNo"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.dialysisNo"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.dialysisNo"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName">透析龄(月):</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.dialysis_age"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.dialysis_age"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.dialysis_age"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
        </div>
        <div class="row1">
          <div class="line">
            <p class="rowName">费别:</p>
            <div class="radioOne">
              <template>
                <el-radio v-model="form.expense_kind" label="1"
                  >基本医保</el-radio
                >
                <el-radio v-model="form.expense_kind" label="2"
                  >新农合</el-radio
                >
                <el-radio v-model="form.expense_kind" label="3"
                  >自费医疗</el-radio
                >
                <el-radio v-model="form.expense_kind" label="4"
                  >公费医疗</el-radio
                >
                <el-radio v-model="form.expense_kind" label="5"
                  >商业保险</el-radio
                >
                <el-radio v-model="form.expense_kind" label="6"
                  >军队医疗</el-radio
                >
                <el-radio v-model="form.expense_kind" label="7">其他</el-radio>
              </template>
            </div>
          </div>
        </div>
        <div class="row1">
          <div class="line">
            <p class="rowName">通信地址:</p>
            <el-input placeholder="请输入内容" :disabled="true"></el-input>
            <!-- <el-input placeholder="请输入内容" :disabled="true"></el-input>
            <el-input placeholder="请输入内容" :disabled="true"></el-input>-->
          </div>
          <div class="rowOne">
            <p class="rowName">具体地址:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.homeAddress"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.homeAddress"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.homeAddress"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
        </div>
        <div class="row">
          <div class="rowOne">
            <p class="rowName">联系人姓名:</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.contact_name"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.contact_name"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.contact_name"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName1">固定电话 &ensp;&ensp;&ensp;&ensp;(电话):</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.tell_phone"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.tell_phone"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.tell_phone"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
          <div class="rowOne">
            <p class="rowName1">联系电话 &ensp;&ensp;&ensp;&ensp;(电话):</p>
            <el-input
              placeholder="请输入内容"
              v-model="form.homeTelephone"
              :disabled="true"
            ></el-input>
            <!-- <div
              class="btn"
              v-clipboard:copy="form.homeTelephone"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
            >复制</div>-->
            <el-button
              type="primary"
              class="newCopy"
              v-clipboard:copy="form.homeTelephone"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制</el-button
            >
          </div>
        </div>
      </div>
    </div>
  <!-- </div> -->
</template>
<script>
import { getDataConfig } from "@/utils/data";
import { uParseTime,jsGetAge } from "@/utils/tools";
import { fetchPatient } from "@/api/patient";
import { fetchAllAdminUsers } from "@/api/doctor";
const defaultForm = {
  avatar: "",
  patientType: "",
  dialysisNo: "",
  admissionNumber: "",
  source: "",
  lapseto: "",
  partition: "",
  bed: "",
  name: "",
  gender: "",
  nation: "",
  native_place: "",
  maritalStatus: "",
  idCardNo: "",
  birth: "",
  age: "",
  reimbursementWayID: "",
  healthCareNo: "",
  healthCareDueDate: "",
  height: "",
  blood: "",
  rh: "",
  healthCareDueAlertDate: "",
  education: "",
  profession: "",
  phone: "",
  homeTelephone: "",
  homeAddress: "",
  work: "",
  receivingDate: "",
  firstDialysisDate: "",
  dialysisAge: "",
  induction: "",
  initial: "",
  dialysisTotal: "",
  contagions: [],
  doctor: "",
  nurse: "",
  assessment: "",
  diseases: [],
  diagnose: "",
  registrars: "",
  patient_complains: "",
  present_history: "",
  past_history: "",
  temperature: "",
  pulse: "",
  respiratory: "",
  sbp: "",
  dbp: "",
  record_date: "",
  response_result: "",
  is_infectious: "",
  formItem: [],
  tell_phone: "",
  first_treatment_date: "",
  dialysis_age: "",
  expense_kind: "",
  contact_name: "",
  create_time: "",
  id_type: "身份证"
};

export default {
  name: "One",
  components: {},

  data() {
    return {
      expenseOptions: [
        { id: 1, name: "基本医保" },
        { id: 2, name: "新农合" },
        { id: 3, name: "自费医疗" },
        { id: 4, name: "公费医疗" },
        { id: 5, name: "商业保险" },
        { id: 6, name: "军队医疗" },
        { id: 7, name: "其他" }
      ],
      form: Object.assign({}, defaultForm),
      adminUserOptions: [],
      maritalOptions: [],
      educationOptions: [],
      professionOptions: []
    };
  },
  created() {
    this.maritalOptions = getDataConfig("patient", "marital_options");
    this.educationOptions = getDataConfig("patient", "education_types");
    this.professionOptions = getDataConfig("patient", "profession_options");
    this.fetchAllAdminUsers();
  },
  methods: {
    getTime(val) {
      return uParseTime(val, "{y}年{m}月{d}日");
    },

    getZones() {
      getZones().then(response => {
        if (response.data.state === 1) {
          this.partitionOptions = response.data.data.zones;
        }
      });
    },
    fetchPatient(id) {
      fetchPatient(id)
        .then(response => {
          if (response.data.state === 1) {
            var patietInfo = response.data.data.patient;
            this.form.avatar = patietInfo.avatar;
            this.form.name = patietInfo.name;
            this.form.alias = patietInfo.alias;
            this.form.lapseto = patietInfo.lapseto;
            this.form.idCardNo = patietInfo.id_card_no;
            this.form.dialysisNo = patietInfo.dialysis_no;
            this.form.gender = patietInfo.gender;
            this.form.is_infectious = patietInfo.is_infectious;
            // this.form.record_date = patietInfo.is_infectious
            this.form.response_result = patietInfo.response_result;
            this.form.remind_cycle = patietInfo.remind_cycle;
            this.infections = response.data.data.infections;
            this.form.formItem = this.infections;
            if (patietInfo.gender === 1 || patietInfo.gender === 2) {
              this.form.gender = patietInfo.gender.toString();
            }
            this.form.nation = patietInfo.nation;
            this.form.native_place = patietInfo.native_place;
            this.form.birth = uParseTime(patietInfo.birthday, "{y}-{m}-{d}");
            this.form.create_time = uParseTime(
              patietInfo.created_time,
              "{y}-{m}-{d}"
            );

            this.form.firstDialysisDate = uParseTime(
              patietInfo.first_dialysis_date,
              "{y}-{m}-{d}"
            );
            this.form.height = patietInfo.height + "";
            if (patietInfo.marital_status > 0) {
              this.form.maritalStatus = patietInfo.marital_status;
            }
            this.form.children = patietInfo.children;
            this.form.admissionNumber = patietInfo.admission_number;
            if (patietInfo.reimbursement_way_id > 0) {
              this.form.reimbursementWayID = patietInfo.reimbursement_way_id;
            }
            this.form.healthCareNo = patietInfo.health_care_no;
            this.form.phone = patietInfo.phone;
            this.form.homeTelephone = patietInfo.home_telephone;
            this.form.relative_phone = patietInfo.relative_phone;
            this.form.relative_relations = patietInfo.relative_relations;
            this.form.homeAddress = patietInfo.home_address;
            this.form.work = patietInfo.work_unit;
            this.form.unit_address = patietInfo.unit_address;

              this.form.age = jsGetAge(this.form.birth, "-");

            if (patietInfo.profession > 0) {
              this.form.profession = patietInfo.profession;
            }
            if (patietInfo.education_level > 0) {
              this.form.education = patietInfo.education_level;
            }
            if (patietInfo.source === 1 || patietInfo.source === 2) {
              this.form.source = patietInfo.source;
            }
            console.log("source:" + this.form.source);
            if (patietInfo.lapseto === 1 || patietInfo.lapseto === 2) {
              this.form.lapseto = patietInfo.lapseto;
            }
            if (
              patietInfo.is_hospital_first_dialysis === 1 ||
              patietInfo.is_hospital_first_dialysis === 2
            ) {
              this.form.is_hospital_first_dialysis =
                patietInfo.is_hospital_first_dialysis;
            }
            if (patietInfo.first_dialysis_date !== 0) {
              this.form.firstDialysisDate = uParseTime(
                patietInfo.first_dialysis_date,
                "{y}-{m}-{d}"
              );
            }
            this.form.first_dialysis_hospital =
              patietInfo.first_dialysis_hospital;
            if (patietInfo.predialysis_condition.length > 0) {
              this.form.predialysis_condition = patietInfo.predialysis_condition.split(
                ","
              );
            }
            this.form.pre_hospital_dialysis_frequency =
              patietInfo.pre_hospital_dialysis_frequency;
            this.form.pre_hospital_dialysis_times =
              patietInfo.pre_hospital_dialysis_times;
            if (patietInfo.hospital_first_dialysis_date !== 0) {
              this.form.hospital_first_dialysis_date = uParseTime(
                patietInfo.hospital_first_dialysis_date,
                "{y}-{m}-{d}"
              );
            }
            this.form.contagions = response.data.data.contagions;
            this.form.diseases = response.data.data.diseases;
            this.form.remark = patietInfo.remark;
            this.form.diagnose = patietInfo.diagnose;

            this.form.patient_complains = patietInfo.patient_complains;
            this.form.present_history = patietInfo.present_history;
            this.form.past_history = patietInfo.past_history;
            this.form.temperature = patietInfo.temperature;
            this.form.pulse = patietInfo.pulse;
            this.form.respiratory = patietInfo.respiratory;
            this.form.sbp = patietInfo.sbp;
            this.form.dbp = patietInfo.dbp;

            this.form.contact_name = patietInfo.contact_name;
            this.form.tell_phone = patietInfo.tell_phone;
            this.form.dialysis_age = patietInfo.dialysis_age;
            if (patietInfo.expense_kind == 0) {
              this.form.expense_kind = "";
            } else {
              this.form.expense_kind = patietInfo.expense_kind.toString();
            }

            this.form.first_treatment_date = uParseTime(
              patietInfo.first_treatment_date,
              "{y}-{m}-{d}"
            );

            if (patietInfo.registrars_id > 0) {
              var eLen = this.adminUserOptions.length;
              for (let index = 0; index < eLen; index++) {
                if (
                  this.adminUserOptions[index].id === patietInfo.registrars_id
                ) {
                  this.form.registrars = this.adminUserOptions[index].name;
                  break;
                }
              }
            } else {
              this.form.registrars = "";
            }

            this.form.maritalStatus = this.getMaritalType(
              patietInfo.marital_status
            );
            this.form.education = this.getEducationType(
              patietInfo.education_level
            );
            this.form.profession = this.getProfessionType(
              patietInfo.profession
            );
          } else {
            console.log("patient get err state");
            // this.$notify.error({
            //   title: "错误",
            //   message: "网络异常"
            // });
          }
        })
        .catch(err => {
          // this.$notify.error({
          //   title: "错误",
          //   message: "网络异常"
          // });
        });
    },
    fetchAllAdminUsers() {
      fetchAllAdminUsers().then(response => {
        if (response.data.state === 1) {
          this.adminUserOptions = response.data.data.users;
        }
      });
    },
    getMaritalType(id) {
      for (let i = 0; i < this.maritalOptions.length; i++) {
        if (this.maritalOptions[i].id == id) {
          return this.maritalOptions[i].name;
        }
      }
    },
    getEducationType(id) {
      for (let i = 0; i < this.educationOptions.length; i++) {
        if (this.educationOptions[i].id == id) {
          return this.educationOptions[i].name;
        }
      }
    },
    getProfessionType(id) {
      for (let i = 0; i < this.professionOptions.length; i++) {
        if (this.professionOptions[i].id == id) {
          return this.professionOptions[i].name;
        }
      }
    },
    onCopy() {
      this.$message.success("复制成功");
    },
    onError() {
      this.$message.success("复制失败,请重试");
    }
  }
};
</script>

<style lang="scss">
// .app-container {
//   padding: 20px 0 20px 20px;
// }
.basicInfo {
  float: left;
  width: 100%;
  padding-left: 20px;
  .headline {
    height: 30px;
    line-height: 30px;
    margin-bottom: 10px;
  }
  .information {
    overflow: hidden;
  }
  .newCopy {
    margin-left: 6px !important;
  }
  .row {
    width: 100%;
    float: left;
    min-height: 56px;
    // overflow: hidden;
    .rowOne {
      float: left;
      height: 36px;
      width: 360px;
      // line-height: 36px;
      margin-right: 12px;
      margin-bottom: 20px;
    }
    .rowTwo {
      float: left;
      height: 36px;
      margin-right: 12px;
      margin-bottom: 20px;
      .btn {
        margin-right: 10px;
      }
    }
    .rowName {
      float: left;
      width: 76px;
      line-height: 36px;
      font-size: 12px;
    }
    .rowName1 {
      float: left;
      width: 76px;
      margin-top: 5px;
      font-size: 12px;
    }
    .el-input {
      float: left;
      width: 130px;
    }
    .btn {
      width: 50px;
      height: 36px;
      line-height: 36px;
      color: #fff;
      background-color: #409eff;
      float: left;
      font-size: 12px;
      text-align: center;
      border-radius: 4px;
      margin-left: 6px;
    }
    .radioOne {
      float: left;
      height: 36px;
      line-height: 36px;
      // margin-right: 76px;
    }
    .line {
      height: 56px;
    }
  }
  .row1 {
    width: 100%;
    // display: block;
    // height: 56px;
    float: left;
    .line {
      float: left;
      // height: 56px;
    }
    .rowName {
      float: left;
      width: 76px;
      line-height: 36px;
      font-size: 12px;
    }
    .radioOne {
      float: left;
      height: 56px;
      line-height: 36px;
    }
    .el-input {
      float: left;
      width: 130px;
      margin-right: 10px;
    }
    .rowOne {
      float: left;
      height: 36px;
      width: 300px;
      // line-height: 36px;
      margin-right: 12px;
      margin-bottom: 20px;
      .el-input {
        margin-right: 0;
      }
    }
    .btn {
      width: 50px;
      height: 36px;
      line-height: 36px;
      color: #fff;
      background-color: #409eff;
      float: left;
      font-size: 12px;
      text-align: center;
      border-radius: 4px;
      margin-left: 6px;
    }
  }
}
</style>
