liuying
2025-09-24 16edbbe772e24eb71f6519558576d513e3cf2746
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
<template>
    <u-modal :show="show" title="选择状态" :closeOnClickOverlay="true" @confirm="handlerConfirm" @close="close">
        <view class="status_flex">
            <view v-for="(item,index) in statusArr" :key="item.code" class="flex_item" @click="activeIndex = index" :class="activeIndex == index ? 'active_item' : ''">
                {{item.title}}
            </view>
            <u-form labelPosition="left" labelWidth="100rpx" :model="form" :rules="rules" ref="uForm">
                <u-form-item v-if="activeIndex==1||activeIndex==2" required label="不合格原因" prop="qualityErrorInfo">
                    <u-textarea :maxlength="255" v-model="form.qualityErrorInfo" placeholder="请输入不合格原因"></u-textarea>
                </u-form-item>
                <u-form-item required label="密码" prop="pwd">
                    <u-input v-model="form.pwd" type="password" placeholder="请输入密码" style="width: 450rpx;"></u-input>
                </u-form-item>
            </u-form>
            
        </view>
    </u-modal>
</template>
 
<script>
    import {$alert} from '@/static/js/utils/index.js'
    import { updateSomeBarStatus} from '@/api/unBindAll/index.js'
    export default {
        emits: ['updateData'],
        data() {
            return {
                show: false,
                activeIndex: 100,
                checkArr:[],
                statusArr:[],
                form: {
                    pwd: '',
                    qualityErrorInfo: ''
                },
                rules: {
                    pwd: {
                        type: 'string',
                        required: true,
                        message: '请输入密码',
                        trigger: ['blur', 'change']
                    },
                    qualityErrorInfo: {
                        type: 'string',
                        required: true,
                        message: '请输入不合格原因',
                        trigger: ['blur', 'change']
                    }
                }
            }
        },
        watch:{
            activeIndex:{
                handler(val){                    
                    if(val==1) {
                        this.form.qualityErrorInfo='不合格'
                    }else if(val==2){
                        this.form.qualityErrorInfo='疑似'
                    }else {
                        this.form.qualityErrorInfo=''
                    }
                }
            }
        },
        methods: {
            showModal(checkArr,statusArr){
                this.show=true
                this.checkArr=checkArr
                this.statusArr=statusArr
            },
            // 选中的状态传递给父组件
            handlerConfirm() {
                
                if(this.activeIndex > 2) {
                    return uni.showToast({
                        title: '请选择状态',
                        icon: 'error'
                    })
                }
                
                this.$refs.uForm.validate().then(res => {
                    const pieceArr = this.checkArr.reduce((curr,item) => {
                        curr.push(item.workPieceID)
                        return curr;
                    },[])
                    
                    const params = {
                        workPieceIDList: pieceArr,
                        qualityState: this.statusArr[this.activeIndex].code,
                        password: this.form.pwd,
                        qualityErrorInfo:this.form.qualityErrorInfo
                    }
                    updateSomeBarStatus(params).then(res => {
                        uni.showToast({
                            title:'批量更改成功'
                        })
                        this.$emit('updateData')
                        this.close()
                    })
                })
            },
            close() {
                this.show = false
                this.activeIndex = 100;
                this.form = {
                    pwd: '',
                    qualityErrorInfo: ''
                }
            }
            
        },
        onReady() {
            this.$refs.uForm.setRules(this.rules)
        }
    }
</script>
 
<style lang="scss" scoped>
    .status_flex {
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        .flex_item {
            width: 450rpx;
            height: 70rpx;
            text-align: center;
            line-height: 70rpx;
            border: 1px solid $color-common;
            color: $color-common;
            font-size: 32rpx;
            font-weight: 550;
            background: #fff;
            margin-bottom: 30rpx;
        }
        .active_item {
            background: $color-common;
            color: #fff;
        }
    }
</style>