helongyang
2026-03-31 8fcd7a67e4391a5f1fbdb590c2a3f913aeb2a0a0
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
<template>
    <view class="page-container">
        <!-- 顶部导航栏 -->
        <view class="nav-header">
            <uni-segmented-control 
                :current="current" 
                :values="items" 
                @clickItem="onClickItem"
                class="segmented-control"
            >
            </uni-segmented-control>
        </view>
        
        <!-- 主内容区 -->
        <view class="main-content">
            <!-- 组盘模块 -->
            <view v-if="current === 0" class="card-container">
                <!-- 组盘表单卡片 -->
                <view class="form-card">
                    <uni-forms class="form-wrapper" label-width="80px">
                        <uni-forms-item label="托盘条码:" class="form-item">
                            <uni-easyinput 
                                type="text" 
                                placeholder="请扫描托盘条码" 
                                :focus="barcodeFocus"
                                v-model="barcode" 
                                @confirm="onBarcodeConfirm"
                                class="input-field"
                                :disabled="isSubmitting"
                            />
                        </uni-forms-item>
                        
                        <uni-forms-item label="内箱标签:" class="form-item">
                            <uni-easyinput 
                                type="text" 
                                placeholder="请扫描内箱标签" 
                                :focus="materSnFocus"
                                v-model="materSn" 
                                @confirm="onMaterSnConfirm"
                                class="input-field"
                                :disabled="isSubmitting"
                            />
                        </uni-forms-item>
                        
                        <uni-forms-item :label="Testlabel" v-if="Test" class="form-item">
                            <uni-easyinput 
                                type="text" 
                                :placeholder="Testplaceholder" 
                                v-model="Initiallife"
                                class="input-field"
                                :disabled="isSubmitting"
                            />
                        </uni-forms-item>
                        
                        <view class="form-actions">
                            <button 
                                @click="submit" 
                                type="primary" 
                                class="btn-primary"
                                :disabled="isSubmitting"
                            >
                                <uni-icons type="refresh" size="16" v-if="isSubmitting"></uni-icons>
                                {{isSubmitting ? '组盘中...' : '组盘'}}
                            </button>
                        </view>
                    </uni-forms>
                </view>
                
                <!-- 物料信息列表 -->
                <view class="list-card" v-if="matInfos.length > 0">
                    <view class="list-header">
                        <text class="list-title">物料信息</text>
                        <text class="count-badge">1</text>
                    </view>
                    
                    <uni-list class="material-list">
                        <uni-list-item 
                            direction="column" 
                            v-for="(item,index) in matInfos" 
                            :key="index"
                            class="list-item"
                        >
                            <template v-slot:body>
                                <view class="list-item-content">
                                    <uni-icons 
                                        type="trash" 
                                        size="20" 
                                        class="delete-icon"
                                        @click="deleteList(index)"
                                        :disabled="isSubmitting"
                                    >
                                    </uni-icons>
                                    
                                    <view class="info-grid">
                                        <view class="info-row">
                                            <text class="label">采购单号:</text>
                                            <text class="value">{{item.purchaseOrderNo}}</text>
                                        </view>
                                        <view class="info-row">
                                            <text class="label">物料编码:</text>
                                            <text class="value">{{item.materielCode}}</text>
                                        </view>
                                        <view class="info-row">
                                            <text class="label">批次号:</text>
                                            <text class="value">{{item.lotNo}}</text>
                                        </view>
                                        <view class="info-row">
                                            <text class="label">数量:</text>
                                            <text class="value">{{item.quantity}}</text>
                                        </view>
                                        <view class="info-row">
                                            <text class="label">生产日期:</text>
                                            <text class="value">{{item.productionDate}}</text>
                                        </view>
                                        <view class="info-row">
                                            <text class="label">有效期:</text>
                                            <text class="value">{{item.effectiveDate}}</text>
                                        </view>
                                        <view class="info-row">
                                            <text class="label">物料长度:</text>
                                            <text class="value">{{item.materielLength}}</text>
                                        </view>
                                    </view>
                                </view>
                            </template>
                        </uni-list-item>
                    </uni-list>
                </view>
                
                <!-- 空状态提示 -->
                <view class="empty-state" v-if="matInfos.length === 0 && barcode">
                    <uni-icons type="empty" size="60" color="#ccc"></uni-icons>
                    <text class="empty-text">暂无物料信息,请扫描内箱标签</text>
                </view>
            </view>
            
            <!-- 入库模块(保持不变) -->
            <view v-if="current === 1" class="card-container">
                <view class="form-card">
                    <uni-forms class="form-wrapper" label-width="80px">
                        <uni-forms-item label="托盘条码:" class="form-item">
                            <uni-easyinput 
                                type="text" 
                                placeholder="请扫描托盘条码" 
                                :focus="!addressFocus"
                                v-model="inboundBarcode" 
                                @confirm="inputChangebarcode"
                                class="input-field"
                                :disabled="isInboundSubmitting"
                            />
                        </uni-forms-item>
                        
                        <uni-forms-item label="地址条码:" class="form-item">
                            <uni-easyinput 
                                type="text" 
                                placeholder="请扫描地址条码" 
                                :focus="addressFocus"
                                v-model="address" 
                                class="input-field"
                                :disabled="addressdisabled || isInboundSubmitting"
                            />
                        </uni-forms-item>
                        
                        <view class="form-actions">
                            <button 
                                @click="inbound" 
                                type="primary" 
                                class="btn-primary"
                                :disabled="isInboundSubmitting"
                            >
                                <uni-icons type="refresh" size="16" v-if="isInboundSubmitting"></uni-icons>
                                {{isInboundSubmitting ? '入库中...' : '入库确认'}}
                            </button>
                        </view>
                    </uni-forms>
                </view>
                
                <view class="list-card" v-if="inboundBarcode">
                    <view class="summary-card" v-if="Summmary > 0">
                        <text class="summary-label">组盘总数量:</text>
                        <text class="summary-value">{{Summmary}}</text>
                    </view>
                    
                    <uni-list class="material-list" v-if="stockInfoDetail.length > 0">
                        <uni-list-item direction="column" v-for="(item,index) in stockInfoDetail" :key="index">
                            <template v-slot:body>
                                <view class="list-item-content">
                                    <view class="info-grid">
                                        <view class="info-row"><text class="label">物料编号:</text><text class="value">{{item.materielCode}}</text></view>
                                        <view class="info-row"><text class="label">物料名称:</text><text class="value">{{item.materielName}}</text></view>
                                        <view class="info-row"><text class="label">物料批次:</text><text class="value">{{item.batchNo}}</text></view>
                                        <view class="info-row"><text class="label">组盘数量:</text><text class="value">{{item.stockQuantity}}</text></view>
                                        <view class="info-row"><text class="label">生产日期:</text><text class="value">{{item.productionDate}}</text></view>
                                        <view class="info-row"><text class="label">有效期:</text><text class="value">{{item.effectiveDate}}</text></view>
                                    </view>
                                </view>
                            </template>
                        </uni-list-item>
                    </uni-list>
                </view>
            </view>
        </view>
        
        <u-toast ref="uToast" />
    </view>
</template>
 
<script>
    const innerAudioContext = uni.createInnerAudioContext();
    export default {
        data() {
            return {
                items: ['组盘', '入库'],
                current: 0,
                // 组盘模块数据
                matInfos: [],
                orderNo: "",
                barcode: "",
                materSn: "",
                Initiallife: 1000,
                sns: [],
                // 组盘焦点控制
                barcodeFocus: true,   // 托盘条码初始获得焦点
                materSnFocus: false,  // 内箱标签焦点
                // 入库模块数据
                addressFocus: false,
                inboundBarcode: "",
                address: "",
                warehouseId: "",
                Test: false,
                Testlabel: "",
                Testplaceholder: "",
                Testcheck: false,
                Summmary: 0,
                stockInfoDetail: [],
                addressdisabled: false,
                isSubmitting: false,
                isInboundSubmitting: false
            }
        },
        onLoad(res) {
            this.orderNo = res.orderNo;
            this.warehouseId = res.warehouseId;
            
            if (this.warehouseId == 6) {
                this.Test = true;
                this.Testlabel = "初始寿命:";
                this.Testplaceholder = "请输入初始寿命";
            } else if (this.warehouseId == 2) {
                this.Test = true;
                this.Testlabel = "数量:";
                this.Testplaceholder = "请输入数量";
                this.Initiallife = 16;
            } else if (this.warehouseId == 3) {
                this.address = "1011";
                this.addressdisabled = true;
            }
            
            // 确保初始焦点在托盘条码
            this.barcodeFocus = true;
            this.materSnFocus = false;
        },
        methods: {
            getData() {},
            onClickItem(e) {
                this.current = e.currentIndex;
                // 切换选项卡时重置焦点
                if (this.current === 0) {
                    this.barcodeFocus = true;
                    this.materSnFocus = false;
                } else {
                    this.addressFocus = false;
                }
            },
            
            // ==================== 组盘模块焦点跳转 ====================
            /**
             * 托盘条码扫描确认
             * 扫描后自动跳转到内箱标签输入框
             */
            onBarcodeConfirm() {
                if (!this.barcode || this.barcode.trim() === '') {
                    this.$refs.uToast.show({
                        title: "请扫描托盘条码",
                        type: 'error'
                    });
                    // 保持焦点在托盘条码框
                    this.barcodeFocus = true;
                    this.materSnFocus = false;
                    return;
                }
                // 托盘码有效,跳转到内箱标签
                this.barcodeFocus = false;
                this.materSnFocus = true;
            },
            
            /**
             * 内箱标签扫描确认
             * 自动解析内箱码,清空输入框,焦点保留在内箱标签框
             */
            onMaterSnConfirm() {
                if (!this.materSn || this.materSn.trim() === '') {
                    this.$refs.uToast.show({
                        title: "请扫描内箱标签",
                        type: 'error'
                    });
                    return;
                }
                
                // 特殊处理:仓库11时去掉后缀
                let snToProcess = this.materSn;
                if (this.warehouseId == 11) {
                    snToProcess = snToProcess.replace(/,SC.*/, '');
                }
                
                // 内箱码格式校验(必须包含7个字段,以逗号分隔)
                if (snToProcess.split(',').length != 7) {
                    this.$refs.uToast.show({
                        title: "内箱码格式错误,请重新扫描",
                        type: 'error'
                    });
                    // 清空输入框,便于重新扫描
                    this.materSn = "";
                    // 焦点不动(materSnFocus 已是 true)
                    return;
                }
                
                // 发起后端解析请求
                this.$u.post('/api/MaterielInfo/PPPKCodeAnalysis?serNum=' + snToProcess, {})
                    .then(res => {
                        if (res.status) {
                            // 解析成功:替换为最新的内箱码(只保留一个)
                            this.sns = [res.data.serialNumber];
                            this.matInfos = [res.data];
                            
                            this.$refs.uToast.show({
                                title: "内箱码已更新",
                                type: "success",
                                duration: 1500
                            });
                            // 清空输入框,为下一次扫描做准备(焦点仍在内箱码框)
                            this.materSn = "";
                            // 焦点不动,保持在内箱码框(materSnFocus 已是 true)
                        } else {
                            this.$refs.uToast.show({
                                title: res.message,
                                type: "error"
                            });
                            // 解析失败,清空输入框,让用户重新扫描
                            this.materSn = "";
                        }
                    })
                    .catch(err => {
                        this.$refs.uToast.show({
                            title: err.message || "解析失败",
                            type: "error"
                        });
                        this.materSn = "";
                    });
            },
            
            // 删除内箱码(清空)
            deleteList() {
                if (this.isSubmitting) return;
                this.matInfos = [];
                this.sns = [];
                this.$refs.uToast.show({
                    title: "内箱码已清空",
                    type: "info"
                });
                // 焦点保留在内箱码框
            },
            
            // ==================== 组盘提交 ====================
            submit() {
                if (this.isSubmitting) return;
                if (!this.barcode) {
                    this.$refs.uToast.show({ title: "请扫描托盘条码", type: 'error' });
                    this.resetFocusToBarcode();
                    return;
                }
                if (this.matInfos.length === 0) {
                    this.$refs.uToast.show({ title: "请扫描内箱标签", type: 'error' });
                    this.resetFocusToMaterSn();
                    return;
                }
                if (this.Test && !this.Testcheck) {
                    this.Testcheck = true;
                    this.$refs.uToast.show({
                        title: this.warehouseId == 2 ? "请确认数量" : "请确认初始寿命",
                        type: 'error'
                    });
                    return;
                }
 
                if (this.warehouseId == 2) {
                    let sn = this.sns[0];
                    this.sns = Array(this.Initiallife).fill(sn);
                }
 
                this.isSubmitting = true;
                let url = `palletCode=${this.barcode}&initiallife=${this.Initiallife}&warehouseId=${this.warehouseId}`;
 
                this.$u.post('/api/InboundOrder/PPPKManualMaterielGroup?' + url, this.sns)
                    .then(res => {
                        if (res.status) {
                            this.$refs.uToast.show({ title: "组盘成功", type: "success" });
                            // 重置表单
                            this.barcode = "";
                            this.matInfos = [];
                            this.sns = [];
                            // 重置焦点:回到托盘条码框,开始新的一轮
                            this.resetFocusToBarcode();
                        } else {
                            this.$refs.uToast.show({ title: res.message, type: "error" });
                        }
                    })
                    .finally(() => {
                        this.isSubmitting = false;
                    });
            },
            
            // ==================== 焦点重置辅助 ====================
            resetFocusToBarcode() {
                this.barcodeFocus = true;
                this.materSnFocus = false;
            },
            resetFocusToMaterSn() {
                this.barcodeFocus = false;
                this.materSnFocus = true;
            },
            
            // ==================== 入库模块(保持原逻辑) ====================
            inputChangebarcode() {
                this.addressFocus = false;
                this.$nextTick(() => {
                    if (!this.inboundBarcode) return;
                    this.addressFocus = true;
                    this.$u.post('/api/StockInfo/StockQueryData', {
                        MainData: { barcode: this.inboundBarcode, warehouseId: this.warehouseId }
                    }).then(res => {
                        this.stockInfoDetail = [];
                        this.Summmary = 0;
                        if (res.status) {
                            this.stockInfoDetail = res.data.details;
                            this.stockInfoDetail.forEach(item => {
                                this.Summmary += item.stockQuantity;
                            });
                        } else {
                            this.$refs.uToast.show({ title: res.message, type: "error" });
                        }
                    })
                })
            },
            
            inbound() {
                if (this.isInboundSubmitting) return;
                if (!this.inboundBarcode) {
                    this.$refs.uToast.show({ title: "请扫描托盘条码", type: "error" });
                    return;
                }
                if (!this.address) {
                    this.$refs.uToast.show({ title: "请扫描地址条码", type: "error" });
                    return;
                }
 
                this.isInboundSubmitting = true;
                this.$u.post('/api/Task/PPPKRequestInboundTask', {
                    MainData: {
                        barcode: this.inboundBarcode,
                        startPoint: this.address,
                        warehouseId: this.warehouseId
                    }
                }).then(res => {
                    if (res.status) {
                        this.inboundBarcode = "";
                        if (this.warehouseId != 3) this.address = "";
                        this.stockInfoDetail = [];
                        this.Summmary = 0;
                        this.$refs.uToast.show({ title: "入库成功", type: "success" });
                    } else {
                        this.$refs.uToast.show({ title: res.message, type: "error" });
                    }
                }).finally(() => {
                    this.isInboundSubmitting = false;
                });
            }
        }
    }
</script>
 
<style lang="scss">
    @import '@/common/uni-ui.scss';
    page { background-color: #f5f7fa; font-size: 14px; color: #333; }
    .page-container { min-height: 100vh; display: flex; flex-direction: column; }
    .nav-header { background: #fff; padding: 12px 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
    .segmented-control { border-radius: 8px; --uni-segmented-control-height: 40px; }
    .main-content { flex: 1; padding: 16px; }
    .card-container { display: flex; flex-direction: column; gap: 16px; }
    .form-card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.04); }
    .form-item { margin-bottom: 16px; }
    .input-field { border-radius: 8px; height: 44px; }
    .form-actions { margin-top: 10px; }
    .btn-primary { width: 100%; height: 48px; border-radius: 8px; }
    .list-card { background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 12px rgba(0,0,0,0.04); }
    .list-header { padding: 16px; border-bottom: 1px solid #f0f0f0; display: flex; justify-content: space-between; }
    .count-badge { background: #e6f4ff; color: #165dff; padding: 2px 8px; border-radius: 20px; font-size: 12px; }
    .list-item-content { position: relative; padding: 16px; }
    .delete-icon { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: #ef4444; }
    .info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
    .info-row { display: flex; flex-direction: column; }
    .label { font-size: 12px; color: #6b7280; }
    .value { font-size: 14px; color: #222; font-weight: 500; }
    .summary-card { padding: 16px; background: #e6f4ff; font-size: 15px; }
    .summary-value { font-weight: bold; color: #165dff; margin-left: 6px; }
    .empty-state { padding: 50px 20px; text-align: center; color: #999; }
</style>