<template>
  <div>
    <vxe-modal show-footer class-name="vxe-table--ignore-clear" title="选择模板" :width="500" :height="400"
      v-model="templateVisible" @confirm="templateConfirm">
      <template #default>
        <vxe-select v-model="templateValue" transfer style="width:100%;">
          <vxe-option v-for="item in templates" :key="item.ID" :value="item.ID" :label="item.name"></vxe-option>
        </vxe-select>

        <vxe-switch style="margin-top:9px;" v-if="!isExport" v-model="isPreview" open-label="打印预览" :open-value="true"
          close-label="直接打印" :close-value="false"></vxe-switch>
      </template>
      <template #footer>
        <vxe-button status="primary" @click="templateConfirm" content="确定"></vxe-button>
        <vxe-button @click="templateVisible = false" content="取消"></vxe-button>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
const BASE_URL = '';
export default {
  name: 'MkPrinter',
  props: {
  },
  data() {
    return {
      isExport: false,
      isPreview: false,
      templateData: {},
      templateVisible: false,
      templates: [],
      templateUrl: "/print.html",

      templateValue: null,
      reportFormsId: "",
    }
  },
  created() {

  },
  watch: {
  },
  methods: {
    open({ templateData, code, isExport }) {
      this.templateData = templateData;
      this.isExport = isExport;
      this.$mk.post({
        url: `${BASE_URL}/api/web/getPrintTemplateList?code=${code || ""}`,
        data: {}
      }).then(a => {
        if (a && a.length) {
          this.templates = a;
          this.templateVisible = true;
          this.templateValue = a[0].ID;
        }
      });
    },
    templateConfirm() {

      this.$mk.post({
        url: `${BASE_URL}/api/web/getPrintTemplateDetail?id=${this.templateValue}`,
        data: {}
      }).then(a => {

        let data = a.data;
 



        // 然后使用 
        let hiprint = this.$hiPrint;


        hiprint.init();

        var hiprintTemplate = new hiprint.PrintTemplate({
          template: JSON.parse(data.TemplateBody)
        });
        hiprintTemplate.print(this.templateData, { printer: '', title: 'hiprint测试打印' });

      });


    },
  }
}
</script>

<style></style>