printBill.vue 2.43 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<template>
  <div>
    <Modal v-model="modalShow" title="打印" @on-ok="printAsync">
      <span>打印模板</span>
      <Select v-model="printTemplate" clearable>
        <Option
          v-for="item in printTemplateList"
          :value="item.name"
          :key="item.name"
          >{{ item.title }}</Option
        >
      </Select>
    </Modal>
  </div>
</template>
<script>
export default {
  props: {},
  data() {
    return {
      subName: null,
      modalShow: false,
      printTemplate: "",
      printTemplateList: [],
      billDefineName: null,
      billId: null,
    };
  },
  watch: {
    billDefineName: {
      handler(newVal, oldVal) {
        this.billDefineName = newVal;
        this.initSelect();
      },
    },
    subName: {
      handler(newVal, oldVal) {
        this.subName = newVal;
      },
    },
  },
  methods: {
    printAsync() {
      //打印接口
      return new Promise((resolve, reject) => {
        // let url=`/gms/bill/print/${this.billDefineName}/${this.billId}/${this.printTemplate}`;
        let url = `/rbcfunc/print/merge/${this.billDefineName}/${this.billId}/${this.printTemplate}?detailName=BXMXZB`;
        GMS.$http
          .post(url, JSON.stringify(), {
            responseType: "blob",
            headers: {
              "Content-Type": "application/pdf;charset=utf-8",
              "X-Requested-With": "XMLHttpRequest",
            },
          })
          .then((res) => {
            let blob = new Blob([res.data], {
              type: "application/pdf;charset=utf-8",
            });
            let downloadElement = document.createElement("a");
            let href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            window.open(href)  
            // let routeData = GMS.routerManager.getRouter().resolve({
            //   path: "/showPrint",
            //   query: { src: href },
            // });
            // window.open(routeData.href, "_blank");
          });
      });
    },
    initSelect() {
      //获取打印模板
      let url = `/common/print/${this.billDefineName}/template`;
      GMS.$http
        .get(url, JSON.stringify(), {
          headers: {
            GET: {
              "Content-Type": "application/json",
            },
          },
        })
        .then((res) => {
          this.printTemplateList = res.data;
        });
    },
  },
  mounted() {},
};
</script>
<style scoped lang="less"></style>