schangxiang@126.com
2025-09-19 9be9c3784b2881a3fa25e93ae2033dc2803c0ed0
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      // 当前正在扫描的数据
      currentRow: null,
      // 已经找到的数据
      existRows: []
    };
  },
  methods: {
    // 播放正确声音
    play() {
      this.$refs.sound_correct.currentTime = 0;
      this.$refs.sound_correct.play();
    },
    // 播放失败声音
    playError() {
      this.$refs.sound_error.currentTime = 0;
      this.$refs.sound_error.play();
    },
    // 获得焦点
    focus(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].focus();
        this.$refs[refName].select();
      } else {
        this.$message.error("焦点不存在:" + refName);
      }
    },
    /**
     * 判断扫描包装条码
     * @param {dataRows} 筛选数据
     * @param {successCallback} 扫描成功后,回调函数
     * @param {noExistCallback} 扫描不存在后,回调函数
     */
    checkPackingProductModel(dataRows, successCallback, noExistCallback) {
      if (!dataRows || !Array.isArray(dataRows)) {
        if (typeof dataRows === "function") {
          successCallback = dataRows;
        }
        dataRows = this.tableData;
      }
      if (!this.formData.extendField06) return;
 
      var code = this.formData.extendField06.trim();
      if (!code) return;
      if (this.currentRow) {
        const exists = this.checkProductModelExist(code, this.currentRow);
        if (!exists || !this.currentRow.unFinishedQuantity) {
          this.currentRow = null;
        } else {
          this.currentRow.sortIndex = 1;
        }
      }
 
      if (!this.currentRow) {
        // 判断是否存在一码多品
        this.existRows = dataRows.filter(item => {
          const exist = this.checkProductModelExist(code, item);
          // UnFinishedQuantity不存在或者大于0
          return exist && (item.unFinishedQuantity === undefined || item.unFinishedQuantity > 0);
        });
        this.focus("extendField06");
 
        if (this.existRows.length > 1) {
          this.$message.error(`【${code}】存在一码多品,需要手动选择需要扫描的明细,双击一下明细即可选择哦。`);
          this.existRows.forEach(item => {
            item.sortIndex = 1;
          });
          // 置顶排序
          dataRows.sort(function(a, b) {
            return b.sortIndex - a.sortIndex;
          });
 
          dataRows.forEach(element => {
            element.sortIndex = 0;
          });
          this.$refs.sound_error.currentTime = 0;
          this.playError();
          return;
        }
        if (!this.existRows.length) {
          // 执行回调函数
          if (typeof noExistCallback === "function") {
            noExistCallback(code);
          } else {
            this.$message.error(`【${code}】没有可扫描的数据`);
            this.playError();
          }
          return;
        }
 
        // 设置当前行
        this.currentRow = this.existRows[0];
        this.currentRow.sortIndex = 1;
      }
      this.currentRow.scanWeight = Math.Round(this.currentRow.weight * this.currentRow.finishedQuantity, 2);
      this.setRowQty(dataRows);
 
      // 执行回调函数
      if (typeof successCallback === "function") {
        successCallback();
      }
    },
    // 扫描数量处理
    setRowQty(dataRows) {
      if (!dataRows || !Array.isArray(dataRows)) {
        dataRows = this.tableData;
      }
      var code = this.formData.extendField06.trim();
 
      // 获得扫描数量
      let scanQty = 1; // 默认扫描数量为1
      if (this.currentRow.middleBarcode === code) {
        // 中包装条码
        scanQty = this.currentRow.middleUnitConvert;
        if (!scanQty || scanQty < 0) {
          this.$message.error(`条码【${this.currentRow.middleBarcode}】没有设置中单位换算关系数据!`);
          this.$refs.sound_error.currentTime = 0;
          this.playError();
          return;
        }
      } else if (this.currentRow.bigBarcode === code) {
        // 中包装条码
        scanQty = this.currentRow.unitConvert;
        if (!scanQty || scanQty < 0) {
          this.$message.error(`条码【${this.currentRow.bigBarcode}】没有设置大单位换算关系数据!`);
          this.$refs.sound_error.currentTime = 0;
          this.playError();
          return;
        }
      }
 
      // 判断是否有足够扫描数量
      if (this.currentRow.unFinishedQuantity !== undefined && this.currentRow.unFinishedQuantity < scanQty) {
        this.$message.error(`物料扫描数量不足!`);
        this.focus("scanQty");
        this.$refs.sound_error.currentTime = 0;
        this.playError();
        return;
      }
 
      // 设置已扫描的数量
      this.currentRow.finishedQuantity += scanQty;
      if (this.currentRow.unFinishedQuantity !== undefined) {
        this.currentRow.unFinishedQuantity -= scanQty;
        this.currentRow.scanWeight = Math.Round(this.currentRow.finishedQuantity * this.currentRow.weight, 4);
      } else {
        this.currentRow.scanWeight = Math.Round(this.currentRow.finishedQuantity * this.currentRow.weight, 4);
      }
      this.formData.scanQty = this.currentRow.finishedQuantity;
      this.play();
 
      // 置顶排序
      dataRows.sort(function(a, b) {
        return b.sortIndex - a.sortIndex;
      });
 
      dataRows.forEach(element => {
        element.sortIndex = 0;
      });
      this.focus("extendField06");
    },
    /**
     * 获得扫描数量,根据大中小进率
     */
    getScanQty() {
      var code = this.formData.extendField06.trim();
      // 获得扫描数量
      let scanQty = 1; // 默认扫描数量为1
      if (this.currentRow.middleBarcode === code) {
        // 中包装条码
        scanQty = this.currentRow.middleUnitConvert;
        if (!scanQty || scanQty < 0) {
          this.$message.error(`条码【${this.currentRow.middleBarcode}】没有设置中单位换算关系数据!`);
          this.$refs.sound_error.currentTime = 0;
          this.playError();
          return;
        }
      } else if (this.currentRow.bigBarcode === code) {
        // 中包装条码
        scanQty = this.currentRow.unitConvert;
        if (!scanQty || scanQty < 0) {
          this.$message.error(`条码【${this.currentRow.bigBarcode}】没有设置大单位换算关系数据!`);
          this.$refs.sound_error.currentTime = 0;
          this.playError();
          return;
        }
      }
 
      return scanQty;
    },
    // 判断所有条码是否存在
    checkProductModelExist(extendField06, rowData) {
      var isExists = false;
      if (!extendField06 || !rowData) {
        return false;
      }
 
      isExists =
        extendField06 === rowData.extendField06 ||
        extendField06 === rowData.relationCode ||
        extendField06 === rowData.relationCode2 ||
        extendField06 === rowData.relationCode3 ||
        extendField06 === rowData.relationCode4 ||
        extendField06 === rowData.relationCode5 ||
        extendField06 === rowData.middleBarcode ||
        extendField06 === rowData.bigBarcode;
 
      return isExists;
    },
    // 手动设置数量
    setScanQty(callback) {
      debugger;
      this.currentRow = null;
 
      if (!this.existRows.length) {
        this.$message.error("请扫描物料条码!");
        this.$refs.sound_error.currentTime = 0;
        this.playError();
        return false;
      }
      if (this.existRows.length > 1) {
        this.$message.error(`【${this.existRows[0].extendField06}】存在一码多品,需要手动选择需要扫描的明细,双击一下明细即可选择哦。`);
        this.$refs.sound_error.currentTime = 0;
        this.playError();
        return;
      }
 
      // 设置当前行
      this.currentRow = this.existRows[0];
      const scanQty = this.formData.scanQty;
      if (this.currentRow.unFinishedQuantity !== undefined) {
        // 判断是否有足够扫描数量
        const totalQty = this.currentRow.unFinishedQuantity + this.currentRow.finishedQuantity;
        if (totalQty < scanQty) {
          this.$message.error("物料扫描数量不足!");
          this.playError();
          this.focus("scanQty");
          return false;
        }
        const total = totalQty - scanQty;
        // 设置未扫描的数量
        this.currentRow.unFinishedQuantity = Math.Round(total, 4);
      }
      // 设置已扫描的数量
      this.$set(this.currentRow, "finishedQuantity", scanQty);
      this.currentRow.scanWeight = this.currentRow.finishedQuantity * this.currentRow.weight;
 
      this.play();
      if (typeof callback === "function") {
        const re = callback();
        if (re === false) {
          this.play();
          return;
        }
      }
      this.play();
 
      return true;
    },
    // 行样式
    rowClass({ row, rowIndex }) {
      if (this.existRows.find(f => f === row)) {
        if (this.existRows.length === 1) {
          return "row-active";
        } else {
          return "multi-row-active";
        }
      }
    },
    // 双击事件
    setCurrent(row, event, column) {
      if (this.checkProductModelExist(this.formData.extendField06, row)) {
        this.currentRow = row;
        this.existRows = [row];
        this.tableData.forEach(element => {
          element.sortIndex = 0;
        });
        this.currentRow.sortIndex = 1;
        this.tableData = this.tableData.sort(function(a, b) {
          return b.sortIndex - a.sortIndex;
        });
        this.tableData.forEach(element => {
          element.sortIndex = 0;
        });
        this.focus("extendField06");
      }
    },
    // 是否已完成
    isFinished() {
      var isAllFinished = this.tableData.every(rowData => {
        return rowData.unFinishedQuantity <= 0;
      });
 
      return isAllFinished;
    },
    // 行数据改变
    rowChangeQty(prop, row, qtyFeild) {
      if (!qtyFeild) {
        qtyFeild = "quantityOrder";
      }
      if (prop === "finishedQuantity") {
        row.unFinishedQuantity = row[qtyFeild] - row.finishedQuantity;
      } else if (prop === "unFinishedQuantity") {
        row.finishedQuantity = row[qtyFeild] - row.unFinishedQuantity;
      }
      row.scanWeight = Math.Round(row.weight * row.finishedQuantity, 2);
    }
  }
};
</script>