<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_name=='待发药'">发药单</span> <span v-if="state_name=='已发药'">领药单</span></div></div>
      <div class="list_title">
        <div>药品名称：{{name}}</div>
        <div>规格：{{specifications}}</div>
        <div>发药状态：{{state_name}}</div>
        <div>日期：{{times}}</div>
<!--  <div v-if="state==2">领药人：</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">
            {{scope.row.name}}
          </template>
        </el-table-column>
        <el-table-column prop="single_dosage" label="单次用量" width="120" align="center">
          <template  slot-scope="scope">
            {{scope.row.single_dosage}}
          </template>
        </el-table-column>
        <el-table-column prop="usage" label="用法" width="120" align="center">
          <template  slot-scope="scope">
            {{scope.row.usage}}
          </template>
        </el-table-column>
        <el-table-column prop="frequency" label="频率" width="120" align="center">
          <template  slot-scope="scope">
            {{scope.row.frequency}}
          </template>
        </el-table-column>
        <el-table-column prop="days" label="天数" width="120" align="center">
          <template  slot-scope="scope">
            {{scope.row.days}}
          </template>
        </el-table-column>
        <el-table-column prop="total" label="总量" width="120" align="center">
          <template  slot-scope="scope">
            {{scope.row.total}}
          </template>
        </el-table-column>
        <el-table-column prop="data_sources" label="数据来源" width="120" align="center">
          <template  slot-scope="scope">
            {{scope.row.data_sources}}
          </template>
        </el-table-column>
        <el-table-column prop="people" label="领药人" width="120" align="center">
          <template  slot-scope="scope">
            {{scope.row.people}}
          </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:"",
      times:"",
      specifications:"",
      state_name:"",
      org_name: this.$store.getters.xt_user.org.org_name,
    };
  },
  props: {
    propForm: {
      type: Object,
    },

    state:{
        type:Number
    }
  },
  created(){
    this.init();
  },
  methods: {
    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)
    },

    // isClose() {
    //   this.visibility = false;
    // },

    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,ids,times) {
      this.times = times
      this.visibility = true;
      this.name = data.name
      this.specifications = data.specifications
      console.log("this.multipleSelection",ids)
      console.log("this.val",val)
      if (state == 1){
        this.state_name = "待发药"
        this.tableData = ids
      }
      if (state == 2){
        this.state_name = "已发药"
        this.tableData = val
      }
    },

    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;
      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: 230px;padding: 10px 0;">药品名称：${this.name}</div>
        <div style="width: 230px;padding: 10px 0;">规格：${this.specifications}</div>
        <div style="width: 230px;padding: 10px 0;">发药状态：${this.state_name}</div>
        <div style="width: 230px;padding: 10px 0;">日期：${this.times}</div>
        </div></div>`, // 打印出来的标题
        data: this.tableData, // 需要打印的数据
        serial: true, // 是否需要打印序列号
        fields: [
          // 需要打印的字段

          "name",
          "single_dosage",
          "usage",
          "frequency",
          "days",
          "total",
          "data_sources",
          "people",
        ],
        properties: [
          // 需要打印的字段对应的表头名

          {
            field: "name",
            displayName: "姓名",
          },
          {
            field: "single_dosage",
            displayName: "单次用量",
          },
          {
            field: "usage",
            displayName: "用法",
          },
          {
            field: "frequency",
            displayName: "频率",
          },
          {
            field: "days",
            displayName: "天数",
          },
          {
            field: "total",
            displayName: "总量",
          },
          {
            field: "data_sources",
            displayName: "数据来源",
          },
          {
            field: "people",
            displayName: "领药人",
          },
        ],
      });
    },
  },
};
</script>

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

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

  div {
    width: 230px;
    padding: 10px 0;
  }
}
</style>
