<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='dialysisPage' style="padding-top:40px;">
      <printOne :list="list" :patient="patient" :order="order" :admin="admin"></printOne>
    </div>
  </div>
</template>

<script>
  import printOne from './listTemplate/printOne'
  import { getHisOrderDetail } from '@/api/his/his'
  import { uParseTime } from '@/utils/tools'

  export default {
    name: 'listPrint',
    components: {
      printOne
    },
    props: {
      paramsObj: Object
    },
    data() {
      return {
        list: [],
        patient:{},
        order:{},
        admin:{},
      }
    },
    created() {
      this.getInfo(this.paramsObj.id)
    },

    methods: {
      getTimes(time) {
        return uParseTime(time, '{y}-{m}-{d} {h}:{i}')
      },
      getInfo(order_id) {
        let params = {
          id: order_id
        }
        getHisOrderDetail(params).then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg)
            return false
          } else {
            this.order = response.data.data.order
            this.patient = response.data.data.patient
            console.log(this.patient)
            this.admin = response.data.data.admin_info


            for (let i = 0; i < response.data.data.order_info.length; i++) {
              var infos = response.data.data.order_info[i]
              let obj = {
                med_chrgitm_type: this.getType(infos.med_chrgitm_type),
                price: infos.pric,
                count: infos.cnt
              }
              console.log(infos)
              if (infos.advice && infos.advice.id == 0 && infos.project && infos.project.id > 0) {
                obj['p_time'] = this.getTimes(infos.project.prescription.ctime)
                if(infos.project.type == 2){
                  obj['name'] = infos.project.project.project_name


                }else if (infos.project.type == 3){

                  obj['name'] = infos.project.good_info.good_name

                }
                obj['spec'] = 1
                obj['unit'] = infos.project.unit

              }

              if (infos.advice && infos.advice.id > 0 && infos.project && infos.project.id == 0) {
                obj['p_time'] = this.getTimes(infos.advice.prescription.ctime)
                obj['name'] = infos.advice.advice_name
                obj['spec'] = infos.advice.drug.drug_spec
                obj['unit'] = infos.advice.drug.max_unit

              }
              this.list.push(obj)
              this.list.sort(function(a, b) {
                return b.p_time < a.p_time ? 1 : -1
              })

            }
          }
        })
      },

      getType(med_chrgitm_type) {
        switch (med_chrgitm_type) {
          case '01':
            return '床位费';
            break;
          case '02':
            return '诊察费';

            break;
          case '03':
            return '检查费';

            break;
          case '04':
            return '化验费';
            break;
          case '05':
            return '治疗费';

            break;
          case '06':
            return '手术费';

            break;
          case '07':
            return '护理费';

            break;
          case '08':
            return '材料费';

            break;
          case '09':
            return '西药费';

            break;
          case '10':
            return '中药饮片费';

            break;
          case '11':
            return '中成药费';

            break;
          case '12':
            return '一般诊疗费';

            break;
          case '13':
            return '挂号费';

            break;
          case '14':
            return '其他费';

            break

        }

      },
      printThisPage() {

        const style =
          '@media print {.listTitle{font-size: 24px;text-align: center;font-weight: bold;margin-bottom: 10px;}.listInfo{display: flex;font-size: 16px;justify-content: space-between;margin: 10px 0;} .listTable{width: 100%;text-align: center;border-collapse: collapse;line-height: 40px;font-size: 14px;border-color: #000;text-align:left;}.listTable tr td {padding: 0 5px;}.tableBottom{font-size: 16px;display: flex;margin-top: 20px;}.tableBottomOne{margin-right: 40px;}}';
        printJS({
          printable: 'list-print',
          type: 'html',
          style: style,
          scanStyles: false
        })

        // if (this.org_template_info.template_id == 1) {
        //   printJS({
        //     printable: "dialysis-print-box",
        //     type: "html",
        //     style: style,
        //     scanStyles: false
        //   });
        // }
      }
    }

  }
</script>

<style>
  .dialysis-print-order {
    width: 960px;
    margin: 0 auto;
  }

  .dialysis-print-order .order-yy-name {
    margin: auto;
    text-align: center;
    font-size: 20px;
    letter-spacing: 5px;
  }

  .dialysis-print-order .order-title {
    margin: auto;
    font-weight: 600;
    text-align: center;
    font-size: 22px;
    padding: 10px;
  }

  .dialysis-print-order .table-box {
    width: 100%;
    line-height: 23px;
    font-size: 14px;
  }

  .dialysis-print-order .print-table {
    width: 100%;
    text-align: center;
    border-collapse: collapse;
    line-height: 40px;
    font-size: 14px;
    border-color: #000;
  }

  .dialysis-print-order .print-table-no {
    width: 100%;
    text-align: center;
    border-collapse: collapse;
    font-size: 14px;
  }

  .dialysis-print-order .under-line {
    border-bottom: 1px solid #999;
    width: 95%;
    text-align: center;
    margin-left: 2px;
  }

  .dialysis-print-order .title-box {
    text-align: center;
    font-size: 16px;
  }

  .dialysis-print-order .radio-lebel-box {
    font-weight: 400;
    cursor: pointer;
  }

  .dialysis-print-order .radio-no {
    opacity: 0;
    outline: none;
    position: absolute;
    margin: 0;
    width: 0;
    height: 0;
    z-index: -1;
  }

  .dialysis-print-order .radio-inner {
    white-space: nowrap;
    cursor: pointer;
    outline: none;
    display: inline-block;
    line-height: 1;
    position: relative;
    vertical-align: middle;
  }

  .dialysis-print-order .radio-fang {
    display: inline-block;
    position: relative;
    border: 1px solid #000;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    background-color: #fff;
    z-index: 1;
    transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
    background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
  }

  .dialysis-print-order .is-checked-radio::after {
    content: "√";
    font-size: 15px;
  }

  .dialysis-print-order .print-table-no tr td {
    padding: 8px 5px;
    line-height: 25px;
  }

  .dialysis-print-order .print-table tr td {
    padding: 1px 1px;
    /*line-height: 25px;*/
  }

  .es-img {
    height: 30px;
  }

  .advice-name {
    text-align: left;
  }

  .advice-children {
    display: flex;
  }

  .title-box-pro {
    border: 0 #fff;
    line-height: 25px;
    height: 25px;
    text-align: left;
    padding-left: 10px !important;
  }

  .title-box-pro-tr {
    border: 0 #fff;
  }

  .text-align-left {
    text-align: left !important;
    padding-left: 10px !important;
    font-size: 14px !important;
    line-height: 25px;
  }

  .print-table-tr-new td {
    line-height: 20px !important;
  }

  .border-top-solid {
    border: solid 1px #000;
  }

  .print-template-two tr {
    line-height: 30px;
  }

  .table-box1 {
    border: 1px solid #000;
    width: 100%;
    line-height: 30px;
    font-size: 14px;
    border-collapse: collapse;
  }

  .table-box1 tr {
    border-bottom: 1px solid #000;
  }
</style>

<style lang="scss">

  .newContainer {

  .dialysisPage::-webkit-scrollbar {
    height: 15px;
  }

  .el-date-editor {

  .el-input__inner {
    padding-right: 0px;
  }

  }
  .el-table td, .el-table th {
    text-align: center;
  }

  }
  .newContainer::-webkit-scrollbar {
    height: 15px !important;
  }
</style>
