<template>
  <div>
    <template>
      <el-button
        style="position:fixed;right:25px;z-index:999"
        :loading="loading"
        size="small"
        icon="el-icon-printer"
        @click="printThisPage"
        type="primary"
        >打印</el-button
      >
    </template>
    <div class="app-container" style="padding-top:40px;">
        <div class='dialysisPage'>
            <printOne v-bind:childResponse="childResponse" :info="info" :p_admin="p_admin" :charge_admin="charge_admin" :paramsObj="paramsObj"></printOne>
        </div>
    </div>
  </div>
</template>

<script>

import { jsGetAge, uParseTime } from "@/utils/tools";
// import LabelBox from "./printItem/LabelBox";
import print from "print-js";
import printOne from "./settlementTemplate/printOne"
import axios from 'axios'
export default {
  name: "dialysisPrintOrder",
  components: {
    printOne
  },
  props:{
    paramsObj:Object
  },
  data() {
    return {
      crumbs: [
        { path: false, name: "透析管理" },
        { path: false, name: "打印单" }
      ],
      childResponse: {},
      paramsObj:{},
      info:null,
      p_admin:{},
      charge_admin:{},

    };
  },
  methods: {
    getAdminUser(id) {
      if (id == 0) {
        return "";
      }
      if (id == undefined) {
        return "";
      }
      for (let i = 0; i < this.adminUser.length; i++) {
        if (this.adminUser[i].id == id) {
          return this.adminUser[i].name;
        }
      }
    },
    getTime(value, temp) {
      if (value == 0) {
        return "";
      }
      if (value != undefined) {
        return uParseTime(value, temp);
      }
      return "";
    },
    printThisPage() {
      var ptime = Math.round(new Date().getTime() / 1000);
      this.print_time = uParseTime(ptime, "{y}-{m}-{d} {h}:{i}");

      const style =
        '@media print {.printTitle{font-size: 22px;text-align: center;font-weight: bold;}.infoMain{display: flex;flex-wrap: wrap;padding:0 10px;margin-top:10px;}.infoMain .infoP{width: 33%;}.chargeBox{border: 1px solid #000;}.chargeUl{display:flex;justify-content: space-between;text-align: center;}.chargeUl p{line-height: 1px;}.chargeP{line-height: 1px;padding-bottom:16px;}.moneyBox{display: flex;justify-content: space-between;padding: 0 10px;background: #eeeeee;-webkit-print-color-adjust:exact;-moz-print-color-adjust:exact;-ms-print-color-adjust:exact;print-color-adjust:exact;height: 40px;align-items: center;border:1px solid #000; border-top:none}.actionBar{display: flex;justify-content: space-between; line-height: 24px;padding:0 10px;}.actionBar div{width:150px;}}';
        const style1 = "@media print{#prescription-print{font-size:14px;}.title{text-align: center;font-size: 22px;font-weight: bold;}.row{display: flex;justify-content: space-between;}.under_line{border-bottom: 1px solid #999;width: 95%;text-align: center;margin-left: 2px;display: inline-block;}.inline_block{display: inline-block;}.print_page_main_content .proj_table {width: 100%;border: 1px solid;border-collapse: collapse;padding: 2px;}.print_page_main_content .proj_table tbody tr td {border: 1px solid;font-size: 14px;padding: 5px 8px;line-height: 30px;}.print_page_main_content .proj_table .inside_table {width: 100%;border: hidden; /* 解决边框冲突 */border-collapse: collapse;}.print_page_main_content .proj_table .inside_table tr td {border: 1px solid;text-align: center;font-size: 14px;padding: 6px 5px;line-height: 16px;}}";
        printJS({
            printable: "prescription-print",
            type: "html",
            style: style1,
            scanStyles: false
        });

      // if (this.org_template_info.template_id == 1) {
      //   printJS({
      //     printable: "dialysis-print-box",
      //     type: "html",
      //     style: style,
      //     scanStyles: false
      //   });
      // }
    },
    getAllDoctorList(){
      getAllDoctorList().then(response=>{
        if(response.data.state == 1){
               var doctor =  response.data.data.doctor;

               this.doctorList = doctor
             }
         })
     },
    getAllHisPatientList(){
         const params = {
           record_date:this.record_date
         };
      getAllHisPatientList(params).then(response=>{
         if(response.data.state == 1){
            this.patientTableData = response.data.data.list;
            this.patientTableDataTwo = response.data.data.list;

            console.log('222', this.patientTableData);
            let cal_one = 0;
            let cal_two = 0;
            for (let i = 0; i < response.data.data.list.length; i++) {
              if (response.data.data.list[i].prescription == null || response.data.data.list[i].prescription.length == 0) {
                cal_one = cal_one + 1
              }
              if (response.data.data.list[i].prescription != null && response.data.data.list[i].prescription.length > 0) {
                cal_two = cal_two + 1
              }
            }
            // this.$refs.tab.setCurrentRow(this.patientTableData[0])
            // console.log(this.patientTableData[0])
            // this.choosePatient(this.patientTableData[0])
            this.cal_one = cal_one;
            this.cal_two = cal_two
         }
      })
    },

    changePatient(row){
      console.log("row",row);
      this.patient_id = row.patient_id;
      this.record_date = this.record_date;
      this.prescription_id = this.prescription_id
      //   var params = {
      //     patient_id:row.patient_id,
      //     record_date:this.record_date,
      //     prescription_id:this.prescription_id,
      //   }
      // getPrescriptionPrint(params).then(response=>{
      //     if(response.data.state == 1){
      //       var advicePrint =  response.data.data.advicePrint
      //       console.log("adviceprint",advicePrint)
      //       this.advicePrint = advicePrint
      //       // var hisPatient =  response.data.data.hisPatient
      //       // console.log("hispatient",hisPatient)
      //       // this.hisPatient = hisPatient
      //       var patient =  response.data.data.patient
      //       console.log("patient",patient)
      //       this.patient = patient
      //       var doctorPorject = response.data.data.doctorPorject
      //       console.log("doctorporject",doctorPorject)
      //     }
      // })
    },
    searchAction(){

    },
    getInfo(order_id) {

        var that = this;

        axios.get('http://127.0.0.1:9532/api/settle/query', {
          params: {
            order_id: order_id,
            admin_user_id:this.$store.getters.xt_user.user.id,

          }
        })
          .then(function (response) {
            if (response.data.state == 0) {
              this.$message.error(response.data.msg);
              return false
            } else {
              console.log("logloglog");

              console.log(response.data.data.info);
              that.info = response.data.data.info;
              that.p_admin = response.data.data.printor_admin;
              that.charge_admin = response.data.data.charge_admin;
              console.log(that.info);


              // that.info['bed_cost_total'] = response.data.data.bedCostTotal


              that.info['bed_cost_total'] = response.data.data.bedCostTotal;
              that.info['bed_cost_self_total'] = response.data.data.bedCostSelfTotal;
              that.info['bed_cost_part_self_total'] = response.data.data.bedCostPartSelfTotal;

              that.info['operation_cost_total'] = response.data.data.operationCostTotal;
              that.info['operation_cost_self_total'] = response.data.data.operationCostSelfTotal;
              that.info['operation_cost_part_self_total'] = response.data.data.operationCostPartSelfTotal;

              that.info['other_cost_total'] = response.data.data.otherCostTotal;
              that.info['other_cost_self_total'] = response.data.data.otherCostSelfTotal;
              that.info['other_cost_part_self_total'] = response.data.data.otherCostPartSelfTotal;

              that.info['material_cost_total'] = response.data.data.materialCostTotal;
              that.info['material_cost_self_total'] = response.data.data.materialCostSelfTotal;
              that.info['material_cost_part_self_total'] = response.data.data.materialCostPartSelfTotal;

              that.info['western_medicine_cost_total'] = response.data.data.westernMedicineCostTotal;
              that.info['western_medicine_cost_self_total'] = response.data.data.westernMedicineCostSelfTotal;
              that.info['western_medicine_cost_part_self_total'] = response.data.data.westernMedicineCostPartSelfTotal;

              that.info['chinese_traditional_medicine_cost_total'] = response.data.data.chineseTraditionalMedicineCostTotal;
              that.info['chinese_traditional_medicine_cost_self_total'] = response.data.data.chineseTraditionalMedicineCostSelfTotal;
              that.info['chinese_traditional_medicine_cost_part_self_total'] = response.data.data.chineseTraditionalMedicineCostPartSelfTotal;


              that.info['check_cost_total'] = response.data.data.checkCostTotal;
              that.info['check_cost_self_total'] = response.data.data.checkCostSelfTotal;
              that.info['check_cost_part_self_total'] = response.data.data.checkCostPartSelfTotal;


              that.info['laboratory_cost_total'] = response.data.data.laboratoryCostTotal;
              that.info['laboratory_cost_self_total'] = response.data.data.laboratoryCostSelfTotal;
              that.info['laboratory_cost_part_self_total'] = response.data.data.laboratoryCostPartSelfTotal;

              that.info['treat_cost_total'] = response.data.data.treatCostTotal;
              that.info['treat_cost_self_total'] = response.data.data.treatCostSelfTotal;
              that.info['treat_cost_part_self_total'] = response.data.data.treatCostPartSelfTotal;
              that.info['date'] =  response.data.data.date;
              that.info['number'] =  response.data.data.number;
              that.info['order_infos'] =  response.data.data.order_infos;
              that.info['diagnosis'] =  response.data.data.diagnosis

            }
          })
          .catch(function (error) {

          });
    }
  },
  created() {
    this.getInfo(this.paramsObj.order_id);
    this.org_id = this.$store.getters.xt_user.org_id
  },
  watch:{
    paramsObj:{//深度监听，可监听到对象、数组的变化
      handler(val, oldVal){
        this.paramsObj = val;
        this.getInfo(this.paramsObj.order_id)

      },
      deep:true
    }
  }
};
</script>

<style lang="scss" scoped>
.printTitle{
    font-size: 22px;
    text-align: center;
    font-weight: bold;
}
.infoMain{
    display: flex;
    flex-wrap: wrap;
    border-bottom: 2px solid #000;
    padding:0 10px;
}
.infoMain .infoP{
    width: 33%;
    line-height: 24px;
}
.prescriptionBox{
    padding:0 10px;
    height:600px;
}
.Rp{
    font-size: 22px;
    font-weight: bold;
}
.drugsBox{
    padding-left: 40px;
    margin-bottom: 10px;
}
.drugsBox p{
    line-height: 30px;
}
.drugsOne{
    line-height: 24px;
}
.drugsOne span{
    margin-right: 20px;
}
.doctorBox{
    display: flex;
    justify-content: space-between;
    padding:0 10px;
    line-height: 24px;
    border-bottom: 2px solid #000;
}
.actionBar{
    display: flex;
    justify-content: space-between;
    line-height: 24px;
    padding:0 10px;
}
.actionBar p{
    width:150px;
}
</style>
