<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 v-if="state==2">领药人：</div>
      </div> -->
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="处方详情" name="first">
          <el-tabs v-model="editableTabsValue" type="card">
            <el-tab-pane
              :key="item.name"
              v-for="(item, index) in editableTabs"
              :label="item.title"
            >
              Rp
              <el-table
                style="width: 1020px; margin: 0 auto"
                :data="tableData"
                border
                max-height="450"
                :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)' }"
              >
                <el-table-column prop="name" label="名称" width="160" align="center">
                </el-table-column>
                 <el-table-column prop="group" label="组" width="100" align="center">
                </el-table-column>
                <el-table-column prop="SingleDosage" label="单次用量" width="100" align="center">
               </el-table-column>
                <el-table-column prop="use" label="用法" width="120" align="center">
                </el-table-column>
                <el-table-column prop="frequency" label="频率" width="120" align="center">
                </el-table-column>
                <el-table-column prop="day" label="天数" width="120" align="center">
                </el-table-column>
                <el-table-column prop="amount" label="总量" width="90" align="center">
                </el-table-column>
                <el-table-column prop="price" label="单价" width="100" align="center">
                </el-table-column>
                <el-table-column prop="tips" label="备注" width="120" align="center">
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane label="病历详情" name="second">病历详情</el-tab-pane>
      </el-tabs>
    </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,
      activeName: "first",
      editableTabsValue: "2",
      editableTabs: [
        {
          title: "处方1",
        },
        {
          title: "处方2",
        },
      ],
      tabIndex: 2,
    };
  },
  props: {
    propForm: {
      type: Object,
    },

    state: {
      type: Number,
    },
  },

  methods: {
    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() {},

    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 打印
    print() {
      Vue.prototype.printJson = printutils.printJson;
      this.printJson({
        // title: ``, // 打印出来的标题
        data: this.tableData, // 需要打印的数据
        serial: false, // 是否需要打印序列号
        fields: [
          // 需要打印的字段

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

          {
            field: "name",
            displayName: "名称",
          },
            {
            field: "group",
            displayName: "组",
          },
          {
            field: "SingleDosage",
            displayName: "单词用量",
          },
          {
            field: "use",
            displayName: "用法",
          },
          {
            field: "frequency",
            displayName: "频率",
          },
          {
            field: "day",
            displayName: "天数",
          },
          {
            field: "amount",
            displayName: "总量",
          },
          {
            field: "price",
            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>
