Mr.Shi
2023-08-11 6e19ef63c0a87588abd76c04ab228a73e3060ea4
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
<template>
    <div class="rework">
        <div class="rework_list">
            <div class="rework_list_item" v-if="form.type !== 3">
                <span>当前工厂</span>
                <div class="rework_list_item_right">
                    <span class="black">{{list.length > 0 ? list[0].dpmodelName : ''}}</span>
                </div>
            </div>
            <div class="rework_list_item" @click="show = true">
                <span>返工类型</span>
                <div class="rework_list_item_right">
                    <span :class="form.typeName ? 'black' : ''">{{form.typeName ? form.typeName : '请点击选择类型'}}</span>
                    <van-icon name="arrow" size="20" color="#999999" />
                </div>
            </div>
            <div class="rework_list_item" @click="openDate = true">
                <span>预计生产日期</span>
                <div class="rework_list_item_right">
                    <span :class="form.date ? 'black' : ''">{{form.date ? form.date : '请点击选择日期'}}</span>
                    <van-icon name="arrow" size="20" color="#999999" />
                </div>
            </div>
            <div class="rework_list_item" @click="openGX = true">
                <span>返工返修工序</span>
                <div class="rework_list_item_right">
                    <span :class="form.processName ? 'black' : ''">{{form.processName ? form.processName : '请点击选择工序'}}</span>
                    <van-icon name="arrow" size="20" color="#999999" />
                </div>
            </div>
            <div class="rework_list_item" @click="getBLInfo('')">
                <span>返工返修原因</span>
                <div class="rework_list_item_right">
                    <span :class="form.reasonName ? 'black' : ''">{{form.reasonName ? form.reasonName : '请点击选择原因'}}</span>
                    <van-icon name="arrow" size="20" color="#999999" />
                </div>
            </div>
            <div class="rework_list_item" @click="openDH = true" v-if="form.type === 3">
                <span>客返单号</span>
                <div class="rework_list_item_right">
                    <span :class="form.singleName ? 'black' : ''">{{form.singleName ? form.singleName : '请点击选择单号'}}</span>
                    <van-icon name="arrow" size="20" color="#999999" />
                </div>
            </div>
            <div class="rework_list_item" v-if="form.type === 3">
                <span>客返客户</span>
                <div class="rework_list_item_right">
                    <span class="black">{{form.clientName}}</span>
                </div>
            </div>
        </div>
        <div class="rework_qd">
            <div class="rework_qd_title">
                <div class="x"></div>
                <span>返工工装清单({{list.length}})</span>
            </div>
            <template v-if="list.length > 0">
                <van-swipe-cell v-for="(item, index) in list" :key="item.id">
                    <div class="rework_qd_item">
                        <div class="rework_qd_item_i">
                            <span class="black">{{item.code}}:</span><span class="black">{{item.num}}{{item.umodelName}}</span>
                        </div>
                        <div class="rework_qd_item_i">
                            <span>物料信息:</span><span>{{item.mmodelName}} | {{item.mmodelCode}}</span>
                        </div>
                        <div class="rework_qd_item_i">
                            <span>批次号:</span><span>{{item.batch}}</span>
                        </div>
                        <div class="rework_qd_item_i">
                            <span>生产工序:</span><span>{{item.pmodelName}}</span>
                        </div>
                    </div>
                    <template #right>
                        <van-button style="height: 100%;" square type="danger" text="删除" @click="dele(index)" />
                    </template>
                </van-swipe-cell>
            </template>
            <div class="rework_qd_item1" v-else>暂无数据</div>
        </div>
        <div class="zw"></div>
        <div class="rework_footer">
            <div class="rework_footer_add" @click="open">扫码添加工装</div>
            <div style="width: 22px;"></div>
            <button class="rework_footer_submit" @click="submit">提交</button>
        </div>
        <!--    扫码组件    -->
        <v-ScanCode
            :openCode="openCode"
            :infos="['请扫描工装码']"
            @closePopup="closePopup"
            @onDecode="onDecode">
        </v-ScanCode>
        <!--    类型    -->
        <van-popup v-model:show="show" position="bottom" round :style="{ height: '45%' }">
            <van-picker
                title="请选择类型"
                :columns="columns"
                @confirm="onConfirm"
                @cancel="onCancel"
            />
        </van-popup>
        <!--    日期    -->
        <van-calendar v-model:show="openDate" color="#4275FC" :min-date="minDate" :max-date="maxDate" @confirm="onConfirmDate" />
        <!--    工序    -->
        <van-popup v-model:show="openGX" position="bottom" round :style="{ height: '45%' }">
            <van-picker
                title="请选择工序"
                :columns="columns1"
                @confirm="onConfirm1"
                @cancel="onCancel1"
            />
        </van-popup>
        <!--    原因    -->
        <van-popup v-model:show="openYY" position="bottom" round :style="{ height: '45%' }">
            <van-picker
                title="请选择原因"
                :columns="columns2"
                @confirm="onConfirm2"
                @cancel="onCancel2"
            />
        </van-popup>
        <!--    单号    -->
        <van-popup v-model:show="openDH" position="bottom" round :style="{ height: '45%' }">
            <van-picker
                title="请选择单号"
                :columns="columns3"
                @confirm="onConfirm3"
                @cancel="onCancel3"
            />
        </van-popup>
    </div>
</template>
 
<script setup lang="ts">
    import { onMounted, reactive, ref } from 'vue'
    import { useRoute, useRouter } from "vue-router"
    import { gsdate } from "@/utils/utils"
    import { Toast } from 'vant'
    import { useStore } from "vuex"
    import { checkFGFXList, getBarcodeContent, getListByCondition, allData, createSingle, productesGroups } from '@/apis/WorkOrderAPI'
    import { QRCodeType } from "@/enum"
 
    const route = useRoute()
    const router = useRouter()
    const store = useStore()
 
    // 表单数据
    let form = reactive({
        factory: '',
        factoryId: '',
        type: '0',
        typeName: '工序返工',
        date: '',
        process: '',
        processName: '',
        reason: '详见产品手写标签',
        reasonName: '详见产品手写标签',
        clientName: '',
        single: '',
        singleName: ''
    })
 
    // 返工返修清单
    let list = ref<Array<any>>([])
 
    // 类型
    const columns = [{ text: '工序返工', id: '0' }]
 
    // 工序
    const columns1 = ref<Array<any>>([])
 
    // 原因
    const columns2 = ref<Array<any>>([])
 
    // 单号
    const columns3 = ref<Array<any>>([])
 
    let show = ref<boolean>(false)
 
    let openGX = ref<boolean>(false)
 
    let openYY = ref<boolean>(false)
 
    let openDH = ref<boolean>(false)
 
    let openDate = ref<boolean>(false)
 
    let openCode = ref<boolean>(false)
 
    // 获取明天日期
    const tomorrow = (): string => {
        let day3 = new Date()
        day3.setTime(day3.getTime() + 24 * 60 * 60 * 1000)
        return day3.getFullYear() + "/" + (day3.getMonth() + 1) + "/" + day3.getDate()
    }
 
    const minDate: any = new Date(tomorrow())
 
    const maxDate: any = new Date(new Date().getFullYear() + 1, 12, 30)
 
    // 提交申请
    const submit = async () => {
        if (!form.date) return Toast.fail({ message: '预计生产日期不能为空' })
        if (!form.process) return Toast.fail({ message: '返工返修工序不能为空' })
        if (!form.reason) return Toast.fail({ message: '返工返修原因不能为空' })
        let arrId: Array<number> = []
        list.value.forEach((element: any) => {
            arrId.push(element.id)
        })
        let res = await createSingle({
            factoryId: list.value[0].pmodelOrgId,
            type: form.type,
            planDate: form.date,
            backProcedureId: form.process,
            content: form.reasonName,
            applianceIdList: arrId
        })
        if (res.code === 200) {
            Toast.success({ message: '申请成功', forbidClick: true, duration: 2000 })
            setTimeout(() => {
                router.go(-1)
            }, 2000)
        }
    }
 
    // 删除指定工装清单
    const dele = (i: number): void => {
        if (list.value.length === 1) {
            Toast.fail({ message: '至少保留一项工装' })
            return
        }
        list.value.splice(i, 1)
    }
 
    // 确认选择日期
    const onConfirmDate = (values: any) => {
        form.date = gsdate(values)
        openDate.value = false
    };
 
    // 类型确认
    const onConfirm = (value: any) => {
        form.type = value.id
        form.typeName = value.text
        show.value = false
    };
 
    const onCancel = () => {
        show.value = false
    }
 
    // 工序确认
    const onConfirm1 = (value: any, index: number) => {
        form.processName = value.text
        form.process = value.id
        openGX.value = false
    };
 
    const onCancel1 = () => {
        openGX.value = false
    }
 
    // 不良原因
    const onConfirm2 = (value: any, index: number) => {
        form.reasonName = value.text
        form.reason = value.id
        openYY.value = false
    };
 
    const onCancel2 = () => {
        openYY.value = false
    }
 
    const onConfirm3 = (value: any, index: number) => {
        console.log(`当前值: ${value}, 当前索引: ${index}`);
    };
 
    const onCancel3 = () => {
        openDH.value = false
    }
 
    const closePopup = (): void => {
        openCode.value = false
    }
 
    // 获取扫码回调
    const onDecode = async (data: string[]): Promise<void> => {
        openCode.value = false
        let res = await getBarcodeContent({
            barcode: data[0]
        })
        if (res.code === 200) {
            if (res.data.barcodeType === QRCodeType.GZ) {
                // 查看是否已有工装
                for (let i = 0; i < list.value.length; i++) {
                    if (list.value[i].id === res.data.id) {
                        Toast.fail({ message: '不能扫描重复的工装' })
                        return
                    }
                }
                // 获取工装详情
                let lk = await getListByCondition({ id: res.data.id })
                if (lk.code === 200) {
                    if (lk.data[0].qualityType === 1) {
                        let next: boolean = false
                        for(let i = 0; i < list.value.length; i++) {    // 物料、工序、仓库一致才可以添加
                            if (list.value[0].mmodelCode === lk.data[0].mmodelCode && list.value[0].procedureId === lk.data[0].procedureId && list.value[0].warehouseId === lk.data[0].warehouseId) {
                                next = true
                            }
                        }
                        if (next) {
                            list.value.push(lk.data[0])
                        } else {
                            Toast.fail({ message: '扫描的工装物料、工序、仓库必须一致' })
                        }
                    } else {
                        Toast.fail({ message: '请扫描质量属性为不良的工装', duration: 2000 })
                    }
                }
            } else {
                Toast.fail({ message: '请扫描正确的工装码' })
            }
        }
 
    }
 
    const open = (): void => {
        openCode.value = true
    }
 
    // 获取工装信息
    const getLKInfo = async (id: string | number): Promise<void> => {
        let res = await getListByCondition({ id })
        if (res.code === 200) {
            if (res.data[0].qualityType === 1) {
                list.value.push(res.data[0])
                await getGXInfo(res.data[0].pmodelOrgId)
            } else {
                Toast.fail({ message: '请扫描质量属性为不良的工装', duration: 2000 })
            }
        }
    }
 
    // 获工序信息
    const getGXInfo = async (id: string): Promise<void> => {
        let res = await productesGroups({ orgId: id })
        if (res.code === 200) {
            res.data.forEach((item: any) => {
                columns1.value.push({ text: item.name, id: item.id })
            })
        }
    }
 
    // 返工返修不良原因
    const getBLInfo = async (id: string | number): Promise<void> => {
        let ids = ref<Array<string>>([])
        if (!id) {
            list.value.forEach((item: any) => {
                ids.value.push(item.id)
            })
        }
        let res = await checkFGFXList({ applianceids: id ? id : ids.value.join(',') })
        if (res.code === 200) {
            columns2.value = []
            res.data.forEach((item: any) => {
                columns2.value.push({ text: item.combinationName, id: item.id })
            })
            columns2.value.unshift({ text: '详见产品手写标签', id: '详见产品手写标签' })
            openYY.value = true
        }
    }
 
    // 查询所有单号
    const getDHInfo = async (): Promise<void> => {
        let res = await allData({})
        if (res.code === 200) {
            // console.log(res)
            res.data.forEach((item: any) => {
                columns3.value.push({ text: item.name, id: item.id })
            })
        }
    }
 
    onMounted(() => {
        getLKInfo(route.query.id as string)
        // getGXInfo()
        // getBLInfo(route.query.id as string)
        // getDHInfo()
    })
</script>
 
<style lang="scss" scoped>
.rework {
    width: 100%;
    height: 100%;
    position: absolute;
    .rework_list {
        display: flex;
        flex-direction: column;
        background: white;
        margin-top: 20px;
        .rework_list_item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 98px;
            padding: 0 30px;
            border-bottom: 1PX solid #E5E5E5;
            &:last-child {
                border: none;
            }
            span {
                font-size: 30px;
                font-weight: 400;
                color: #222222;
                flex-shrink: 0;
                margin-right: 15px;
            }
            .rework_list_item_right {
                flex: 1;
                display: flex;
                align-items: center;
                justify-content: flex-end;
                span {
                    text-align: right;
                    width: 400px;
                    font-size: 28px;
                    font-weight: 400;
                    color: #999999;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    -o-text-overflow: ellipsis;
                }
                .black {
                    color: black !important;
                }
            }
        }
    }
    .rework_qd {
        margin-top: 40px;
        .rework_qd_title {
            display: flex;
            align-items: center;
            padding: 0 30px 30px 30px;
            span {
                font-size: 32px;
                font-weight: 500;
                color: #222222;
            }
            .x {
                width: 8px;
                height: 30px;
                background: #4275FC;
                border-radius: 2px;
                margin-right: 12px;
            }
        }
        .rework_qd_item1 {
            height: 150px;
            background: white;
            display: flex;
            align-items: center;
            justify-content: center;
            color: black;
            font-size: 28px;
        }
        .rework_qd_item {
            background: #ffffff;
            padding: 30px;
            display: flex;
            flex-direction: column;
            margin-bottom: 20px;
            &:last-child {
                margin-bottom: 0;
            }
            .rework_qd_item_i {
                display: flex;
                align-items: center;
                margin-bottom: 30px;
                &:last-child {
                    margin-bottom: 0!important;
                }
                .black {
                    font-size: 30px!important;
                    font-weight: 400!important;
                    color: #222222!important;
                }
                span {
                    &:first-child {
                        font-size: 26px;
                        font-weight: 400;
                        color: #666666;
                    }
                    &:last-child {
                        font-size: 26px;
                        font-weight: 400;
                        color: #333333;
                    }
                }
            }
        }
    }
    .zw {
        height: 168px;
    }
    .rework_footer {
        width: calc(100% - 60px);
        position: fixed;
        bottom: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 30px 68px 30px;
        .rework_footer_add {
            flex: 1;
            height: 88px;
            font-size: 30px;
            font-weight: 500;
            color: $nav-color;
            background: #FFFFFF;
            box-shadow: 0 0 12px 0 rgba(0,0,0,0.0800);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .rework_footer_submit {
            flex: 1;
            height: 88px;
            font-size: 30px;
            font-weight: 500;
            color: #ffffff;
            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;
            border: none;
        }
    }
}
</style>