<template>
  <div id="prescription-print">
    <div class="prescription-print">
      <div class="printTitle">{{ orgname }}血透中心病历</div>
      <!-- <div class="record_Title">
            <div>姓名：{{patient.name?patient.name:''}}</div>
            <div>性别：
                <span v-if="patient.gender == 1">男</span>
                <span v-if="patient.gender == 2">女</span>
            </div>
            <div>年龄：{{patient.age?patient.age:''}}岁</div>
            <div>透析病历号:{{patient.id?patient.id:''}}</div>
        </div> -->
      <div class="infoTitle" style="margin-top: 20px">
        <div class="name_slot">
          姓名：{{ patient.name ? patient.name : "" }}
        </div>
        <div class="address_slot">
          家庭住址：{{ patient.home_address ? patient.home_address : "" }}
        </div>
      </div>
      <div class="infoTitle">
        <div class="name_slot">
          性别：
          <span v-if="patient.gender == 1">男</span>
          <span v-if="patient.gender == 2">女</span>
        </div>
        <div class="address_slot">工作单位：{{ patient.work_unit }}</div>
      </div>
      <div class="infoTitle">
        <div class="name_slot">
          出生日期：{{ patient.id_card_no.slice(6, 10) }}年{{
            patient.id_card_no.slice(10, 12)
          }}月{{ patient.id_card_no.slice(12, 14) }}日
        </div>
        <div class="address_slot">身份证号：{{ patient.id_card_no }}</div>
      </div>
      <div class="infoTitle">
        <div class="name_slot">联系人：{{ patient.contact_name }}</div>
        <div class="address_slot">
          联系电话：{{ patient.phone ? patient.phone : "" }}
        </div>
      </div>
      <div class="otherInfo" style="border-bottom: 1px solid">
        <div>进入透析时间：{{ getTime(patient.first_dialysis_date) }}</div>
        <div style="flex: 1"></div>
      </div>
      <div class="infoTitle">
        <div style="width: 300px">原发病：{{ history.primary_disease }}</div>
        <div class="address_slot">
          确诊肾衰日期：{{ getTime(history.confirm_failure_date) }}
        </div>
      </div>
      <div class="otherInfo">
        <div>
          药物过敏史：{{
            history.allergic_history ? history.allergic_history : ""
          }}
        </div>
      </div>
      <div class="otherInfo">
        <div>初始透析日期：{{ getTime(patient.first_dialysis_date) }}</div>
        <div style="flex: 1"></div>
      </div>
      <div class="otherInfo" style="border-bottom: 1px solid">
        <div>血管通路：{{ accessList.blood_access_part_opera_id }}</div>
        <div style="flex: 1"></div>
      </div>

      <div class="otherInfo" style="min-height: 60px">
        <div class="otherName">主诉：</div>
        <div style="flex: 1">
          {{ history.chief_conplaint ? history.chief_conplaint : "" }}
        </div>
      </div>

      <div class="otherInfo" style="min-height: 180px">
        <div class="otherName">现病史：</div>
        <div style="flex: 1">
          {{
            history.history_of_present_illness
              ? history.history_of_present_illness
              : ""
          }}
        </div>
      </div>

      <div class="otherInfo" style="min-height: 100px">
        <div class="otherName">既往史：</div>
        <div style="flex: 1">
          {{ history.past_history ? history.past_history : "" }}
        </div>
      </div>

      <div class="otherInfo" style="min-height: 80px">
        <div class="otherName">个人史：</div>
        <div style="flex: 1">
          {{ history.personal_history ? history.personal_history : "" }}
        </div>
      </div>
 
      <div class="otherInfo" style="min-height: 150px">
        <div class="otherName">家族史：</div>
        <div style="flex: 1">
          {{ history.family_history ? history.family_history : "" }}
        </div>
      </div>
    </div>
    <div style="page-break-after: always; margin-top: 50px"></div>
    <div class="prescription-print">
      <!-- <div class="printTitle">病历内容</div> -->
      <div class="recordTitle">
        <div>体格检查</div>
        <div class="recordContent" style="height: fit-content;min-height: 250px;">
          <div>
            <span
              >体温：{{
                history.temperature ? history.temperature + "℃" : "/"
              }}</span
            >
            <span
              >脉搏：{{ history.pulse ? history.pulse + "次/分" : "/" }}</span
            >
            <span
              >呼吸：{{
                history.breathing ? history.breathing + "次/分" : "/"
              }}</span
            >
            <span>血压：{{ history.sbp }}/{{ history.dbp }}mmHg</span>
          </div>
           <div style="text-align:left;">
          {{history.physical_examination}}
        </div>
        </div>

      </div>
      <div class="recordTitle">
        <div>专科检查</div>
        <div class="recordContent">{{ history.special_inspection }}</div>
      </div>
      <div class="recordTitle" style="border-bottom: 1px solid">
        <div>实验室及器械检查</div>
        <div class="recordContent" style="height: fit-content;min-height: 250px;">
          {{ history.lab_apparatus }}
        </div>
      </div>
      <div style="display: flex; justify-content: flex-end">
        <div class="endInfo">
          <div style="height: 100px">
            诊断：{{ history.diagnostic ? history.diagnostic : "" }}
          </div>
          <div style="display: flex">
            <div>
              医师：{{
                getDoctor(history.doctor) ? getDoctor(history.doctor) : ""
              }}
            </div>
            <div>手签：</div>
          </div>
          <div
            style="text-align: center; letter-spacing: 3px; padding-top: 20px"
          >
            {{ getTime(history.record_date) }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { jsGetAge, uParseTime } from "@/utils/tools";

import { getDataConfig } from "@/utils/data";
import { getAllDoctorList, getPatientCaseHistory } from "@/api/project/project";
import { getAccessList } from "@/api/patient";
export default {
  props: {
    patient: Object,
    hispatient: Object,
    patientid: Number,
    //   history:Object,
  },
  data() {
    return {
      educationOptions: [],
      departmentList: [],
      orgname: "",
      history: {},
      printDate: "",
      accessList: {},
      blood_access_part_opera: [],
    };
  },


  methods: {
    getAge(patient) {
      var thisLen = patient.id_card_no.length;
      var birth = "";
      if (thisLen == 15) {
        birth = "19" + patient.id_card_no.substr(6, 6);
      } else {
        birth = patient.id_card_no.substr(6, 8);
      }
      var births =
        birth.substr(0, 4) +
        "-" +
        birth.substr(4, 2) +
        "-" +
        birth.substr(6, 2);
      return jsGetAge(births, "-");
    },
    show(val) {
      this.patientid = val;
      this.getAllDoctorList();
      this.getPatientCaseHistory();
    },
    getProfession(id) {
      var name = "";
      for (let i = 0; i < this.educationOptions.length; i++) {
        if (id == this.educationOptions[i].id) {
          name = this.educationOptions[i].name;
        }
      }
      return name;
    },
    getAllDoctorList() {
      getAllDoctorList().then((response) => {
        if (response.data.state == 1) {
          var doctor = response.data.data.doctor;

          this.doctorList = doctor;
          var department = response.data.data.department;
          this.departmentList = department;
        }
      });
    },
    getDoctor(id) {
      var name = "";
      for (let i = 0; i < this.doctorList.length; i++) {
        if (id == this.doctorList[i].admin_user_id) {
          name = this.doctorList[i].user_name;
        }
      }
      return name;
    },
    getPatientCaseHistory() {
      const params = {
        patient_id: this.patientid,
      };
      getPatientCaseHistory(params).then((response) => {
        if (response.data.state == 1) {
          var patient = response.data.data.patient;
          this.patient = patient;
          var history = response.data.data.history;
          this.history = history;
          var hispatient = response.data.data.hispatient;
          this.hispatient = hispatient;
          var accessList = response.data.data.accessList;
          this.accessList = accessList;
        }
      });
    },
    getDeparment(id) {
      var name = "";
      for (let i = 0; i < this.departmentList.length; i++) {
        if (id == this.departmentList[i].id) {
          name = this.departmentList[i].name;
        }
      }
      return name;
    },
    getTime(val) {
      if (val < 0) {
        return "";
      }
      if (val == "") {
        return "";
      } else {
        return uParseTime(val, "{y}-{m}-{d}");
      }
    },
    getAccessList() {
      getAccessList().then((response) => {
        if (response.data.state == 1) {
          var blood_access_part_opera =
            response.data.data.blood_access_part_opera;
          this.blood_access_part_opera = blood_access_part_opera;
        }
      });
    },
    getAccess(id) {
      var name = "";
      for (let i = 0; i < this.blood_access_part_opera.length; i++) {
        if (id == this.blood_access_part_opera[i].value) {
          name = this.blood_access_part_opera[i].name;
        }
      }
      return name;
    },
  },
  created() {
    this.educationOptions = getDataConfig("patient", "education_types");
    // this.getAllDoctorList();
    // this.getPatientCaseHistory();
    // this.getAccessList();
    var xtuser = this.$store.getters.xt_user;
    this.orgname = xtuser.org.org_name;
    var data = new Date();
    var month =
      data.getMonth() < 9 ? "0" + (data.getMonth() + 1) : data.getMonth() + 1;
    var date = data.getDate() <= 9 ? "0" + data.getDate() : data.getDate();
    this.printDate = data.getFullYear() + "-" + month + "-" + date;
  },
};
</script>


<style lang="scss" scoped>
.prescription-print {
  -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27),
    0 0 60px rgba(0, 0, 0, 0.06) inset;
  -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27),
    0 0 40px rgba(0, 0, 0, 0.06) inset;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
  margin-bottom: 20px;
  padding: 20px 10px;
}
.printTitle {
  font-size: 22px;
  text-align: center;
  font-weight: bold;
}
.infoTitle {
  display: flex;
  margin-top: 10px;
  line-height: 24px;
  padding: 0 10px;
}
.infoTitle div {
  width: 200px;
}

.infoTitle .address_slot {
  width: 400px;
}
.infoTitle .name_slot {
  width: 250px;
}

.otherInfo {
  display: flex;
  margin-top: 10px;
  line-height: 24px;
  padding: 0 10px;
}
.endInfo {
  display: flex;
  flex-direction: column;
  justify-content: end;
  margin-top: 10px;
  line-height: 24px;
}
.endInfo div {
  width: 300px;
}
.recordTitle {
  display: flex;
  justify-content: center;
  flex-direction: column;
  margin-top: 10px;
  line-height: 24px;
  padding: 0 10px;
  border-top: 1px solid;
}
.recordTitle div {
  width: 100%;
  text-align: center;
}
.recordTitle .recordContent {
  width: 100%;
  height: fit-content;
  min-height: 150px;
  text-align: left;
}

.record_Title {
  display: flex;
  margin-top: 10px;
  line-height: 24px;
  padding: 0 10px;
  border-bottom: 2px solid #000;
}

.record_Title div {
  width: 200px;
}
</style>
