skyouc
13 小时以前 9382f2c611581996c9b015abeb079891acbddde4
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
<template>
    <view>
        <view class="code">
            <view class="item">
                <view class="code-decs">源托盘:</view>
                <input
                    type="text"
                    placeholder=" 扫码 / 输入"
                    v-model="orgBarcode"
                    :focus="orgBarcodeFocus"
                    @input="barcodeInput()"
                />
            </view>
            <view class="item">
                <view class="code-decs">目标托盘:</view>
                <input
                    type="text"
                    placeholder=" 扫码 / 输入"
                    v-model="tarBarcode"
                    :focus="tarBarcodeFocus"
                />
            </view>
            <view class="item">
                <view class="code-decs">站点号:</view>
                <input
                    type="text"
                    placeholder=" 扫码 / 输入"
                    v-model="devNo"
                />
            </view>
        </view>
        <view class="mat-list-title">商品列表</view>
        <scroll-view scroll-y>
            <view
                class="list"
                v-for="(item, index) in dataList"
                :key="index"
            >
                <view class="list-left">
                    <view class="list-left-item">
                        <view class="desc">No:</view>
                        <view class="left-item">{{ index + 1 }}</view>
                    </view>
                    <view class="list-left-item">
                        <view class="desc">编码:</view>
                        <view class="left-item">
                            <uni-tag
                                :text="item.matnr"
                                type="primary"
                            ></uni-tag>
                        </view>
                    </view>
                    <view class="list-left-item">
                        <view class="desc">品名:</view>
                        <uni-tooltip
                            class="left-item"
                            :content="item.maktx"
                            placement="bottom"
                        >
                            <view
                                class="left-item tip"
                                style=""
                            >
                                {{ item.maktx }}
                            </view>
                        </uni-tooltip>
                    </view>
                    <view class="list-left-item">
                        <view class="desc">规格:</view>
                        <view class="left-item">{{ item.specs }}</view>
                    </view>
                    <view class="list-left-item">
                        <view class="desc">供应商:</view>
                        <view class="left-item">
                            <uni-tag
                                :text="item.standby1"
                                type="warning"
                            ></uni-tag>
                        </view>
                    </view>
                    <view class="list-left-item">
                        <view class="desc">数量:</view>
                        <view class="left-item">{{ item.anfme }}</view>
                    </view>
                    <view class="list-left-item">
                        <view class="desc">拣货数量:</view>
                        <view
                            class="left-item"
                            style="border: none; justify-content: center"
                        >
                            <uni-number-box
                                v-model="item.workQty"
                                :max="item.anfme"
                                color="#747474"
                            />
                        </view>
                    </view>
                </view>
                <view class="list-right">
                    <uni-icons
                        type="trash"
                        color="#f58a8a"
                        size="24"
                        @click="remove(index)"
                    ></uni-icons>
                </view>
            </view>
            <!-- 空状态提示 -->
            <view
                v-if="dataList.length === 0"
                class="empty-tips"
            >
                暂无商品,请扫码添加
            </view>
        </scroll-view>
        <!-- 底部操作按钮 -->
        <view class="buttom">
            <button
                size="mini"
                @click="reset"
            >
                重置
            </button>
            <button
                size="mini"
                type="primary"
                @click="combConfirm"
            >
                组托
            </button>
        </view>
 
        <!-- 修改数量弹窗 -->
        <uni-popup
            ref="revisePopup"
            type="dialog"
        >
            <view class="popup">
                <view class="title">修改</view>
                <view class="popup-item">
                    <view class="popup-item-left">编码:</view>
                    <view class="popup-item-right">
                        <input
                            type="text"
                            v-model="editForm.matnr"
                            disabled
                            style="
                                background-color: #f7f7f7;
                                padding: 0;
                                color: #d5d5d5;
                            "
                        />
                    </view>
                </view>
                <view class="popup-item">
                    <view class="popup-item-left">代码:</view>
                    <view class="popup-item-right">
                        <input
                            type="text"
                            v-model="editForm.standby1"
                        />
                    </view>
                </view>
                <view class="popup-item">
                    <view class="popup-item-left">数量:</view>
                    <view
                        class="popup-item-right"
                        style="border: none; justify-content: center"
                    >
                        <uni-number-box
                            :value="editForm.count"
                            :step="0.01"
                            :max="9999999"
                            color="#747474"
                            @change="changeValue"
                        />
                    </view>
                </view>
                <view class="btn">
                    <view
                        class="btn-left"
                        @click="reviseClose"
                    >
                        取消
                    </view>
                    <view
                        class="btn-right"
                        @click="reviseConfirm"
                    >
                        修改
                    </view>
                </view>
            </view>
        </uni-popup>
 
        <!-- 移除确认弹窗 -->
        <uni-popup
            ref="removeDialog"
            type="dialog"
        >
            <uni-popup-dialog
                type="warn"
                confirmText="移除"
                title="警告"
                content="是否移除当前商品!"
                @confirm="removeConfirm"
                @close="removeClose"
            ></uni-popup-dialog>
        </uni-popup>
 
        <!-- 消息提示 -->
        <uni-popup
            ref="message"
            type="message"
        >
            <uni-popup-message
                :type="msgType"
                :message="messageText"
                :duration="2000"
            ></uni-popup-message>
        </uni-popup>
 
        <!-- 确认组托弹窗 -->
        <uni-popup
            ref="combDialog"
            type="dialog"
        >
            <uni-popup-dialog
                type="warn"
                cancelText="取消"
                confirmText="确认"
                title="警告"
                content="是否现在组托!"
                @confirm="comb"
                @close="combClose"
            ></uni-popup-dialog>
        </uni-popup>
 
        <!-- 确认重置弹窗 -->
        <uni-popup
            ref="resetDialog"
            type="dialog"
        >
            <uni-popup-dialog
                type="warn"
                cancelText="取消"
                confirmText="确认"
                title="警告"
                content="是否重置!"
                @confirm="resetConfirm"
                @close="resetClose"
            ></uni-popup-dialog>
        </uni-popup>
    </view>
</template>
 
<script>
export default {
    data() {
        return {
            baseUrl: '',
            token: '',
            orgBarcode: '',
            tarBarcode: '',
            dataList: [],
            orgBarcodeFocus: true,
            tarBarcodeFocus: false,
            devNo: '',
            // 编辑表单
            editForm: {
                index: -1,
                matnr: '',
                standby1: '',
                weight: '',
                count: 0
            },
            // 待移除项索引
            removeIndex: -1,
            // 消息提示
            msgType: 'success',
            messageText: '',
            // 组托按钮防抖
            isCombing: false
        }
    },
 
    onShow() {
        this.baseUrl = uni.getStorageSync('baseUrl')
        this.token = uni.getStorageSync('token')
    },
 
    methods: {
        itemWorkQtyChange(item) {},
        // 显示消息提示
        showMessage(text, type = 'success') {
            this.msgType = type
            this.messageText = text
            this.$refs.message.open()
        },
 
        // 重置光标焦点
        resetFocus(field) {
            this[field] = false
            setTimeout(() => {
                this[field] = true
            }, 100)
        },
 
        // 处理授权错误
        handleAuthError(msg) {
            this.showMessage(msg, 'error')
            setTimeout(() => {
                uni.reLaunch({ url: '../login/login' })
            }, 1000)
        },
 
        // 源托盘输入事件
        barcodeInput() {
            setTimeout(() => {
                const len = this.orgBarcode.length
                if (len > 0 && len < 8) {
                    uni.showToast({
                        title: '托盘码有误请重试',
                        icon: 'none',
                        position: 'top'
                    })
                    this.orgBarcode = ''
                    this.resetFocus('orgBarcodeFocus')
                    return
                }
                this.resetFocus('tarBarcodeFocus')
            }, 200)
            this.search()
        },
        search() {
            let that = this
            uni.request({
                url: that.baseUrl + '/mobile/agv/collectionPakin/view',
                header: {
                    token: uni.getStorageSync('token')
                },
                data: JSON.stringify({
                    orgBarcode: that.orgBarcode
                }),
                method: 'POST',
                success(res) {
                    res = res.data
                    if (res.code === 200) {
                        that.dataList = res.data.map((item) => ({
                            ...item,
                            workQty: item.anfme
                        }))
                    } else if (res.code == 403) {
                        that.messageText = res.msg
                        that.messageToggle('error')
                        setTimeout(() => {
                            uni.reLaunch({
                                url: '../login/login'
                            })
                        }, 1000)
                    } else {
                        that.showMessage(res.msg, 'error')
                    }
                }
            })
        },
        // 搜索物料
        findMat() {
            if (!this.tarBarcode) return
 
            setTimeout(() => {
                uni.request({
                    url: `${this.baseUrl}/mat/auth`,
                    data: { matnr: this.tarBarcode },
                    header: { token: this.token },
                    success: (result) => {
                        const res = result.data
                        if (res.code === 200 && res.data) {
                            this.navigateToMatSelect(res.data)
                        } else if (res.code === 403) {
                            this.handleAuthError(res.msg)
                        } else {
                            uni.showToast({
                                title: res.msg,
                                icon: 'none',
                                position: 'top'
                            })
                        }
                    }
                })
            }, 200)
        },
 
        // 跳转物料选择页
        navigateToMatSelect(matData) {
            matData.batch = ''
            uni.navigateTo({
                url: '../mat/matSelected',
                success: (res) => {
                    res.eventChannel.emit('mat', { data: [matData] })
                },
                events: {
                    matList: (data) => {
                        this.checkMat(data.data)
                        this.tarBarcode = ''
                        this.resetFocus('tarBarcodeFocus')
                    }
                }
            })
        },
 
        // 选择物料
        selectMat() {
            uni.navigateTo({
                url: '../mat/matQuery',
                success: (res) => {
                    res.eventChannel.emit('commonUrl', { commonUrl: '' })
                },
                events: {
                    acceptDataFromOpenedPage: (data) => {
                        this.tarBarcode = data.data
                        this.findMat()
                    }
                }
            })
        },
 
        // 检查并添加物料
        checkMat(mat) {
            const existIndex = this.dataList.findIndex(
                (item) => item.matnr === mat.matnr && item.batch === mat.batch
            )
 
            if (existIndex > -1) {
                // 相同物料相同批号,数量累加
                this.dataList[existIndex].anfme += mat.anfme
                this.$forceUpdate()
            } else {
                // 新增到列表头部
                this.dataList.unshift(mat)
            }
        },
 
        // 打开修改弹窗
        revise(index) {
            const item = this.dataList[index]
            this.editForm = {
                index,
                matnr: item.matnr,
                standby1: item.standby1,
                weight: item.weight,
                count: item.anfme
            }
            this.$refs.revisePopup.open()
        },
 
        // 数量变更
        changeValue(value) {
            this.editForm.count = value
        },
 
        // 确认修改
        reviseConfirm() {
            const { index, count, standby1, weight } = this.editForm
            this.dataList[index].anfme = count
            this.dataList[index].standby1 = standby1
            this.dataList[index].weight = weight
            this.$refs.revisePopup.close()
            this.showMessage('修改成功')
        },
 
        // 关闭修改弹窗
        reviseClose() {
            this.$refs.revisePopup.close()
        },
 
        // 打开移除确认弹窗
        remove(index) {
            this.removeIndex = index
            this.$refs.removeDialog.open()
        },
 
        // 确认移除
        removeConfirm() {
            this.dataList.splice(this.removeIndex, 1)
            this.showMessage('移除成功')
        },
 
        // 关闭移除弹窗
        removeClose() {
            this.$refs.removeDialog.close()
        },
 
        // 打开组托确认弹窗
        combConfirm() {
            if (!this.orgBarcode) {
                this.showMessage('请扫描源托盘条码', 'error')
                return
            }
            if (this.dataList.length === 0) {
                this.showMessage('请添加商品列表', 'error')
                return
            }
            if (!this.tarBarcode) {
                this.showMessage('请扫描目标托盘条码', 'error')
                return
            }
            const invalidItem = this.dataList.find(
                (item) => !item.anfme || item.anfme === 0
            )
            if (invalidItem) {
                this.showMessage(
                    `${invalidItem.matnr} 组托数量不能为0`,
                    'error'
                )
                return
            }
            this.$refs.combDialog.open()
        },
 
        // 关闭组托弹窗
        combClose() {
            this.$refs.combDialog.close()
        },
 
        // 执行组托
        comb() {
            if (this.isCombing) return
            this.isCombing = true
            uni.vibrateShort()
 
            uni.request({
                url: `${this.baseUrl}/mobile/agv/collectionPakin/auth`,
                method: 'POST',
                data: JSON.stringify({
                    orgBarcode: this.orgBarcode,
                    tarBarcode: this.tarBarcode,
                    devNo: this.devNo,
                    combMats: this.dataList
                }),
                header: { token: this.token },
                success: (result) => {
                    const res = result.data
                    if (res.code === 200) {
                        this.clearAll()
                        this.showMessage(res.msg, 'success')
                        // this.showMessage('组托成功')
                        // // 播放成功提示音
                        // const audio = uni.createInnerAudioContext()
                        // audio.src = '/static/music/pakinOk.mp3'
                        // audio.play()
                    } else if (res.code === 403) {
                        this.handleAuthError(res.msg)
                    } else {
                        this.showMessage(res.msg, 'error')
                    }
                },
                complete: () => {
                    // 请求完成后解除防抖锁定
                    setTimeout(() => {
                        this.isCombing = false
                    }, 500)
                }
            })
        },
 
        // 打开重置确认弹窗
        reset() {
            this.$refs.resetDialog.open()
        },
 
        // 确认重置
        resetConfirm() {
            this.clearAll()
            this.showMessage('重置完成')
        },
 
        // 关闭重置弹窗
        resetClose() {
            this.$refs.resetDialog.close()
        },
 
        // 清空所有数据
        clearAll() {
            this.dataList = []
            this.orgBarcode = ''
            this.tarBarcode = ''
            this.devNo = ''
            this.resetFocus('orgBarcodeFocus')
        }
    }
}
</script>
 
<style>
@import url('../../static/css/wms.css/wms.css');
 
.code {
    width: 100%;
    position: fixed;
    min-height: 200rpx;
    background-color: #fff;
    z-index: 10;
}
 
.item {
    display: flex;
    align-items: center;
    height: 100rpx;
    margin-left: 20rpx;
    border-bottom: 1px solid #dcdfe6;
}
 
.item input {
    height: 50rpx;
    line-height: 50rpx;
    font-size: 36upx;
    font-family: PingFang SC;
    width: 55vw;
}
 
.code-decs {
    width: 20vw;
    font-size: 18px;
    color: #303133;
}
 
.item-right {
    margin-left: auto;
    margin-right: 20rpx;
}
 
.mat-list-title {
    height: 80rpx;
    line-height: 80rpx;
    width: 100%;
    background-color: white;
    position: fixed;
    margin-top: 300rpx;
    z-index: 9;
    text-align: center;
    box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.5);
}
 
.list:first-child {
    margin-top: 400rpx;
}
 
.empty-tips {
    text-align: center;
    color: #909399;
    padding: 100rpx 0;
    margin-top: 300rpx;
}
.tip {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
</style>