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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<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="800" height="600" pluginspage="/upload/install_lodop32.exe" />
      </object>
    </div>
    <el-button type="primary" class="no-print" @click="print">打印</el-button>
    <el-button type="primary" class="no-print" @click="setting">设置模板</el-button>
  </div>
</template>
 
<script>
import VueBarcode from "@xkeshi/vue-barcode";
 
export default {
  name: "PrintBarcode",
  components: {
    barcode: VueBarcode
  },
  data() {
    return {
      LODOP: null
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    // 初始化数据
    async init() {
      // 打印类别
      const printType = localStorage.getItem("printType");
 
      const columList = await this.getColumnList();
      let code = await this.getLodopTemplate(printType);
      if (!code) code = "{}";
 
      // =====判断浏览器类型:===============
      let LODOP = null;
      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 = isIE ? LODOP_OBJ : LODOP_EM;
      this.LODOP = LODOP;
      LODOP.SET_LICENSES("达令心潮(北京)商贸有限公司", "B95259F540E2C256132EC7CE6AB55737", "", "");
      if (printType === "货位条码打印") {
        const positionNames = localStorage.getItem("positionNames").split(",");
        // 明细行数据循环
        for (const positionName of positionNames) {
          LODOP.NewPage();
 
          let _code = code.replace("PRINT_INITA(0,", "SET_PRINT_PAGESIZE(");
          const key = "{货位名称}";
          const value = positionName;
          _code = _code.replace(key, value);
          // eslint-disable-next-line
          eval(_code);
        }
      } else {
        const tableData = localStorage.getItem("tableData");
        if (!tableData) {
          this.$message.error("没有可生成的数据");
          return;
        }
        // 物料明细行数据循环
        const _tableData = JSON.parse(tableData);
        for (const item of _tableData) {
          const productInfo = await this.getProductInfo(item.product_Id);
          this.createBarcode(LODOP, item, code, columList, productInfo);
        }
      }
      LODOP.SET_SHOW_MODE("PREVIEW_IN_BROWSE", true); // 预览界面内嵌到页面内
      LODOP.PREVIEW();
    },
    // 获得字段
    getColumnList() {
      return new Promise((resolve, reject) => {
        const url = "/api/sys/print/getColumnList";
        var params = {};
        this.common.ajax(
          url,
          params,
          res => {
            this.common.showMsg(res);
            if (res.result) {
              resolve(res.data);
            } else {
              reject();
            }
          },
          true
        );
      });
    },
    // 获取模板
    getLodopTemplate(sendBillName) {
      return new Promise((resolve, reject) => {
        const url = "/api/sys/print/getLodopTemplate";
        var params = {
          sendBillName: sendBillName
        };
        this.common.ajax(
          url,
          params,
          res => {
            this.common.showMsg(res);
            if (res.result) {
              resolve(res.data.designConent);
            } else {
              reject();
            }
          },
          true
        );
      });
    },
    // 获取物料数据
    getProductInfo(product_Id) {
      return new Promise((resolve, reject) => {
        const url = "/api/basicInfo/base/productInfo/getById";
        var params = {
          id: product_Id
        };
        this.common.ajax(
          url,
          params,
          res => {
            this.common.showMsg(res);
            if (res.result) {
              resolve(res.data);
            } else {
              reject();
            }
          },
          true
        );
      });
    },
    // 创建物料条码
    createBarcode(LODOP, item, code, columList, productInfo) {
      // 条码数量循环
      for (let i = 0; i < item.quantity; i++) {
        LODOP.NewPage();
 
        let _code = code.replace("PRINT_INITA(0,", "SET_PRINT_PAGESIZE(");
        // eslint-disable-next-line
        for (const colInfo of columList) {
          const key = "{" + colInfo.columnComment + "}";
          const columnName = this.common.caseStyle(colInfo.columnName);
          const value = item[columnName] || (productInfo ? productInfo[columnName] : "");
          _code = _code.replace(key, value);
        }
        // 自定义键值
        let keyValues = localStorage.getItem("keyValues");
        if (keyValues) {
          keyValues = JSON.parse(keyValues);
          keyValues.forEach(item => {
            const key = "{" + item.key + "}";
            const value = item.value;
            _code = _code.replace(key, value);
          });
        }
        // eslint-disable-next-line
        eval(_code);
      }
    },
    // 打印
    print() {
      this.LODOP.PRINT();
    },
    // 设计模板
    setting() {
      window.open("/#/inbound/purchase/print-barcode-setting");
    }
  }
};
</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>