1
yangpeixing
2026-03-12 9181f3dce9e6f617b34fa80b7bb72bb490be788b
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
<template>
    <view>
        <view class="itemstyle">
            <uni-forms label-width="180">
                <uni-forms-item label="托盘条码:">
                    <uni-easyinput type="text" placeholder="请扫描托盘条码" ref='midInput' :focus="!focus" v-model="palletCode"
                        @input="barcodeInput" @confirm="handleScanConfirm" />
                </uni-forms-item>
                <uni-forms-item>
                    <button @click="AGVTasks" type="primary" size="default" style="margin-top: 2%;">确认完成</button>
                </uni-forms-item>
            </uni-forms>
 
            <!-- 库存明细展示区域 -->
            <view v-if="stockDetails.length > 0" class="stock-details-container">
                <uni-list>
                    <uni-list-item v-for="(detail, index) in stockDetails" :key="index" :title="`明细 ${index + 1}`"
                        :showArrow="false">
                        <template v-slot:body>
                            <view class="detail-content">
                                <view class="detail-row">
                                    <text class="detail-label">物料编码:</text>
                                    <text class="detail-value">{{ detail.materielCode || '无' }}</text>
                                </view>
                                <view class="detail-row">
                                    <text class="detail-label">批次号:</text>
                                    <text class="detail-value">{{ detail.batchNo || '无' }}</text>
                                </view>
                                <view class="detail-row">
                                    <text class="detail-label">数量:</text>
                                    <view class="quantity-container">
                                        <input type="number" :value="detail.stockQuantity || detail.quantity || 0"
                                            @input="handleQuantityChange($event, index)" placeholder="请输入数量"
                                            class="quantity-input" />
                                        <text class="quantity-unit">{{ detail.unit || '' }}</text>
                                    </view>
                                </view>
                            </view>
                        </template>
                    </uni-list-item>
                </uni-list>
 
                <view class="summary-info">
                    <text class="summary-label" style="margin-left: 20rpx;">明细总数:</text>
                    <text class="summary-value">{{ stockDetails.length }} 条</text>
                </view>
            </view>
 
            <!-- 无数据提示 -->
            <view v-else-if="palletCode && !loading" class="no-data">
                <uni-icons type="info" size="24" color="#999"></uni-icons>
                <text class="no-data-text">未找到该托盘的库存明细</text>
            </view>
 
            <!-- 加载中 -->
            <view v-if="loading" class="loading">
                <uni-load-more status="loading" content="正在查询库存明细..."></uni-load-more>
            </view>
        </view>
        <u-toast ref="uToast" />
    </view>
</template>
 
<script>
    const innerAudioContext = uni.createInnerAudioContext();
    export default {
        data() {
            return {
                focus: false,
                palletCode: "",
                warehouseId: "",
                stockDetails: [], // 库存明细列表
                loading: false,
                timer: null,
            }
        },
        onShow() {},
        onLoad(res) {
            this.focus = false;
            this.warehouseId = res.warehouseId;
        },
        methods: {
            barcodeInput() {
                this.$nextTick(function(x) {
                    if (this.barcode.length > 0) {
                        this.focus = true;
                    }
                })
 
                // 防抖处理,扫描完成后自动查询
                clearTimeout(this.timer);
                this.timer = setTimeout(() => {
                    if (this.palletCode.length > 0) {
                        this.queryStockDetails();
                    }
                }, 500);
            },
 
            handleScanConfirm() {
                // 扫码枪回车确认
                if (this.palletCode.length > 0) {
                    this.queryStockDetails();
                }
            },
 
            // 处理数量变化
            handleQuantityChange(event, index) {
                const value = event.detail ? event.detail.value : event.target.value;
                // 确保 value 是数字
                const numValue = parseFloat(value) || 0;
 
                // 更新对应明细的数量
                this.stockDetails[index].stockQuantity = numValue;
 
                // 触发更新,确保数据响应式
                this.$set(this.stockDetails, index, {
                    ...this.stockDetails[index]
                });
            },
 
            // 查询库存明细
            queryStockDetails() {
                if (!this.palletCode.trim()) {
                    return;
                }
 
                this.loading = true;
                this.stockDetails = [];
 
                var postDate = {
                    MainData: {
                        palletCode: this.palletCode,
                        warehouseId: this.warehouseId,
                    }
                }
 
                this.$u.post('/api/StockInfo/GetStockDetails', postDate).then(res => {
                    console.log("接口返回数据:", res.data); // 调试用
 
                    if (res && res.status) {
                        // 后端返回的是 stockInfo.Details 数组,在 res.data 中
                        this.stockDetails = res.data;
 
                        // 如果 data 不是数组,尝试从对象中提取数组
                        if (!Array.isArray(this.stockDetails) && res.data) {
                            console.warn("返回的数据不是数组:", res.data);
                            // 尝试从对象中提取数组
                            if (Array.isArray(res.data.Details)) {
                                this.stockDetails = res.data.Details;
                            } else if (Array.isArray(res.data.data)) {
                                this.stockDetails = res.data.data;
                            } else {
                                this.stockDetails = [];
                            }
                        }
 
                        // 确保 stockDetails 是数组
                        if (!Array.isArray(this.stockDetails)) {
                            this.stockDetails = [];
                        }
 
                        // 初始化 stockQuantity 字段(如果不存在)
                        this.stockDetails.forEach(item => {
                            if (!item.hasOwnProperty('stockQuantity')) {
                                // 如果原始数据有 quantity 字段,复制到 stockQuantity
                                item.stockQuantity = item.quantity || 0;
                            }
                        });
 
                        if (this.stockDetails.length === 0) {
                            this.$refs.uToast.show({
                                title: "该托盘无库存明细记录",
                                type: 'warning'
                            })
                        } else {
                            this.$refs.uToast.show({
                                title: `找到 ${this.stockDetails.length} 条明细记录`,
                                type: 'success',
                                duration: 1500
                            })
                        }
                    } else {
                        this.$refs.uToast.show({
                            title: res?.message || "查询失败",
                            type: "error"
                        })
                    }
                }).catch(error => {
                    console.error("查询库存明细失败:", error);
                    this.$refs.uToast.show({
                        title: "查询失败,请稍后重试",
                        type: "error"
                    })
                }).finally(() => {
                    this.loading = false;
                });
            },
 
            AGVTasks() {
                if (!this.palletCode) {
                    this.$refs.uToast.show({
                        title: "请扫描托盘条码",
                        type: 'error'
                    })
                    return;
                }
 
                if (this.stockDetails.length === 0) {
                    this.$refs.uToast.show({
                        title: "请先查询库存明细",
                        type: 'error'
                    })
                    return;
                }
 
                // 准备提交的数据
                const detailsToSubmit = this.stockDetails.map(detail => ({
                    materielCode: detail.materielCode || '',
                    batchNo: detail.batchNo || '',
                    stockQuantity: detail.stockQuantity || detail.quantity || 0,
                    unit: detail.unit || ''
                }));
 
                // 过滤掉无效数据
                const validDetails = detailsToSubmit.filter(item => 
                    item.materielCode && item.batchNo && item.stockQuantity > 0
                );
 
                if (validDetails.length === 0) {
                    this.$refs.uToast.show({
                        title: "请填写有效的物料信息",
                        type: 'error'
                    })
                    return;
                }
 
                // 构造提交数据
                var postDates = {
                    MainData: {
                        palletCode: this.palletCode,
                        warehouseId: this.warehouseId,
                        details: validDetails // 传递所有有效的明细数据
                    }
                }
 
                console.log("提交的数据:", postDates);
 
                this.$u.post('/api/StockInfo/UpdateGetStockDetails', postDates).then(
                    res => {
                        if (res.status) {
                            this.$refs.uToast.show({
                                title: "任务创建成功",
                                type: "success"
                            })
                            // 清空数据
                            this.palletCode = "";
                            this.stockDetails = [];
                            this.focus = false;
                        } else {
                            this.$refs.uToast.show({
                                title: res.message || "任务创建失败",
                                type: "error"
                            })
                        }
                    }).catch(error => {
                    console.error("提交任务失败:", error);
                    this.$refs.uToast.show({
                        title: "网络错误,请重试",
                        type: "error"
                    })
                })
            }
        }
    }
</script>
 
<style lang="scss">
    @import '@/common/uni-ui.scss';
 
    .content {
        display: flex;
        height: 150px;
    }
 
    .content-text {
        font-size: 14px;
        color: #666;
    }
 
    .itemstyle {
        margin-top: 30px;
        margin-left: 5%;
    }
 
    .headerstyle {
        width: 90%;
    }
 
    /* 库存明细容器 */
    .stock-details-container {
        margin-top: 30rpx;
    }
 
    /* 明细内容样式 */
    .detail-content {
        padding: 20rpx 0;
    }
 
    .detail-row {
        display: flex;
        flex-direction: row;
        margin-bottom: 12rpx;
        padding: 8rpx 0;
        border-bottom: 1rpx solid #f0f0f0;
 
        &:last-child {
            border-bottom: none;
        }
 
        .detail-label {
            width: 140rpx;
            color: #666;
            font-size: 26rpx;
            font-weight: bold;
            flex-shrink: 0;
        }
 
        .detail-value {
            flex: 1;
            color: #333;
            font-size: 26rpx;
            word-break: break-all;
            padding-left: 20rpx;
        }
    }
 
    /* 数量输入框样式 */
    .quantity-container {
        display: flex;
        align-items: center;
        flex: 1;
    }
 
    .quantity-input {
        flex: 1;
        padding: 8rpx 16rpx;
        border: 1rpx solid #e0e0e0;
        border-radius: 6rpx;
        font-size: 26rpx;
        color: #333;
        background-color: #fff;
        margin-right: 10rpx;
        width: 250rpx;
        height: 30px;
 
        &:focus {
            border-color: #409EFF;
            outline: none;
        }
    }
 
    .quantity-unit {
        color: #333;
        font-size: 26rpx;
        width: 300rpx;
        flex-shrink: 0;
        padding-left: 10rpx;
    }
 
    /* 合计信息 */
    .summary-info {
        margin-top: 30rpx;
        padding: 20rpx;
        background-color: #f5f7fa;
        border-radius: 8rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
 
        .summary-label {
            color: #333;
            font-size: 28rpx;
            font-weight: bold;
            margin-right: 10rpx;
        }
 
        .summary-value {
            color: #409EFF;
            font-size: 28rpx;
            font-weight: bold;
            margin-right: 30rpx;
        }
    }
 
    /* 无数据样式 */
    .no-data {
        margin-top: 60rpx;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 60rpx 40rpx;
        background-color: #f9f9f9;
        border-radius: 12rpx;
 
        .no-data-text {
            margin-top: 20rpx;
            color: #999;
            font-size: 28rpx;
        }
    }
 
    /* 加载中样式 */
    .loading {
        margin-top: 60rpx;
        text-align: center;
        padding: 40rpx;
    }
</style>