jiangping
2023-08-11 5c98be0b50b8ca78ed05358cbd434193e75dcd8a
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
<template>
    <div class="lk">
        <!--   详情   -->
        <div class="lk_box">
            <div class="lk_box_title">{{info.mmodelName ? info.mmodelName : '-'}} | {{info.mmodelCode ? info.mmodelCode : '-'}} | {{info.batch ? info.batch : '-'}}</div>
            <div class="lk_box_info">
                <div class="lk_box_info_item"><span>所在仓库:</span><span>{{info.whmodelName}}</span></div>
                <div class="lk_box_info_item"><span>所在货位:</span><span>{{info.lmodelUnionName}}</span></div>
                <div class="lk_box_info_item">
                    <span>质量属性:</span>
                    <span class="green" v-if="info.qualityType === 0">合格</span>
                    <span class="yellow" v-else-if="info.qualityType === 1">不良</span>
                    <span class="red" v-else-if="info.qualityType === 2">报废</span>
                    <span v-else></span>
                </div>
                <div class="lk_box_info_item"><span>产生工序:</span><span>{{info.pmodelName ? info.pmodelName : '-'}}</span></div>
                <div class="lk_box_info_item"><span>返修工序:</span><span>{{info.fxpmodelName ? info.fxpmodelName : '-'}}</span></div>
                <div class="lk_box_info_item"><span>客返单号:</span><span>{{info.saleorderId ? info.saleorderId : '-'}}</span></div>
                <div class="lk_box_info_item"><span>客返客户:</span><span>{{info.cmodelName ? info.cmodelName : '-'}}</span></div>
            </div>
        </div>
        <!--   扫工装   -->
        <div class="lk_scode">
            <div class="lk_scode_jiu" @click="openScanCode('old')">
                <img src="@/assets/icon/jianyan_ic_saoma@2x.png" alt="" />
                <span>扫码旧工装</span>
            </div>
            <div class="z"></div>
            <div class="lk_scode_xin" @click="openScanCode('new')">
                <img src="@/assets/icon/gon1gdan_ic_saoma@2x.png" alt="" />
                <span>扫码新工装</span>
            </div>
        </div>
        <div class="lk_content">
            <!--   旧工装   -->
            <div class="lk_content_jiu">
                <div class="lk_content_jiu_title">
                    <div class="lk_content_jiu_title_left">
                        <div class="x"></div>
                        <span>旧工装码</span>
                    </div>
                    <div class="lk_content_jiu_title_right" @click="openGZ(1)">
                        <img src="@/assets/icon/gongdan_ic_shoudong@2x.png" alt="">
                        <span>新增</span>
                    </div>
                </div>
                <div class="lk_content_jiu_box">
                    <template v-if="data.oldList.length > 0">
                        <van-swipe-cell v-for="(item, i) in data.oldList" :key="item.code">
                            <div class="item">
                                <div class="item_wz">
                                    <span class="green" v-if="item.smodelLabel === Attribute.HG">[合格]</span>
                                    <span class="yellow" v-else-if="item.smodelLabel === Attribute.BL">[不良]</span>
                                    <span class="red" v-else-if="item.smodelLabel === Attribute.BF">[报废]</span>
                                    <span class="green" v-else-if="item.smodelLabel === Attribute.HH">[混合]</span>
                                    <span>&nbsp;{{item.code}}</span>
                                </div>
                                <div class="item_num">{{item.num}}{{item.umodelName}}</div>
                            </div>
                            <template #right>
                                <van-button style="height: 100%" square type="danger" text="删除" @click="dele(1, i)" />
                            </template>
                        </van-swipe-cell>
                    </template>
                    <template v-else>
                        <div class="items">暂无数据</div>
                    </template>
                </div>
            </div>
            <!--   新工装   -->
            <div class="lk_content_jiu">
                <div class="lk_content_jiu_title">
                    <div class="lk_content_jiu_title_left">
                        <div class="x"></div>
                        <span>新工装码</span>
                    </div>
                    <div class="lk_content_jiu_title_right" @click="openGZ(2)">
                        <img src="@/assets/icon/gongdan_ic_shoudong@2x.png" alt="">
                        <span>新增</span>
                    </div>
                </div>
                <div class="lk_content_jiu_box">
                    <template v-if="data.newList.length > 0">
                        <van-swipe-cell v-for="(item, i) in data.newList" :key="item.code">
                            <div class="item">
                                <div class="item_wz">
                                    <span class="green" v-if="item.smodelLabel === Attribute.HG">[合格]</span>
                                    <span class="yellow" v-else-if="item.smodelLabel === Attribute.BL">[不良]</span>
                                    <span class="red" v-else-if="item.smodelLabel === Attribute.BF">[报废]</span>
                                    <span class="green" v-else-if="item.smodelLabel === Attribute.HH">[混合]</span>
                                    <span>&nbsp;{{item.code}}</span>
                                </div>
                                <div class="item_num">
                                    <input type="number" v-model="item.num" @blur="changeNum(item.num, i, item.umodelData)" placeholder="0" />
                                    <span>{{data.oldList[0].umodelName}}</span>
                                </div>
                            </div>
                            <template #right>
                                <van-button style="height: 100%" square type="danger" text="删除" @click="dele(2, i)" />
                            </template>
                        </van-swipe-cell>
                    </template>
                    <template v-else>
                        <div class="items">暂无数据</div>
                    </template>
                </div>
            </div>
        </div>
        <div class="lk_zw"></div>
        <div class="lk_footer">
            <button class="lk_footer_submit" @click="submit" v-preventReClick>提交</button>
        </div>
        <!--  扫码  -->
        <v-ScanCode
            :openCode="openCode"
            :infos="['请扫描工装码']"
            @closePopup="closePopup"
            @onDecode="onDecode">
        </v-ScanCode>
        <!--  工装器具  -->
        <Tooling :show="gzShow" :classification="true" :statusname="'1'" @close="close" @value="getValue" />
    </div>
</template>
 
<script setup lang="ts">
    import { ref, reactive, onMounted } from 'vue'
    import { useRoute, useRouter } from "vue-router"
    import { QRCodeType, Attribute } from '@/enum'
    import { Toast } from 'vant'
    import { REGULAR } from '@/utils/utils'
    import { getBarcodeContent, getListByCondition, chageApplicance } from "@/apis/WorkOrderAPI"
    import Tooling from '@/components/common/Tooling.vue'
 
    const route = useRoute()
 
    const router = useRouter()
 
    let data = reactive<{ oldList: any, newList: any, type: string | number }>({    // 新旧工装数据
        oldList: [],
        newList: [],
        type: ''
    })
 
    let gzShow = ref<boolean>(false)
    let info = ref<any>({})    // 详情数据
    let openCode = ref<boolean>(false)
    let type = ref<string>('')
 
    // 修改新工装数量
    const changeNum = (num: any, i: number, umodelData: number): void => {
        if (umodelData === 0) {
            if (!REGULAR.positiveInteger.test(num)) {
                Toast.fail({ message: '数量只能输入正整数' })
                data.newList.forEach((element: any, index: number) => {
                    if (i === index) {
                        element.num = ''
                    }
                })
            }
        } else if (umodelData === 1) {
            if (!REGULAR.number.test(num)) {
                Toast.fail({ message: '数量只能输入整数或小数(四位)' })
                data.newList.forEach((element: any, index: number) => {
                    if (i === index) {
                        element.num = ''
                    }
                })
            }
            // if (!REGULAR.positiveInteger.test(num) && !REGULAR.decimal.test(num)) {
            //     Toast.fail({ message: '数量只能输入整数或小数' })
            //     data.newList.forEach((element: any, index: number) => {
            //         if (i === index) {
            //             element.num = ''
            //         }
            //     })
            // }
        }
    }
 
    const openGZ = (Type: number): void => {
        data.type = Type
        gzShow.value = true
    }
 
    // 删除新旧工装
    const dele = (type: number, i: number): void => {
        if (type === 1) {
            if (data.oldList.length === 1) {
                Toast.fail({ message: '至少保留一项旧工装', duration: 2000 })
                return
            }
            data.oldList.splice(i, 1)
        } else if (type === 2) {
            if (data.newList.length === 1) {
                Toast.fail({ message: '至少保留一项新工装', duration: 2000 })
                return
            }
            data.newList.splice(i, 1)
        }
    }
 
    // 获取工装数据
    const getValue = (item: any): void => {
        const arr: Array<any> = [...data.oldList, ...data.newList]
        if (data.type == 1) {
            let next: boolean = true
            arr.forEach((element: any) => {
                if (item.id === element.id) {
                    next = false
                    Toast.fail({ message: '不能重复添加相同的工装' })
                    return
                }
            })
            if (next) {
                data.oldList.push(item)
            }
        } else if (data.type == 2) {
            let next: boolean = true
            arr.forEach((element: any) => {
                if (item.id === element.id) {
                    next = false
                    Toast.fail({ message: '不能重复添加相同的工装' })
                    return
                }
            })
            if (next) {
                data.newList.push(item)
            }
        }
        gzShow.value = false
    }
 
    const close = (): void => {
        gzShow.value = false
    }
 
    const closePopup = (): void => {
        openCode.value = false
    }
 
    // 获取扫码回调
    const onDecode = async (datas: string[]): Promise<void> => {
        openCode.value = false
        const arr: Array<any> = [...data.oldList, ...data.newList]
        let res = await getBarcodeContent({    // 扫码请求返回类型和id
            barcode: datas[0]
        })
        if (res.code === 200) {
            if (res.data.barcodeType === QRCodeType.GZ) {
                let infos = await getListByCondition({ id: res.data.id })
                if (infos.code === 200) {
 
                    if (type.value === 'new') {
                        if (info.value.smodelLabel === infos.data[0].smodelLabel) {
                            // if (infos.data[0].status === 1) {
                                data.newList.push(infos.data[0])
                            // } else {
                            //     Toast.fail({ message: '工装状态必须为空', duration: 2000 })
                            // }
                        } else {
                            Toast.fail({ message: '工装属性不一致', duration: 2000 })
                        }
                        return
                    }
 
                    let next: boolean = true
                    arr.forEach((element: any) => {
                        if (element.id === infos.data[0].id) {
                            next = false
                            Toast.fail({ message: '不能重复添加相同的工装' })
                        }
                    })
                    if (next) {
                        if (type.value === 'old') {
                            if (info.value.warehouseId === infos.data[0].warehouseId) {
                                if (info.value.locationId === infos.data[0].locationId) {
                                    if (info.value.qualityType === infos.data[0].qualityType) {
                                        if (info.value.procedureId === infos.data[0].procedureId) {
                                            if (info.value.fxpmodelName === infos.data[0].fxpmodelName) {
                                                if (info.value.saleorderId === infos.data[0].saleorderId) {
                                                    if (info.value.cmodelName === infos.data[0].cmodelName) {
                                                        data.oldList.push(infos.data[0])
                                                    } else {
                                                        Toast.fail({ message: '客返客户不一致', duration: 2000 })
                                                    }
                                                } else {
                                                    Toast.fail({ message: '客返单号不一致', duration: 2000 })
                                                }
                                            } else {
                                                Toast.fail({ message: '返修工序不一致', duration: 2000 })
                                            }
                                        } else {
                                            Toast.fail({ message: '产生工序不一致', duration: 2000 })
                                        }
                                    } else {
                                        Toast.fail({ message: '质量属性不一致', duration: 2000 })
                                    }
                                } else {
                                    Toast.fail({ message: '货位不一致', duration: 2000 })
                                }
                            } else {
                                Toast.fail({ message: '仓库不一致', duration: 2000 })
                            }
                        }
                        // else if (type.value === 'new') {
                        //     if (info.value.smodelLabel === infos.data[0].smodelLabel) {
                        //         if (infos.data[0].status === 1) {
                        //             data.newList.push(infos.data[0])
                        //         } else {
                        //             Toast.fail({ message: '工装状态必须为空', duration: 2000 })
                        //         }
                        //     } else {
                        //         Toast.fail({ message: '工装属性不一致', duration: 2000 })
                        //     }
                        // }
                    }
                } else {
                    Toast.fail({ message: '请扫描正确的工装码' })
                }
            }
        }
    }
 
    // 打开扫一扫
    const openScanCode = (Type: string): void => {
        type.value = Type
        openCode.value = true
    }
 
    // 获取工装详情
    const getInfo = async () => {
        let res = await getListByCondition({ id: route.query.id })
        if (res.code === 200) {
            info.value = res.data[0]
            data.oldList.push(res.data[0])
        }
    }
 
    // 提交换篮筐
    const submit = async (): Promise<void> => {
        if (data.oldList.length === 0) {
            Toast.fail({ message: '旧工装不能为空' })
            return
        }
        if (data.newList.length === 0) {
            Toast.fail({ message: '新工装不能为空' })
            return
        }
        let news: number = 0
        let old: number = 0
        data.oldList.forEach((element: any) => {
            old = old + element.num
        })
        data.newList.forEach((element: any) => {
            news = news + element.num
        })
        if (news !== old) {
            Toast.fail({ message: '新旧工装数量必须一致' })
            return
        }
        let res = await chageApplicance({
            oldList: data.oldList,
            newList: data.newList
        })
        if (res.code === 200) {
            Toast.success({ message: '操作成功', forbidClick: true, duration: 3000 })
            setTimeout(() => {
                router.go(-1)
            }, 2000)
        }
    }
 
    onMounted(() => {
        getInfo()
    })
</script>
 
<style lang="scss" scoped>
    .lk {
        width: 100%;
        height: 100%;
        position: absolute;
        background: #F7F7F7;
        .lk_box {
            padding: 30px;
            background: white;
            .lk_box_title {
                font-size: 32px;
                font-weight: 500;
                color: #333333;
            }
            .lk_box_info {
                margin-top: 30px;
                background: #F7F7F7;
                padding: 24px 30px;
                .lk_box_info_item {
                    display: flex;
                    align-items: center;
                    margin-bottom: 24px;
                    &:last-child {
                        margin-bottom: 0 !important;
                    }
                    span {
                        font-size: 26px;
                        font-weight: 400;
                        &:first-child {
                            color: #666666;
                        }
                        &:last-child {
                            color: #222222;
                        }
                    }
                }
            }
        }
        .lk_scode {
            margin-top: 30px;
            padding: 0 30px;
            display: flex;
            align-items: center;
            .lk_scode_jiu {
                flex: 1;
                height: 76px;
                background: #FFFFFF;
                border-radius: 36px;
                border: 1PX solid #E5E5E5;
                display: flex;
                align-items: center;
                justify-content: center;
                img {
                    width: 28px;
                    height: 28px;
                    margin-right: 12px;
                }
                span {
                    font-size: 26px;
                    font-weight: 400;
                    color: #222222;
                }
            }
            .z {
                width: 30px;
            }
            .lk_scode_xin {
                flex: 1;
                height: 76px;
                background: $nav-color;
                border-radius: 36px;
                display: flex;
                align-items: center;
                justify-content: center;
                img {
                    width: 28px;
                    height: 28px;
                    margin-right: 12px;
                }
                span {
                    font-size: 26px;
                    font-weight: 400;
                    color: #ffffff;
                }
            }
        }
        .lk_content {
            .lk_content_jiu {
                margin-top: 40px;
                .lk_content_jiu_title {
                    padding: 0 30px;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    .lk_content_jiu_title_left {
                        display: flex;
                        align-items: center;
                        .x {
                            width: 8px;
                            height: 30px;
                            background: #4275FC;
                            border-radius: 2px;
                            margin-right: 12px;
                        }
                        span {
                            font-size: 32px;
                            font-weight: 500;
                            color: #222222;
                        }
                    }
                    .lk_content_jiu_title_right {
                        display: flex;
                        align-items: center;
                        img {
                            width: 28px;
                            height: 28px;
                            margin-right: 12px;
                        }
                        span {
                            font-size: 28px;
                            font-weight: 400;
                            color: #4275FC;
                        }
                    }
                }
                .lk_content_jiu_box {
                    margin-top: 28px;
                    background: white;
                    display: flex;
                    flex-direction: column;
                    .items {
                        width: 100%;
                        height: 98px;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        font-size: 28px;
                        font-weight: 400;
                        color: #000000;
                    }
                    .item {
                        margin: 0 30px;
                        height: 98px;
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        border-bottom: 1PX solid #E5E5E5;
                        &:last-child {
                            border-bottom: 0PX !important;
                        }
                        .item_wz {
                            span {
                                font-size: 30px;
                                font-weight: 400;
                                color: #222222;
                            }
                        }
                        .item_num {
                            font-size: 28px;
                            font-weight: 400;
                            color: #333333;
                            input {
                                font-size: 28px;
                                font-weight: 400;
                                color: #333333;
                                width: 180px;
                                height: 60px;
                                background: #FFFFFF;
                                border-radius: 8px;
                                border: 1PX solid #CCCCCC;
                                padding: 0 30px;
                                box-sizing: border-box;
                                margin-right: 20px;
                            }
                            input::-webkit-input-placeholder {
                                font-size: 28px;
                                font-weight: 400;
                                color: #999999;
                            }
                            span {
                                font-size: 28px;
                                font-weight: 400;
                                color: #666666;
                            }
                        }
                    }
                }
            }
        }
        .lk_zw {
            height: 168px;
        }
        .lk_footer {
            position: fixed;
            bottom: 0;
            left: 30px;
            padding-bottom: 60px;
            width: calc(100% - 60px);
            .lk_footer_submit {
                border: none;
                width: 100%;
                height: 88px;
                background: $nav-color;
                box-shadow: 0 0 12px 0 rgba(0,0,0,0.0800);
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 30px;
                font-weight: 500;
                color: #FFFFFF;
            }
        }
    }
</style>