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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<template>
  <div class="scan-container">
    <el-card class="scan-card">
      <div slot="header" class="clearfix">
        <span>补货扫描</span>
      </div>
      <el-form ref="form" :model="formData" label-width="120px" class="scan-form">
        <el-form-item label="补货单号">
          <el-input ref="replenishmentCode" v-model="formData.replenishmentCode" class="input-300" autofocus @keyup.native.enter.stop="getData"></el-input>
          <span class="sub-item">
            <span class="sub-label">扫描物料</span>
            <el-switch v-model="formData.isValidateProductCode" @change="onIsValidateProductCodeChange"></el-switch>
          </span>
        </el-form-item>
        <el-form-item label="目标货位">
          <el-input ref="targetPositionName" v-model="formData.targetPositionName" :disabled="!formData.isValidateProductCode" class="input-300" @keyup.native.enter.stop="positionNameClick"></el-input>
        </el-form-item>
        <el-form-item label="物料条码">
          <el-input ref="productModel" v-model="formData.productModel" :disabled="!formData.isValidateProductCode" class="input-300" @keyup.native.enter.stop="checkPackingBarcode"></el-input>
          <span class="sub-item">
            <span class="sub-label">扫描数量:</span>
            <!-- :min="1" -->
            <el-input-number v-model="formData.scanQty" :disabled="!formData.isValidateProductCode" class="input-100" controls-position="right" @change="changeScanQty"></el-input-number>
          </span>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="saveCheck">确认出库</el-button>
          <el-button @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="scan-card body-no-padding">
      <div slot="header" class="clearfix">
        <span>扫描结果</span>
      </div>
      <el-table ref="scan-table" :data="tableData" :row-class-name="rowClass" stripe style="width: 100%" class="scan-table" @row-click="setCurrent">
        <el-table-column prop="productModel" label="条形码" width="130">
        </el-table-column>
        <el-table-column prop="batchNumber" label="批次号" width="80">
        </el-table-column>
        <el-table-column prop="plateCode" label="拍号" width="100">
        </el-table-column>
        <el-table-column prop="produceDate" label="生产时间" width="120">
          <template slot-scope="scope">
            <template>
              <el-date-picker v-model="scope.row.produceDate" :disabled="true" size="mini" type="date" placeholder="选择日期" class="w-100">
              </el-date-picker>
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="storageName" label="仓库" width="100">
        </el-table-column>
        <el-table-column prop="originalPositionName" label="原货位" width="100">
        </el-table-column>
        <el-table-column prop="targetPositionName" label="目标货位" width="100">
        </el-table-column>
        <el-table-column prop="finishedQuantity" label="已扫描数量" width="100">
          <template slot-scope="scope">
            <template v-if="!formData.isValidateProductCode">
              <el-input-number v-model.number="scope.row.placeholderStorage" :disabled="false" size="mini" class="w-90" controls-position="right"></el-input-number>
            </template>
            <template v-else>
              {{ scope.row.finishedQuantity }}
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="unFinishedQuantity" label="未扫描数量" width="100">
          <template slot-scope="scope">
            <template v-if="!formData.isValidateProductCode">
              0
              <!-- <el-input-number v-model="scope.row.unFinishedQuantity" :disabled="true" size="mini" class="w-90" controls-position="right"></el-input-number> -->
            </template>
            <template v-else>
              {{ scope.row.unFinishedQuantity }}
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="productCode" label="物料编号" width="130">
        </el-table-column>
        <el-table-column prop="productSpec" label="物料规格" width="100">
        </el-table-column>
        <el-table-column prop="manufacturer" label="生产厂家" width="120">
        </el-table-column>
        <el-table-column prop="productName" label="物料名称" width="120">
        </el-table-column>
      </el-table>
    </el-card>
 
    <!--声音文件-->
    <audio ref="sound_error" controls="controls" style="display:none;">
      <source src="@/assets/sounds/error2.mp3" type="audio/mpeg" />
    </audio>
    <audio ref="sound_correct" controls="controls" style="display:none;">
      <source src="@/assets/sounds/feixin.mp3" type="audio/mpeg" />
    </audio>
    <audio controls="controls" style="display:none;">
      <source ref="sound_scan" src="@/assets/sounds/saomiao.wav" type="audio/mpeg" />
    </audio>
 
  </div>
</template>
 
<script>
export default {
  name: "scan-purchase-order",
  data() {
    return {
      formData: {
        orderCode: null,
        // 是否校验物料
        isValidateProductCode: true,
        // 自动生成上架单
        isOnShelve: false,
        positionName: null,
        productModel: null,
        scanQty: null
      },
      // 明细数据
      tableData: [],
      // 仓库ID
      storage_Id: 0,
      // 仓库信息
      storageInfo: {},
      // 收货位候选项
      positionList: [],
      // 当前正在扫描的数据  {}
      currentRow: null,
      // 已经找到的数据
      existRows: [],
      // 装箱方式:0:常规扫描,1:一品一箱,2:多品一箱
      caseMode: 0,
      // 一次扫描的数量
      scanCount: 1,
      // 装箱新增行
      caseNewRows: [],
      // 配置参数
      config: {
        // 自动生成上架单
        in_generateShelve: true,
        // 是否启用装箱操作
        in_caseNumber: false,
        // 支持一品多码
        sku_productToMultiBarcode: true
      }
    };
  },
  // 监听数据
  watch: {
    // 当前行扫描数据改变后,将扫描数量也改变
    currentRow: {
      handler: function(rowData) {
        this.formData.scanQty = rowData.finishedQuantity;
      },
      deep: true
    }
  },
  activated() {
    const isOnShelve = localStorage["isOnShelve"];
    if (isOnShelve) {
      this.formData.isOnShelve = isOnShelve === "true";
    }
    const isValidateProductCode = localStorage["isValidateProductCode"];
    if (isOnShelve) {
      this.formData.isValidateProductCode = isValidateProductCode === "true";
    }
  },
  methods: {
    // 直接上架设置
    onIsValidateProductCodeChange() {
      localStorage["isValidateProductCode"] = this.formData.isValidateProductCode;
    },
    positionNameClick() {
      this.$refs.productModel.focus();
      this.$refs.productModel.select();
    },
    // 获得明细数据
    getData() {
      var replenishmentCode = this.formData.replenishmentCode;
      if (!replenishmentCode) {
        this.$message.error("补货单号不能为空");
        return;
      }
      const url = "/api/storage/replenishment/replenishmentGetData";
      const params = {
        replenishmentCode: replenishmentCode
      };
      var callback = res => {
        this.common.showMsg(res);
        if (res.result) {
          // 构建数据
          // this.currentRow = {};
          this.tableData = res.data.map(row => {
            row.unFinishedQuantity = Math.Round(row.placeholderStorage - 0, 4);
            row.finishedQuantity = 0;
            row.sortIndex = 0;
            row.originalPositionName = row.positionName;
            return row;
          });
        }
      };
      this.common.ajax(url, params, callback, this.$refs["form"]);
    },
    // 判断扫描包装条码
    checkPackingBarcode(evt) {
      evt.target.select();
      var code = this.formData.productModel;
      code = code.trim();
      if (!code) return;
      this.existRows = [];
      var targetPositionName = "";
      if (this.formData.targetPositionName) {
        targetPositionName = this.formData.targetPositionName.trim();
      }
 
      var isItemFinished = false;
      var isExistsProduct = false; // 物料是否在明细存在
      for (var index in this.tableData) {
        var rowData = this.tableData[index];
        if (rowData.productModel === code) {
          isExistsProduct = true;
          var finishedQuantity = parseInt(rowData.finishedQuantity);
          var unFinishedQuantity = parseInt(rowData.unFinishedQuantity);
          if (unFinishedQuantity > 0) {
            this.currentRow = rowData;
            this.existRows.push(rowData);
            rowData.finishedQuantity = finishedQuantity + 1;
            rowData.unFinishedQuantity = unFinishedQuantity - 1;
            this.$refs.sound_error.play(); // 播放声音
            if (targetPositionName) {
              rowData.targetPositionName = targetPositionName;
            }
          } else {
            // 查找明细中是否还有该 条码 的物料
            var isHaveAnother = false;
            for (var index2 in this.tableData) {
              var rowData2 = this.tableData[index2];
              if (rowData2.productModel === code && parseInt(rowData2.unFinishedQuantity) > 0) {
                isHaveAnother = true;
                var _finishedQuantity = parseInt(rowData2.finishedQuantity);
                var _unFinishedQuantity = parseInt(rowData2.unFinishedQuantity);
                this.currentRow = rowData2;
                this.existRows.push(rowData2);
                rowData2.finishedQuantity = _finishedQuantity + 1;
                rowData2.unFinishedQuantity = _unFinishedQuantity - 1;
                this.$refs.sound_error.play(); // 播放声音
                if (targetPositionName) {
                  rowData2.targetPositionName = targetPositionName;
                }
                break;
              }
            }
            if (!isHaveAnother) {
              isItemFinished = true;
            }
          }
          // 不管这个物料编号有几个item,满足第一个物料编号后就跳出,不能扫描一个条码,对每一个明细扫描数量都加1
          break;
        }
      }
      if (!isExistsProduct) {
        this.$message.error("物料条码【" + code + "】在该订单不存在!");
        this.$refs.sound_error.play(); // 播放声音
        return;
      }
      if (isItemFinished) {
        this.$message.error("物料【" + code + "】已经扫描完成,不需要再扫描!");
        this.$refs.sound_error.play(); // 播放声音
        return;
      }
    },
    // 扫描数量手工改变
    changeScanQty() {
      var code = this.formData.productModel;
      if (this.currentRow) {
        if (this.formData.scanQty <= 0) {
          this.$message.error("数量不正确");
          this.$refs.sound_error.play(); // 播放声音
          return false;
        }
        if (this.formData.scanQty > this.currentRow.placeholderStorage) {
          this.$message.error("物料 【" + code + "】的未扫描数量小于您的输入的数量。");
          this.$refs.sound_error.play(); // 播放声音
          return false;
        }
        this.currentRow.finishedQuantity = this.formData.scanQty;
        this.currentRow.unFinishedQuantity = this.currentRow.placeholderStorage - this.formData.scanQty;
      }
    },
    // 行样式
    rowClass({ row, rowIndex }) {
      if (this.existRows.find(f => f === row)) {
        return "row-active";
      }
    },
    // 重置onReset
    onReset() {
      this.formData = {
        replenishmentCode: null,
        isValidateProductCode: true, // 是否校验物料
        targetPositionName: null,
        productModel: null,
        scanQty: 0
      };
      this.tableData = [];
      this.$refs.replenishmentCode.focus();
    },
    // 确认出库
    saveCheck() {
      var replenishmentCode = this.formData.replenishmentCode;
      var IsLess = 0;
      var IsnoEnd = 0;
      var productModelList = [];
      this.tableData.forEach(rowData => {
        if (!this.formData.isValidateProductCode) {
          rowData.finishedQuantity = parseInt(rowData.placeholderStorage);
          rowData.unFinishedQuantity = 0;
        }
        if (rowData.finishedQuantity <= 0) return;
        if (rowData.unFinishedQuantity !== 0) {
          IsnoEnd = 1;
          return;
        }
        IsLess = 1;
        productModelList.push({
          product_Id: parseInt(rowData.product_Id),
          finishedQuantity: parseInt(rowData.finishedQuantity),
          originalPositionName: rowData.originalPositionName,
          targetPositionName: rowData.targetPositionName,
          batchNumber: rowData.batchNumber,
          produceDate: rowData.produceDate,
          plateCode: rowData.plateCode,
          consignor_Id: rowData.consignor_Id
        });
      });
      var zeroList = [];
      zeroList = productModelList.filter(r => r.finishedQuantity === 0);
      if (zeroList.length > 0) {
        this.$message.error("已扫描数量不能全部为零!");
        return;
      }
      if (IsLess === 0) {
        this.$message.error("已扫描数量不能全部为零!");
        return;
      }
      if (IsnoEnd === 1) {
        this.$message.error("不允许部分扫描!");
        return;
      }
 
      var url = "/api/storage/replenishment/replenishmentSave";
      var params = {
        productModelList: productModelList,
        replenishmentCode: replenishmentCode
      };
 
      var callback = res => {
        this.common.showMsg(res);
        if (res.result) {
          this.onReset();
          this.$refs.sound_correct.play(); // 播放声音
        } else {
          this.$refs.sound_error.play(); // 播放声音
        }
      };
      this.common.ajax(url, params, callback);
    },
 
    // 双击事件
    setCurrent(row, event, column) {
      if (row.productModel === this.formData.productModel) {
        this.currentRow = row;
        this.existRows = [];
        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.existRows.push(row);
      }
    }
  }
};
</script>
 
<style lang="scss" scoped>
@import "../../../styles/scan.scss";
</style>