333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
  <div class="print-container">
    <div class="margin-bottom-20">
      <object id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="800" height="600">
        <param name="Caption" value="显示区" />
        <param name="Border" value="0" />
        <param name="Color" value="white" />
        <embed id="LODOP_EM" type="application/x-print-lodop" width="1200" height="500" pluginspage="/upload/install_lodop32.exe" />
      </object>
    </div>
    <el-button type="text" class="no-print" @click="deleteItem">删除选择项</el-button>
    <el-button type="primary" class="no-print" @click="save">保存模板</el-button>
  </div>
</template>
 
<script>
import VueBarcode from "@xkeshi/vue-barcode";
 
export default {
  name: "PrintBarcode",
  components: {
    barcode: VueBarcode
  },
  data() {
    return {
      // 模板类型
      printType: ""
    };
  },
  computed: {},
  created() {
    this.printType = localStorage.getItem("printType");
    this.tableData = JSON.parse(localStorage.getItem("tableData") || "[]");
  },
  mounted() {
    window.setTimeout(() => {
      this.initData();
    }, 1000);
  },
  methods: {
    initData() {
      // 判断浏览器类型
      var isIE = navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0;
      var LODOP_OBJ = document.getElementById("LODOP");
      var LODOP_EM = document.getElementById("LODOP_EM");
      // LODOP对象
      const LODOP = isIE ? LODOP_OBJ : LODOP_EM;
 
      // 默认设置
      const defaultDesign = `
        LODOP.PRINT_INITA(0,0,"100.01mm","60.01mm","打印设计");
        LODOP.ADD_PRINT_BARCODE(89,5,141,148,"QRCode","{物料二维码}");
        LODOP.ADD_PRINT_BARCODE(15,11,354,66,"128B","{物料条码}");
        LODOP.ADD_PRINT_TEXT(96,138,203,20,"名称:{物料名称}");
        LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
        LODOP.ADD_PRINT_TEXT(130,141,216,25,"编号:{物料编号}");
        LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
        LODOP.ADD_PRINT_TEXT(162,140,169,20,"规格:{物料规格}");
        LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
      `;
      const url = "/api/sys/print/getLodopTemplate";
      var params = {
        sendBillName: this.printType
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            // eslint-disable-next-line
            eval(res.data.designConent);
            LODOP.SET_SHOW_MODE("DESIGN_IN_BROWSE", 1);
            LODOP.PRINT_DESIGN();
          } else {
            // eslint-disable-next-line
            eval(defaultDesign);
            LODOP.SET_SHOW_MODE("DESIGN_IN_BROWSE", 1);
            LODOP.PRINT_DESIGN();
          }
        },
        true
      );
    },
    // 保存模板
    save() {
      // 判断浏览器类型
      var isIE = navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0;
      var LODOP_OBJ = document.getElementById("LODOP");
      var LODOP_EM = document.getElementById("LODOP_EM");
      // LODOP对象
      const LODOP = isIE ? LODOP_OBJ : LODOP_EM;
 
      const designConent = LODOP.GET_VALUE("ProgramCodes", 0);
      const url = "/api/sys/print/saveLodopTemplate";
      const params = {
        sendBillName: this.printType,
        designConent: designConent
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.$notify({
            title: "提示",
            type: "success",
            message: res.msg,
            position: "top-right"
          });
        },
        true
      );
    },
    // 删除选中项
    deleteItem() {
      // 判断浏览器类型
      var isIE = navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0;
      var LODOP_OBJ = document.getElementById("LODOP");
      var LODOP_EM = document.getElementById("LODOP_EM");
      // LODOP对象
      const LODOP = isIE ? LODOP_OBJ : LODOP_EM;
 
      LODOP.SET_PRINT_STYLEA("Selected", "Deleted", true);
    }
  }
};
</script>
 
<style lang="scss" scoped>
.print-container {
  padding: 20px;
  .print-page {
    page-break-after: always;
    margin-top: 20px;
  }
}
 
@media print {
  .canvas-container {
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    margin: 0px;
    .canvas-content {
      border: 0px dotted #000000;
    }
  }
  .no-print {
    display: none;
  }
  .page-next {
    page-break-after: always;
  }
}
</style>