<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">
        <div>患者名称：</div>
        <div>数据来源：</div>
        <div>发药状态：</div>
        <div>领药时间：</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">
        </el-table-column>
        <el-table-column prop="name" label="名称" width="160">
        </el-table-column>
        <el-table-column prop="SingleDosage" label="单次用量" width="120">
        </el-table-column>
        <el-table-column prop="use" label="用法" width="120"> </el-table-column>
        <el-table-column prop="frequency" label="频率" width="120">
        </el-table-column>
        <el-table-column prop="day" label="天数" width="120"> </el-table-column>
        <el-table-column prop="amount" label="总量" width="120">
        </el-table-column>
        <el-table-column prop="tips" label="备注" width="120">
        </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
    };
  },
  props: {
    propForm: {
      type: Object,
    },
  },

  methods: {
    // 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 () {
      this.visibility = true;
    },

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

    // 打印
    print() {
      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 style="width: 940px;border-bottom: 1px solid;display: flex;margin: 30px auto;">
        <div style="width: 230px;padding: 10px 0;">患者名称：${1}</div>
        <div style="width: 230px;padding: 10px 0;">数据来源：${1}</div>
        <div style="width: 230px;padding: 10px 0;">预约状态：${1}</div>
        <div style="width: 230px;padding: 10px 0;">领药时间：${1}</div>
        </div>`, // 打印出来的标题
        data: this.tableData, // 需要打印的数据
        serial: true, // 是否需要打印序列号
        fields: [
          // 需要打印的字段

          "name",
          "SingleDosage",
          "use",
          "frequency",
          "day",
          "amount",
          "tips",
        ],
        properties: [
          // 需要打印的字段对应的表头名

          {
            field: "name",
            displayName: "姓名",
          },
          {
            field: "SingleDosage",
            displayName: "单词用量",
          },
          {
            field: "use",
            displayName: "用法",
          },
          {
            field: "frequency",
            displayName: "频率",
          },
          {
            field: "day",
            displayName: "天数",
          },
          {
            field: "amount",
            displayName: "总量",
          },
          {
            field: "tips",
            displayName: "备注",
          },
        ],
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.print_style {
  position: absolute;
  right: 10px;
  top: 42px;
}

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

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