wangxinhui
7 小时以前 526b70eecc5dac5aea91bfffbe0b98118f25827f
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
<template>
    <view>
        <view class="itemstyle">
            <uni-forms label-width="180">
                <uni-forms-item label="外箱码:">
                    <uni-easyinput type="text" placeholder="请扫描外箱码" ref='midInput'  v-model="barcode" :focus="!focus"
                         class="search_box" :disabled="isDisable" @confirm="handleKeyPress"/>
                </uni-forms-item>
            </uni-forms>
        </view>
        <view style="padding: 0 0rpx 0rpx;">
            <!-- 当前出库外包号 -->
            <view class="item_boxItem">
                <uni-list>
                    <uni-list-item direction="column" v-for="(item,index) in listShow" :key="index">
                        <template v-slot:body>
                            <view class="uni-list-box">
                                <uni-icons type="trash" size="22" style="position: absolute;right: 5%;"
                                    @click="deleteList(index)">
                                </uni-icons>
                                <view class="uni-content">
                                    <view class="uni-title-sub uni-ellipsis-2">外包:{{item.code}} &nbsp;&nbsp; 数量:{{item.qty}}</view>
                                </view>
                            </view>
                        </template>
                    </uni-list-item>
                </uni-list>
            </view>
        </view>
        <view style="padding: 0 14rpx 200rpx;">
            <!-- 明细 -->
            <view v-for="i in list" :key="i.id" class="item_box">
                <view style="line-height: 17px;color: #596671;font-size: 14px;text-align: left;font-weight: bold;">订单明细行号:{{i.rowId}}
                </view>
                <view style="margin-top: 22rpx;height: 140rpx;display: flex;flex-direction: column;justify-content: space-around;">
                    <view style="color: #00070F;font-size: 12px;">客户代号:{{i.customer}}</view>
                    <view style="color: #00070F;font-size: 12px;">产品编号:{{i.pCode}}</view>
                    <view style="color: #00070F;font-size: 12px;">销售订单:{{i.saleOrder}}</view>
                    <view style="color: #f56c6c;font-size: 12px;">订单数量:{{i.qtyPcs}}</view>
                    <view style="color: #67c23a;font-size: 12px;">已出数量:{{i.overQtyPcs}}</view>
                </view>
                <view style="width: 100%;height: 1rpx;background-color: #00070F;margin-top: 28rpx;">
                </view>
            </view>
        </view>
        <view style="padding:20rpx;position: fixed;bottom: 0;left: 0;background-color:lightgray;width: 100%;z-index: 999;display: flex;justify-content: space-between;">
            <view style="margin-bottom: 22rpx;padding-left: 16rpx;line-height: 80rpx;">
                <view style="font-size: 24rpx;font-weight: bold;color: #f56c6c;">订单总数量:<text>{{orderQty}}</text></view>
                <view style="font-size: 24rpx;font-weight: bold;color: #67c23a;">已扫总数量:<text>{{total}}</text></view>
            </view>
            <view style="display: flex;height: 110rpx;margin-top: 40rpx;">
                <button @click="reset" type="default" size="default" style="margin-top: 2%;width: 160rpx;border: 1rpx solid #007aff;color: #007aff;margin-right: 30rpx;">重置</button>
                <button @click="InEmpty" type="primary" size="default" style="margin-top: 2%;width: 160rpx;">出货</button>
            </view>
        </view>
        <u-toast ref="uToast" />
    </view>
</template>
 
<script>
    const innerAudioContext = uni.createInnerAudioContext();
    export default {
        data() {
            return {
                focus: false,
                barcode: "",
                proOutNo: "",
                id: null,
                list:[],
                listOutBags:[],
                listShow:[],
                total:0,
                orderQty:0,
                isDisable:false
            }
        },
        onShow() {},
        onLoad(res) {
            this.proOutNo=res.proOutNo;
            this.GetDetail(res.id);
            this.id=res.id;
            uni.hideKeyboard(); //隐藏软键盘
        },
        methods: {
            handleKeyPress(e) {
                console.log(e);
                  // 回车符(ASCII 13)表示扫码结束
                  this.isDisable=true;
                  this.focus=true;
                  this.$nextTick(function(x) {
                      var values= this.barcode.split(',');
                      if(values.length==5){
                          // if (values.length != 5) {
                          //     this.$refs.uToast.show({
                          //         title: "扫描格式错误"+value,
                          //         type: 'error'
                          //     })
                          //     this.barcode="";
                          //     this.$refs.midInput.focus();
                          //     return;
                          // }
                          this.$u.post('/api/ProOutOrder/CheckCode?code='+this.barcode,{}).then(
                              res => {
                                  if (res.status) {
                                      //判断是否重复
                                      if (this.listShow.some(item => item.code === values[0])) {
                                          this.barcode="";
                                          setTimeout(() => {
                                              this.isDisable=false;
                                              this.focus=false;
                                          },200);
                                          this.$refs.uToast.show({
                                              title: "重复扫描"+values[0]+"已存在",
                                              type: 'error'
                                          })
                                          return;
                                      }
                                      if (this.list.some(item => item.pCode === values[1])) {
                                          var outCode=values[0];
                                          var outQty=parseInt(values[4]);
                                          //判断outQty为数字
                                          if (isNaN(outQty)) {
                                                  this.barcode="";
                                                  setTimeout(() => {
                                                      this.isDisable=false;
                                                      this.focus=false;
                                                  },200);
                                                  this.$refs.uToast.show({
                                                      title: "扫描格式错误"+values[4],
                                                      type: 'error'
                                                  })
                                                  return;
                                              }
                                          //判断outQty是否大于0
                                          if (outQty<=0) {
                                              this.barcode="";
                                              setTimeout(() => {
                                                  this.isDisable=false;
                                                  this.focus=false;
                                              },200);
                                              this.$refs.uToast.show({
                                                  title: "标签数必须大于0",
                                                  type: 'error'
                                              })
                                              return;
                                          }
                                          this.total+=outQty;
                                          if(this.orderQty<this.total){
                                              this.barcode="";
                                              setTimeout(() => {
                                                  this.isDisable=false;
                                                  this.focus=false;
                                              },200);
                                              this.$refs.uToast.show({
                                                  title: "订单数超出",
                                                  type: 'error'
                                              })
                                              return;
                                          }
                                          this.listShow.unshift({code:outCode,qty:outQty});
                                          console.log(this.listShow);
                                          //去除this.barcode的空格
                                          this.listOutBags.push(this.barcode.replace(/\s*/g, ""));
                                          this.barcode="";
                                          setTimeout(() => {
                                              this.isDisable=false;
                                              this.focus=false;
                                          },200);
                                          
                                      }else{
                                          this.barcode="";
                                          setTimeout(() => {
                                              this.isDisable=false;
                                              this.focus=false;
                                          },200);
                                          this.$refs.uToast.show({
                                              title: "扫描"+values[1]+"批号不在订单中",
                                              type: 'error'
                                          })
                                          return;
                                      }
                                  }
                              })
                      }
                  })
                },
            GetDetail(value) {
                this.$u.post('/api/ProOutOrder/GetOrderDetails?keyId='+value).then(
                    res => {
                        if (res.status) {
                            this.list=res.data.proOutOrderDetails;
                            this.orderQty=this.list.map(x=>{
                                return x.qtyPcs
                            }).reduce((a,b)=>{
                                return a+b
                            });
                        } else {
                            this.$refs.uToast.show({
                                title: res.message,
                                type: "error"
                            })
                        }
                    })
            },
            // voiceSpeech(src) {
            //     innerAudioContext.src = src; // '../../static/success.mp3';
            //     innerAudioContext.play();
            // },
            // barcodeInput(value) {
            //     this.isDisable=true;
            //     this.focus=true;
            //     setTimeout(x=>{
            //         this.$nextTick(function(x) {
            //             var values= this.barcode.split(',');
            //             if(values.length==5){
            //                 // if (values.length != 5) {
            //                 //     this.$refs.uToast.show({
            //                 //         title: "扫描格式错误"+value,
            //                 //         type: 'error'
            //                 //     })
            //                 //     this.barcode="";
            //                 //     this.$refs.midInput.focus();
            //                 //     return;
            //                 // }
            //                 this.$u.post('/api/ProOutOrder/CheckCode?code='+this.barcode,{}).then(
            //                     res => {
            //                         if (res.status) {
            //                             //判断是否重复
            //                             if (this.listShow.some(item => item.code === values[0])) {
            //                                 this.barcode="";
            //                                 setTimeout(() => {
            //                                     this.isDisable=false;
            //                                     this.focus=false;
            //                                 },200);
            //                                 this.$refs.uToast.show({
            //                                     title: "重复扫描"+values[0]+"已存在",
            //                                     type: 'error'
            //                                 })
            //                                 return;
            //                             }
            //                             if (this.list.some(item => item.pCode === values[1])) {
            //                                 var outCode=values[0];
            //                                 var outQty=parseInt(values[4]);
            //                                 //判断outQty为数字
            //                                 if (isNaN(outQty)) {
            //                                         this.barcode="";
            //                                         setTimeout(() => {
            //                                             this.isDisable=false;
            //                                             this.focus=false;
            //                                         },200);
            //                                         this.$refs.uToast.show({
            //                                             title: "扫描格式错误"+values[4],
            //                                             type: 'error'
            //                                         })
            //                                         return;
            //                                     }
            //                                 //判断outQty是否大于0
            //                                 if (outQty<=0) {
            //                                     this.barcode="";
            //                                     setTimeout(() => {
            //                                         this.isDisable=false;
            //                                         this.focus=false;
            //                                     },200);
            //                                     this.$refs.uToast.show({
            //                                         title: "标签数必须大于0",
            //                                         type: 'error'
            //                                     })
            //                                     return;
            //                                 }
            //                                 this.total+=outQty;
            //                                 if(this.orderQty<this.total){
            //                                     this.barcode="";
            //                                     setTimeout(() => {
            //                                         this.isDisable=false;
            //                                         this.focus=false;
            //                                     },200);
            //                                     this.$refs.uToast.show({
            //                                         title: "订单数超出",
            //                                         type: 'error'
            //                                     })
            //                                     return;
            //                                 }
            //                                 this.listShow.unshift({code:outCode,qty:outQty});
            //                                 console.log(this.listShow);
            //                                 //去除this.barcode的空格
            //                                 this.listOutBags.push(this.barcode.replace(/\s*/g, ""));
            //                                 this.barcode="";
            //                                 setTimeout(() => {
            //                                     this.isDisable=false;
            //                                     this.focus=false;
            //                                 },200);
                                            
            //                             }else{
            //                                 this.barcode="";
            //                                 setTimeout(() => {
            //                                     this.isDisable=false;
            //                                     this.focus=false;
            //                                 },200);
            //                                 this.$refs.uToast.show({
            //                                     title: "扫描"+values[1]+"批号不在订单中",
            //                                     type: 'error'
            //                                 })
            //                                 return;
            //                             }
            //                         }
            //                     })
            //             }
            //         })
            //     },200)
            // },
            deleteList(res) {
                let indexExist =-1;
                //查询this.listOutBags中是否有this.listShow[res].code
                this.listOutBags.forEach((item,index) => {
                    //item是否包含 this.listShow[res].code
                    if (item.includes(this.listShow[res].code)) {
                        indexExist=index;
                    }
                });
                console.log(indexExist);
                if (indexExist !=-1) { // 如果找到了索引,则执行删除操作
                    this.total-=this.listShow[res].qty;
                    this.listOutBags.splice(indexExist, 1); // 从索引位置开始删除一个元素
                    this.listShow.splice(res, 1);
                }
                setTimeout(() => {
                    this.isDisable=false;
                },200);
                this.barcode="";
            },
            reset(){
                this.listShow=[];
                this.total=0;
                this.listOutBags=[];
                this.focus=true;
                this.barcode="";
                setTimeout(() => {
                    this.barcode="";
                    this.isDisable=false;
                    this.focus=false;
                }, 200);
            },
            InEmpty() {
                // if (this.barcode == "") {
                //     this.$refs.uToast.show({
                //         title: "请扫描外箱码",
                //         type: 'error'
                //     })
                //     return;
                // }
                if(this.orderQty!==this.total){
                        this.$refs.uToast.show({
                            title: "请扫描"+this.orderQty+"数量",
                            type: 'error'
                        })
                        return;
                }
                var postData = {
                    MainData: {
                        "outProOrderNo":this.proOutNo
                    },
                    DelKeys:this.listOutBags
                }
                this.$u.post('/api/ProOutOrder/OutProScanCodeSync',postData).then(
                    res => {
                        if (res.status) {
                            this.$refs.uToast.show({
                                title: "成功",
                                type: "success"
                            })
                            this.reset();
                            this.GetDetail(this.id);
                        } else {
                            this.$refs.uToast.show({
                                title: res.message,
                                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%;
    }
    .item_box {
        background-color: white;
        // height: 344rpx;
        border-radius: 12rpx;
        padding: 40rpx 38rpx 28rpx 34rpx;
        font-size: 24rpx;
        line-height: 34rpx;
        margin-top: 20rpx;
    }
    .item_boxItem {
        background-color: white;
        padding: 40rpx 38rpx 28rpx 34rpx;
        // height: 344rpx;
        border-radius: 12rpx;
        font-size: 24rpx;
        line-height: 17rpx;
    }
    .headerstyle {
        width: 90%;
    }
    .search_box {
        padding: 10rpx 20rpx 20rpx;
        background-color: white;
    }
</style>