<template>
  <el-dialog
    title="打印"
    :visible.sync="visibility"
    :close-on-click-modal="isClose"
    :close-on-press-escape="isClose"
  >
    <el-button type="primary" @click="print" class="print_style"
      >打印</el-button
    >
    <div id="dialysis-print-box-1" class="dialysis-print-box-1">
       <div class="list_title" style="border-bottom:none;"><div style="width:100%;text-align:center;font-size:16px;font-weight:bold;">{{org_name}} <span v-if="state=='待发药'">发药单</span> <span v-if="state=='已发药'">领药单</span></div></div>
      <div class="list_title">
        <div>患者名称：{{name}}</div>
        <div>发药状态：{{state}}</div>
        <div>日期：{{times}}</div>
      </div>

      <el-table
        style="width: 940px; margin: 0 auto"
        :data="tableData"
        border
        max-height="450"
        :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)' }"
      >
        <el-table-column type="index" prop="index" label="序号" width="60" align="center">
        </el-table-column>
        <el-table-column prop="name" label="名称" width="160" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.Name ? scope.row.Name : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="SingleDosage" label="单次用量" width="120" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.SingleDosage ? scope.row.SingleDosage : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="use" label="用法" width="120" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.Usage ? scope.row.Usage : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="frequency" label="频率" width="120" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.Frequency ? scope.row.Frequency : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="day" label="天数" width="120" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.Days ? scope.row.Days : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="总量" width="120" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.Total ? scope.row.Total : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="tips" label="数据来源" width="120" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.DataSources ? scope.row.DataSources : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="tips" label="备注" width="120" align="center">
          <template slot-scope="scope" >
            <span>{{scope.row.Remarks ? scope.row.Remarks : ""}}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-dialog>
</template>
<script>
import Vue from "vue";
import print from "print-js";
import printutils from "./print.js";

export default {
  data() {
    return {
      visibility: false,
      tableData: [],
      isClose:false,
      name:"",
      state:null,
      times:"",
      org_name: this.$store.getters.xt_user.org.org_name,
    };
  },
  props: {
    propForm: {
      type: Object,
    },
  },
  created(){
    this.init();
  },
  methods: {
    // isClose() {
    //   this.visibility = false;
    // },
    init(){
      // let year = new Date().getFullYear();
      // let month = new Date().getMonth() +1;
      // let day = new Date().getDate();
      // let hour = new Date().getHours();
      // let minute = new Date().getMinutes();
      // this.times = year + "年" + month + "月" + day + "日" + hour + "时" + minute + "分"
      // console.log("times:",this.times)
    },

    hide: function () {
      this.visibility = false;
      for (let i = 0; i < this.propForm.goods.length; i++) {
        for (let key in this.propForm.goods[i]) {
          if (key != "index") {
            this.propForm.goods[i][key].isSelected = false;
          }
        }
      }
    },
    show: function (val,data,state,times) {
      this.times = times
      this.visibility = true;
      console.log("val",val)
      this.tableData = val
      this.name = data.Name
      if (state == 1){
        this.state = "待发药"
      }
      if (state == 2){
        this.state = "已发药"
      }

    },

    comfirm: function (formName) {
      this.goodInfo = [];
      this.goodInfoTableData = [];
      this.$emit("dialog-comfirm", this.getValue());
      this.$refs.multipleTable.clearSelection();
      this.$refs.table.setCurrentRow(null);
    },
    getValue() {},

    // 打印
    print() {
      console.log(this.org_name,'this.org_name')
      Vue.prototype.printJson = printutils.printJson;
      //   const style =
      //     '@media print {.list_title{  width: 940px;border-bottom: 1px solid;display: flex;margin: 30px auto}}';
      //   printJS({
      //     printable: "dialysis-print-box-1",
      //     type: "html",
      //     style: style,
      //     scanStyles: false,
      //   });
      this.printJson({
        title: `
        <div>
        <div style="width: 940px;text-align:center;font-size:16px;font-weight:bold;">${this.org_name} 发药单</div>
        <div style="width: 940px;border-bottom: 1px solid;display: flex;margin: 30px auto;font-size:14px;">
        <div style="width: 310px;padding: 10px 0;">患者名称：${this.name}</div>
        <div style="width: 320px;padding: 10px 0;">发药状态：${this.state}</div>
        <div style="width: 310px;padding: 10px 0;">日期：${this.times}</div>
        </div></div>`, // 打印出来的标题
        data: this.tableData, // 需要打印的数据
        serial: true, // 是否需要打印序列号
        fields: [
          // 需要打印的字段

          "Name",
          "SingleDosage",
          "Usage",
          "Frequency",
          "Days",
          "Total",
          "DataSources",
          "Remarks",
        ],
        properties: [
          // 需要打印的字段对应的表头名

          {
            field: "Name",
            displayName: "名称",
          },
          {
            field: "SingleDosage",
            displayName: "单次用量",
          },
          {
            field: "Usage",
            displayName: "用法",
          },
          {
            field: "Frequency",
            displayName: "频率",
          },
          {
            field: "Days",
            displayName: "天数",
          },
          {
            field: "Total",
            displayName: "总量",
          },
          {
            field: "DataSources",
            displayName: "数据来源",
          },
          {
            field: "Remarks",
            displayName: "备注",
          },
        ],
      });
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/ .el-dialog{
  width: 60%;
}
/deep/ .el-table__body-wrapper::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.print_style {
  position: absolute;
  right: 65px;
  top: 50px;
}

.list_title {
  width: 940px;
  border-bottom: 1px solid;
  display: flex;
  margin: 30px auto;

  div {
    width: 320px;
    padding: 10px 0;
  }
}

</style>

<style>
.sign-and-weigh-box .sign-and-weigh-box-patients .cell {
  font-size: 12px;
}

.sign-and-weigh-box .sign-and-weigh-box-patients .current-row > td {
  background: #6fb5fa;
}

.count {
  color: #bd2c00;
}
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}
</style>
