guoyujie
9 天以前 a6c698f7418c1b0ea6202f068993d74a3347b0e6
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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
<template>
    <view class='main'>
    
        <view class="flex-item title_main">
            <uni-section :title="'流程卡号:'+processId" type="line">
                <template v-slot:right>
                                    <button @click='reviewReportForWork' v-if='!reportState' size='mini'>审核</button>
                                    <button :loading="buttonLoading" @click="saveReportForWork" v-if='reportState'  size='mini'>报工</button>
                </template>
            </uni-section>
            
            
            
        </view>
        <view class="flex-item table_main">
            <uni-table  border stripe  style='width:100%;overflow-y: auto;'>
                <uni-tr>
                        <uni-th width='48' align="center">序号</uni-th>
                        <uni-th width='48' align="center">小片</uni-th>
                        <uni-th width='50' align="center">宽</uni-th>
                        <uni-th width='50' align="center">高</uni-th>
                        <uni-th width='50' align="center">总数</uni-th>
                        <uni-th 
                        @click="cleanAllFinish" 
                        width='50' 
                        align="center" 
                        style="background-color: #409eff;color: black;"
                        >完工</uni-th>
                        <uni-th width='50' align="center">次破</uni-th>
                </uni-tr>
                    
                <uni-tr v-for="(item,index) in processList">
                        <uni-td>{{item.order_number}}</uni-td>
                        <uni-td>{{item.technology_number}}</uni-td>
                        <uni-td>{{item.child_width}}</uni-td>
                        <uni-td>{{item.child_height}}</uni-td>
                        <uni-td>{{item.quantity}}</uni-td>
                        <uni-td>
                            <!-- @keyboardheightchange  @blur-->
                            <input type="number" v-model='item.completedQuantity'
                                :disabled="!reportState"
                                @confirm="changeFinishNum(item)"
                                @blur="changeFinishNum(item)"
                            />
                        </uni-td>
                        <uni-td>
                            <input type="number" v-model='item.breakageQuantity'
                                @confirm='changeBreakNum(item,index)'
                                @blur="changeBreakNum(item,index)"
                                :disabled="!reportState"
                            />
                        </uni-td>
                </uni-tr>
            </uni-table>
        </view>
        <!-- <view class="flex-item uni-bg-blue">C</view> -->  
        
    </view>
    
    <!-- 次破弹出层 -->
    <uni-popup class='breakInfo' ref="popup" :mask-click="false" >
        <view class="flex-item foot_main">
            <uni-row>
                <uni-col class='break_col' :span='24' >第{{damageShowRow}}行</uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >次破类型:</uni-col>
                <uni-col class='break_col' :span='16'>
                    <uni-data-select
                           v-model="damageDetail.breakageType"
                           :localdata="breakageType"
                         />
                </uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >次破原因:</uni-col>
                <uni-col class='break_col' :span='16' >
                    <uni-data-select
                                 v-model="damageDetail.breakageReason"
                                 :localdata="breakageReason"
                             />
                </uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >责任工序:</uni-col>
                <uni-col class='break_col' :span='16'>
                    <uni-data-select
                           v-model="damageDetail.responsibleProcess"
                           :localdata="responsibleProcess"
                                 @change='changeResponsibleProcess'
                         />
                </uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >责任设备:</uni-col>
                <uni-col class='break_col' :span='16'>
                    <uni-data-select
                           v-model="damageDetail.responsibleEquipment"
                           :localdata="responsibleEquipment"
                         />
                </uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >责任班组:</uni-col>
                <uni-col class='break_col' :span='16'>
                    <uni-data-select
                           v-model="damageDetail.responsibleTeam"
                           :localdata="responsibleTeam"
                         />
                </uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >可利用:</uni-col>
                <uni-col class='break_col' :span='16'>
                     <checkbox-group @change='changeAvailable($event)'>
                       <checkbox :value="1" />
                     </checkbox-group>
                </uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >返回工序:</uni-col>
                <uni-col class='break_col' :span='16'>
                     <uni-data-select
                            v-model="damageDetail.returnProcess"
                            :localdata="backProcess"
                          />
                </uni-col>
            </uni-row>
            <uni-row>
                <uni-col class='break_col' :span='8' >责任信息:</uni-col>
                <uni-col class='break_col' :span='16'>
                    <input v-model="damageDetail.responsiblePersonnel" />
                </uni-col>
            </uni-row>
        </view>
        <view>
            
            <uni-row>
                <uni-col :span='12'>
                    <button @click="close(0)">取消</button>
                </uni-col>
                <uni-col :span='12'>
                    <button type="primary" @click="close(1)">确定</button>
                </uni-col>
            </uni-row>
        </view>
    </uni-popup>
    
    <!-- 提示弹窗 -->
    <view>
        <!-- 提示窗示例 -->
        <uni-popup ref="alertDialog" type="dialog">
            <uni-popup-dialog type="warn" 
                cancelText="再次报工" 
                confirmText="确认完成" 
                title="通知" 
                content="流程卡数量还未全部报完!" 
                @confirm="dialogConfirm"
                @close="dialogClose" />
        </uni-popup>
    </view>
    <view>
        <!-- 提示信息弹窗 -->
        <uni-popup ref="message" type="message">
            <uni-popup-message :type="msgType" :message="messageText" :duration="3000"></uni-popup-message>
        </uni-popup>
    </view>
</template>
 
<script setup>
import { computed, onMounted,ref, watch } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import userInfo from '@/stores/userInfo'
import request from '@/utils/request'
    const store=userInfo()
  let processId = ref(null)
    let process = ref(null)
    let reportState = ref(false)
    let damageShowFlag = ref(false)
    let damageShowRow = ref(0)
    let processTitle = ref(null)
    let processList = ref([])
    let buttonLoading = ref(true)
    const alertDialog = ref(null)
    const message = ref(null)
    const popup = ref(null)
    const type=ref('center')
    const msgType=ref('success')
    const messageText=ref('')
    
    //定义接收加载表头下拉数据
    const titleSelectJson = ref({
      historyDevice:[],
      historyTeams:[],
      historyProcess:[],
      breakageType:[],
      breakageReason:[]
    })
 
    //定义破损明细    
    const damageDetail = ref({
        breakageQuantity: null,//破损数量
        available: null,//可利用
        returnProcess: null,//返回工序
        breakageType: null,//破损类型
        breakageReason: null,//原因
        responsibleProcess: null,//责任工序
        responsibleEquipment: null,//责任设备
        responsibleTeam: null,//责任班组
        responsiblePersonnel: null//责任信息
    })
    
 
    
    onLoad(async (option)=>{
        processId.value = option.processId
        process.value = option.process
        await getProcessCardList(option.processId,option.process)
        buttonLoading.value = false
        if(store.choiceDevice.value===null){
            messageToggle('warn','未选择设备,报工设备将以手机形式报工!')
        }
    })
    //查询流程卡
    const getProcessCardList = (processId,process1) => {
        const processIdList = processId.split('/')
        const reportType = 2//报工是否查询样品订单2查询,1不查询
        request.post(`/reportingWork/addSelectLastWork/${processIdList[0]}/${processIdList[1]}/${process1}/${reportType}`)
        .then((res) => {
            if (res.code == 200) {
                    processList.value = res.data.Detail
                    res.data.data.processId = processId
                    processTitle.value = res.data.data
                    //历史班组
                    titleSelectJson.value.historyTeams= res.data.historyTeams
                    titleSelectJson.value.historyTeams.unshift(
                        {
                            basic_name:store.user.userName,
                            process:process.value
                        }
                    ) 
                    //历史设备
                    titleSelectJson.value.historyDevice = res.data.historyDevice
                    //历史工序
                    titleSelectJson.value.historyProcess =  res.data.historyProcess
                    //次破类型
                    titleSelectJson.value.breakageType =  res.data.breakageType
                    //次破原因
                    titleSelectJson.value.breakageReason =  res.data.breakageReason
                    if(res.data.data.reviewedState==1){
                        reportState.value=true
                    }
            }
        }).catch(err => {
            uni.showModal({
                title: '提示',
                content: err,
                showCancel:false
            });
        })
    }
    //报工保存
    const saveReportForWork = () => {
        if(finishNum.value===0){
            messageToggle('error','完工数量或次破数量至少大于0')
            return
        }
        let notSame = null
        
        for(let i in processList.value){
            if(processList.value[i].breakageQuantity!== undefined && processList.value[i].breakageQuantity!==null && processList.value[i].breakageQuantity!==''){
                if(processList.value[i].damageDetails === undefined){
                    messageToggle('error',`序号'${processList.value[i].order_number}'未检测到次破数据`)
                    return
                }else{
                    if(processList.value[i].damageDetails[0].breakageQuantity*1!==processList.value[i].breakageQuantity*1){
                        messageToggle('error',`序号'${processList.value[i].order_number}'次破数量不匹配`)
                        return
                    }
                }
            }else{
                delete processList.value[i].breakageQuantity
            }
            
            
        }
        
        
        const hasConflict = processList.value.some((item, index) => {
            // 检查当前元素之后是否有相同 id 但不同 num 的对象
            return processList.value.slice(index + 1).some(other => {
                    if(other.order_number === item.order_number 
                            && other.completedQuantity !== item.completedQuantity
                                || other.quantity<other.completedQuantity){
                                    
                            notSame = other
                            return true
                        }
                }
            )
        })
        if(hasConflict){
            messageToggle('error',`序号'${notSame.order_number}'同序号完工不相同或数量超过总数`)
            return
        }
        
        
        buttonLoading.value = true
        processTitle.value.teamsGroupsName = store.user.userName
        processTitle.value.deviceName =store.choiceDevice.text ||'phone'
        processTitle.value.deviceId =store.choiceDevice.value ||''
        processTitle.value.creatorId = store.user.userId
        processTitle.value.creator = store.user.userName
        const requestData = {
            title:processTitle.value,
            detail:processList.value,
            type:0,//审核状态
            userId:store.user.userId,
            userName:store.user.userName,
                class:"",
            qualityInsStatus:2//跨工序质检审核,1不需要,2需要
          }
        request.post(`/reportingWork/saveReportingWork`,requestData).then(res =>{
            if(res.code == 200){
                    //messageToggle('success','成功')
                    if(allQuantity.value>finishNum.value){
                        alertDialog.value.open()
                    }else{
                        uni.reLaunch({
                          url: `/pages/mainView/mainView?state=success`
                        })
                    }
                    
            }else{
              const errorObj = JSON.parse(res.msg)
              const msg = t('reportingWorks.pleaseNumber1')+":"+errorObj.orderNumber+'\n'
                  +t('reportingWorks.pleaseNumber2')+':'+errorObj.technologyNumber+'\n'
                  +t('reportingWorks.pleaseNumber3')+':'+errorObj.processNum+'<'+
                  +t('reportingWorks.pleaseNumber4')+':'+errorObj.sumNum+'\n'
                  +t('reportingWorks.pleaseNumber5')
                    messageToggle('error',msg)
            }
          }).catch(err => {
                uni.showModal({
                    title: '提示',
                    content: err,
                    showCancel:false
                });
            }).finally(() => {
                buttonLoading.value = false
            })
    }
    
    //弹出框确认
    const dialogConfirm = () => {
        uni.reLaunch({
          url: `/pages/mainView/mainView?state=success`
        })
    }
    const dialogClose = () => {
        uni.redirectTo({
            url: `/pages/reportingWork/reportingWork?processId=${processId.value}`
        });
    }
    
    //下工序审核
    const reviewReportForWork = () => {
        const reportWork = {
            process: processTitle.value.previousProcess,
            processId:processId.value,
            thisProcess:processTitle.value.thisProcess,
            technologyStr:processId.value.split('/')[1],
            userName:store.user.userName
        }
        request.post("/reportingWork/reviewReportingWork",reportWork).then((res) =>{
            if(res.code === '200'){
                uni.redirectTo({
                    url: `/pages/reportingWork/reportingWork?processId=${processId.value}`
                })
            }
        }).catch(err => {
            uni.showModal({
                title: '提示',
                content: err,
                showCancel:false
            });
        })
    }
    //此流程卡目前总数量
    const allQuantity = computed( () => {
        let sum = 0
        processList.value.forEach( item => {
            let quantity = item.quantity*1 || 0
            sum += quantity
        })
        return sum
    })
    // 完工次破总数量
    const finishNum = computed( () => {
        let sum = 0
        processList.value.forEach( item => {
            let finish = item.completedQuantity*1 || 0
            let breakNum = item.breakageQuantity*1 || 0
            sum += finish
            sum += breakNum
        })
        return sum
    })
    //打开提示框
    const messageToggle = (type,msg) => {
        msgType.value = type
        messageText.value = msg
        message.value.open()
    }
    //判断可利用
    const backProcess = ref([])
    const changeAvailable = (e) => {
        backProcess.value = []
        if(e.detail.value.length){
            damageDetail.value.available = 1
            titleSelectJson.value.historyProcess.forEach( item => {
                backProcess.value.push({
                    value:item.basic_category,
                    text:item.basic_category
                })
            })
        }else{
            damageDetail.value.available = null
            damageDetail.value.returnProcess = null
        }
    }
  //责任工序
    const responsibleProcess = computed(()=>{
        let list = []
        titleSelectJson.value.historyProcess.forEach( item => {
            list.push({
                value:item.basic_category,
                text:item.basic_category
            })
        })
        return list
    })
    //计算属性 次破类型
    const breakageType = computed(()=>{
        let list = []
        titleSelectJson.value.breakageType.forEach( item => {
            list.push({
                value:item.basic_name,
                text:item.basic_name
            })
        })
        return list
    })
    
    //计算属性 次破原因
    const breakageReason = computed(()=>{
        let list = []
        titleSelectJson.value.breakageReason.forEach( item => {
            list.push({
                value:item.basic_name,
                text:item.basic_name
            })
        })
        return list
    })
    
     //责任设备 responsibleEquipment
    const responsibleEquipment = ref([])
    const responsibleTeam = ref([])
    const changeResponsibleProcess = () =>{
        responsibleEquipment.value = []
        responsibleTeam.value = []
        damageDetail.value.responsibleEquipment = null
        damageDetail.value.responsibleTeam = null
        titleSelectJson.value.historyDevice.forEach( item => {
            if(item.basic_category===damageDetail.value.responsibleProcess){
                responsibleEquipment.value.push({
                    value:item.basic_name,
                    text:item.basic_name
                })
            }
        })
        titleSelectJson.value.historyTeams.forEach( item => {
            if(item.process===damageDetail.value.responsibleProcess){
                responsibleTeam.value.push({
                    value:item.basic_name,
                    text:item.basic_name
                })
            }
        })
    }
    // 完工改变
    const changeFinishNum = (row) => {
        damageShowFlag.value = false
        const finishNum = row.completedQuantity*1 || 0
        const breakNum = row.breakageQuantity*1 || 0
        if((row.quantity-finishNum-breakNum)<0){
            row.completedQuantity = null
            return
        }
        processList.value.forEach(item => {
            if(item.order_number == row.order_number && finishNum<=item.quantity){
                item.completedQuantity = finishNum
            }
        })
    }
    const changeBreakNum = (row,index) => {
        const finishNum = row.completedQuantity*1 || 0
        const breakNum = row.breakageQuantity*1 || 0
        if((row.quantity-breakNum)<0){
            row.breakageQuantity = null
            return
        }
        row.completedQuantity = row.quantity-breakNum
        if(processList.value[index].damageDetails){
            damageDetail.value = processList.value[index].damageDetails[0]
        }else{
            for(let index in damageDetail.value){
                damageDetail.value[index] = null
            }
        }
        
        if(breakNum*1>0){
            damageDetail.value.breakageQuantity = breakNum*1
            damageShowRow.value = index+1
            popup.value.open()
        }else{
            delete processList.value[index].damageDetails
            for(let index in damageDetail.value){
                damageDetail.value[index] = null
            }
        }
        
    }
    
    const rules = {
        breakageType: '请选择次破类型',
        breakageReason:'请选择次破原因',
        responsibleProcess:'请选择责任工序',
        responsibleEquipment:'请选择责任设备',
        responsibleTeam:'请选择责任班组',
        returnProcess:'可利用已勾选,请选择返回工序'
    }
    
    const close = (type) => {
        //判断是否是确定
        if(type===1){
            for(let item in rules){
                //判断选中可利用和下拉框是否为空
                if(!damageDetail.value[item] && item!=='returnProcess'){
                    messageToggle('error',rules[item])
                    return
                }else if(item==='returnProcess' && !damageDetail.value[item] && damageDetail.value['available']){
                    messageToggle('error',rules[item])
                    return
                }
            }
            //每行破损赋值
            processList.value[damageShowRow.value-1].damageDetails = [
                JSON.parse(JSON.stringify(damageDetail.value))
            ]
        }else{
            delete processList.value[damageShowRow.value-1].breakageQuantity
            delete processList.value[damageShowRow.value-1].damageDetails
        }
        popup.value.close()
    }
    
    const cleanAllFinish = () => {
        processList.value.forEach(item => {
            item.completedQuantity = 0
        })
    }
    
 
</script>
 
<style>
    .main{
        width: 100vw;
        height: 93.5vh
    }
    .flex-item{
        /* flex-direction: column;
        background-color: aliceblue; */
    }
    .title_main{
        width: 100vw;
        height: 12vh;
    }
    .table_main{
        width: 100vw;
        height: 80vh;
        margin: 0 auto;
    }
    .foot_main{
        width: 96vw;
        margin: 0 auto;
        background-color: white;
    }
    
    .uni-row{
        text-align: center;
    }
    .break_col{
        height: 35px;
        border:1px solid black;
    }
    .breakInfo{
        width: 96vw;
    }
</style>