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
<template>
    <view class="container">
        <view class="header">
            <view class="item">
                <view class="left">条码编号:</view>
                <view class="right">
                    <input name="HBarCode" v-model="barCodeInfoMeta.barCodeNo" placeholder="请扫描条码"
                        @confirm="searchbarCodeInfo" />
                </view>
                <view>
                    <uni-icons type="scan"
                        style="background-color: #3A78FF;padding: 6rpx;color: #fff;border-radius: 100%;font-weight: 500;"
                        size="20" @click="toScanCode"></uni-icons>
                </view>
            </view>
            <view class="item">
                <view class="left">拆码数量:</view>
                <view class="right">
                    <input type="number" name="HSplitNum" v-model="barCodeInfoMeta.splitNum" placeholder="请输入拆码数量" />
                </view>
            </view>
            <view class="item">
                <view class="left">制单人:</view>
                <view class="right">
                    <input type="text" disabled name="HMaker" v-model="barCodeInfoMeta.billMaker"
                        placeholder="请输入制单人" />
                </view>
            </view>
            <view class="operation-zone">
                <button class="btn-c" @click="searchbarCodeInfoMeta">拆码</button>
                <button type="default" :class="cantGenerate?'':'btn-c'" @click="SaveBarCodeCreate"
                    :disabled="cantGenerate">生成</button>
            </view>
        </view>
        <view class="divide"></view>
        <view class="content">
            <view class="barcode-detail" v-show="CommonUtils.isEmpty(Object.assign(barCodeInfo, {})) === false">
                <view class="title">条码信息</view>
                <uni-card>
                    <view class="detail">
                        <text>条码号:</text>{{barCodeInfo['条码编号'] || ''}}
                    </view>
                    <view class="detail">
                        <text>原数量:</text>{{barCodeInfo['数量'] || '0'}}
                    </view>
                    <view class="dWetail">
                        <text>物料编码:</text>{{barCodeInfo['物料代码'] || ''}}
                    </view>
                    <view class="detail">
                        <text>物料名称:</text>{{barCodeInfo['物料名称'] || ''}}
                    </view>
                    <view class="detail">
                        <text>规格型号:</text>{{barCodeInfo['规格型号'] || ''}}
                    </view>
                    <view class="detail">
                        <text>计量单位:</text>{{barCodeInfo['计量单位'] || ''}}
                    </view>
                </uni-card>
            </view>
            <view class="divide"></view>
            <view class="barcode-split" v-show="barCodeSplitInfo.length>0">
                <view class="title">条码拆码</view>
                <view class="barcode-split-list" v-for="(item,index) in barCodeSplitInfo" :key="index">
                    <uni-card @tap="ModityHQty(item)">
                        <view class="detail">
                            <text>条码编号:</text>{{item['HBarCode'] || ''}}
                        </view>
                        <view class="detail">
                            <text>条码数量:</text>{{item['HQty'] || '0'}}
                        </view>
                        <view class="detail split-num">
                            <text>拆分数量:</text>{{item['HSplitNum'] || '0'}}
                        </view>
                        <view class="detail">
                            <text>物料代码:</text>{{item['HNumber'] || ''}}
                        </view>
                        <view class="detail">
                            <text>物料名称:</text>{{item['HName'] || ''}}
                        </view>
                        <view class="detail">
                            <text>规格型号:</text>{{item['HModel'] || ''}}
                        </view>
                        <view class="detail">
                            <text>计量单位:</text>{{barCodeInfo['计量单位'] || ''}}
                        </view>
                    </uni-card>
                </view>
            </view>
        </view>
        <view class="over" v-if="barCodeSplitInfo.length == 0">暂无数据</view>
        <view class="over" v-if="barCodeSplitInfo.length != 0">已到底</view>
        <view>
            <!-- 输入框示例 -->
            <uni-popup ref="inputDialog" type="dialog">
                <uni-popup-dialog ref="inputClose" mode="input" title="请输入拆码数量" :value="dialogVal" placeholder="请输入拆码数量"
                    @confirm="dialogInputConfirm"></uni-popup-dialog>
            </uni-popup>
        </view>
    </view>
</template>
 
<script>
    import {
        getUserInfo
    } from "@/utils/auth.js";
    import {
        CommonUtils
    } from "@/utils/common.js"
    export default {
        data() {
            return {
                CommonUtils,
                userInfo: getUserInfo(),
                serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
                barCodeInfoMeta: {
                    barCodeNo: "",
                    splitNum: "",
                    billMaker: getUserInfo().HEmpName,
                    billMakerID: getUserInfo().HEmpID
                },
                barCodeInfo: {
 
                },
                barCodeSplitInfo: [],
                dialogVal: 0,
                itemCache: {},
                cantGenerate: true
            };
        },
        methods: {
            doRequest(url, data, resFunction, errFunction, method) {
                uni.showLoading({
                    title: '加载中...'
                })
                uni.request({
                    method: method || "GET",
                    url: this.serverUrl + url,
                    data: data || "",
                    success: (res) => {
                        if (typeof resFunction === 'function') {
                            resFunction.call(this, res)
                        } else if (typeof errFunction === 'undefined') {
                            return
                        } else {
                            throw new TypeError("访问成功回调函数类型异常!")
                        }
                    },
                    fail: (err) => {
                        uni.showToast({
                            icon: "error",
                            title: "接口访问异常!",
                            duration: 2000
                        })
                        if (typeof errFunction === 'function') {
                            errFunction.call(this, err)
                        } else if (typeof errFunction === 'undefined') {
                            return
                        } else {
                            throw new TypeError("访问失败回调函数类型异常!")
                        }
                    }
                })
                uni.hideLoading()
            },
            async searchbarCodeInfoMeta() {
                this.cantGenerate = true
                if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) === true) {
                    return uni.showToast({
                        icon: 'none',
                        title: '条码编号不得为空!'
                    });
                }
                if (CommonUtils.isEmpty(this.barCodeInfoMeta.splitNum, true) === true) {
                    return uni.showToast({
                        icon: 'none',
                        title: '拆分数量不得为空!'
                    });
                }
                if (this.barCodeInfoMeta.splitNum > 10 || this.barCodeInfo.splitNum < 2) {
                    return uni.showToast({
                        icon: 'none',
                        title: '拆分数量必须在2~10之间!'
                    });
                }
                this.doRequest(
                    "/Gy_SplitBarCode/Info", {
                        HBarCodeNo: this.barCodeInfoMeta.barCodeNo,
                        HSplitBarNum: this.barCodeInfoMeta.splitNum
                    },
                    function(res) {
                        console.log(res)
                        this.barCodeSplitInfo = []
                        let res1 = res.data
                        let {
                            data,
                            count,
                            Message
                        } = res1
                        if (count > 0) {
 
                            if (data.length < 1) {
                                return uni.showToast({
                                    icon: 'none',
                                    title: Message
                                });
                            }
                            // this.barCodeInfo = data[0]
                            if (data[0]["HQty"] < this.barCodeInfoMeta.splitNum) {
                                return uni.showToast({
                                    icon: 'none',
                                    title: '拆分数量大于条码数量!'
                                });
                            }
                            let remainder = data[0]["HQty"] % this.barCodeInfoMeta.splitNum
                            let i
                            for (i = 0; i < this.barCodeInfoMeta.splitNum; i++) {
                                let barCodeItem = JSON.parse(JSON.stringify(data[0]));
                                this.barCodeSplitInfo.push(Object.assign(barCodeItem, {
                                    HSplitNum: Math.floor(data[0]["HQty"] / this.barCodeInfoMeta
                                        .splitNum),
                                    HBarCode: data[0]["HBarCode"] + String.fromCharCode(('A'
                                        .charCodeAt(0) + i))
                                }))
                            }
                            this.barCodeSplitInfo[i - 1]["HSplitNum"] += remainder
                            this.cantGenerate = false
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: '没有找到对应的单据'
                            });
                        }
                    },
                    function(err) {
                        console.error(err)
                    }
                )
            },
            async searchbarCodeInfo() {
                await this.$nextTick()
                let urlEncode =
                    `/Gy_BarCodeBillList/page?sWhere= and 条码编号=\'\'${this.barCodeInfoMeta.barCodeNo}\'\'&user=${this.userInfo.HEmpName}&page=1&size=1`
                    .toString()
                if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) == true) {
                    return uni.showToast({
                        icon: "fail",
                        title: "条码编号不能为空!"
                    })
                }
                this.doRequest(
                    urlEncode,
                    null,
                    function(res) {
                        console.log(res)
                        let res1 = res.data
                        let {
                            data,
                            count
                        } = res1
                        if (count > 0) {
                            this.barCodeInfo = data[0]
                        }
                    },
                    function(err) {
                        console.err(err)
                    }
                )
            },
            ModityHQty(item) {
                this.dialogVal = item["HSplitNum"]
                this.itemCache = item
                this.inputDialogToggle()
 
            },
            inputDialogToggle() {
                this.$refs.inputDialog.open()
            },
            dialogInputConfirm(val) {
                this.itemCache["HSplitNum"] = val
 
                // 关闭窗口后,恢复默认内容
                this.$refs.inputDialog.close()
 
            },
            SaveBarCodeCreate() {
                // 校验拆码数量
                let sum = this.barCodeSplitInfo.reduce((acc, obj) => {
                    return acc + obj["HSplitNum"]
                }, 0)
 
                if (sum > this.barCodeInfo["HQty"]) {
                    return uni.showToast({
                        icon: 'none',
                        title: '拆码数量和不得大于条码数量'
                    });
                }
                let msg =
                    `${this.barCodeInfoMeta["baoCodeNo"]};${this.barCodeInfoMeta["splitNum"]};${JSON.stringify(this.barCodeSplitInfo)};${this.userInfo["HEmpName"]}`
                this.doRequest(
                    "/Sc_BarCode/Save_SplitBarCode", {
                        msg: msg
                    },
                    function(res) {
                        this.cantGenerate = true
                        uni.showToast({
                            title: '生成成功!'
                        });
                    },
                    function(err) {
                        console.err(err)
                    },
                    "POST"
                )
 
            },
            toScanCode() {
                var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
                mpaasScanModule.mpaasScan({
                    'hideAlbum': true,
                    'timeoutInterval':'10', //超时时间
                    'timeoutText':'未识别到二维码' //超时提醒            
                },(ret) => {
                    console.log(ret.resp_result)
                    if (this.CommonUtils.isEmpty(ret.resp_result) === false) {
                        console.log('条码内容:' + ret.resp_result);
                        this.barCodeInfoMeta.barCodeNo = ret.resp_result
                    
                        this.searchbarCodeInfo()
                        // this.doRequest(
                        //     "/Gy_SplitBarCode/Info", {
                        //         HBarCodeNo: ret.resp_result,
                        //         HSplitBarNum: 1
                        //     },
                        //     function(res) {
                        //         console.log(res)
                        //         this.barCodeSplitInfo = []
                        //         let res1 = res.data
                        //         let {
                        //             data,
                        //             count
                        //         } = res1
                        //         if (count > 0) {
                        //             console.log(data[0])
                        //             this.barCodeInfo = data[0]
                        //         }
                        //     },
                        //     function(err) {
                        //         console.error(err)
                        //     }
                        // )
                    }
                })
            }
        },
        onLoad() {
        }
    }
</script>
 
<style lang="scss">
    * {
        box-sizing: border-box;
    }
 
    input {
        padding: 8rpx 20rpx;
        font-size: 30rpx;
        line-height: 30rpx;
    }
    
    button {
        padding: 0;
        width: 150rpx;
        font-size: 25rpx;
    }
 
    .uni-card {
        margin: 0 !important;
    }
 
    .container {
        .header {
            padding: 20rpx 10rpx;
            display: flex;
            flex-direction: column;
            gap: 20rpx;
 
            .item {
                display: flex;
                flex-direction: row;
                padding: 0 10rpx;
                gap: 20rpx;
                font-size: 30rpx;
                // height: 1.5rem;
                // justify-content: center;
                align-items: center;
 
                .left {
                    text-align: right;
                    width: 5rem;
                }
 
                .right {
                    flex: 1;
                    height: 100%;
                    padding: 6rpx 0;
                    border-radius: 22rpx;
                    border: 1px solid #e4e4e4;
                    background-color: #e4e4e4;
 
                    >input {
                        height: auto;
                    }
                }
            }
 
            .operation-zone {
                display: flex;
                flex-direction: row;
                justify-content: space-evenly;
 
                .btn-c {
                    background-color: #3a78ff;
                    color: #fff;
                }
            }
        }
 
        .divide {
            width: 100%;
            height: 16rpx;
            background-color: #e5e5e5;
        }
 
        .content {
            flex: 1;
 
            .barcode-detail,
            .barcode-split {
                padding: 30rpx;
                display: flex;
                flex-direction: column;
                gap: 30rpx;
            }
        }
    }
</style>