郑永安
2023-06-19 2befd4a5d3733520b69ed97da88e675b6b086a3c
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
<template>
    <el-dialog
        :title="title"
        :visible.sync="dialogVisible"
        :close-on-press-escape="false"
        width="45%">
        <el-form :model="productJudgeForm" ref="ruleForm" label-width="200px">
            <el-row>
                <el-col :span="20">
                    <el-form-item label="企业名称" prop="enterprisename" >
                        <el-select v-model="productJudgeForm.enterprisename" filterable @change="giveEnterpriseNumber">
                            <el-option
                                v-for="item in enterpriseList"
                                :key="item.id"
                                :value="item.enterprisename"
                                :label="item.enterprisename">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20">
                    <el-form-item label="处罚类型" prop="punishmentmeasure">
                        <el-select v-model="productJudgeForm.punishmentmeasure">
                            <el-option
                                v-for="item in punishmentMeasureList"
                                :key="item.id"
                                :value="item.value"
                                :label="item.text">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20">
                    <el-form-item label="处罚原因" prop="punishmentreason">
                        <el-input type="textarea" :row="2" v-model="productJudgeForm.punishmentreason">
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20">
                    <el-form-item label="文件:" prop="directionCode">
                        <input id="upload" ref="upload"  type="file" accept="image/*"/>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div align="center">
            <el-button @click="dialogVisible = false">取消</el-button>
            <el-button type="primary" @click="submit()">确定</el-button>
        </div>
    </el-dialog>
</template>
 
<script>
import {getEnterprise , addProductJudge , updateProductJudge} from "../../../../api/productJudge";
import {dictionaryAllItems} from "../../../../api/dictionary";
import {parseError} from "../../../../utils/messageDialog";
 
export default {
    name: "productJudgeForm",
    data(){
        return{
            title:'',
            dialogVisible:false,
            productJudgeForm:{
                enterprisename:'',
                enterprisenumber:'',
                punishmentmeasure:'',
                punishmentreason:'',
                file:'',
            },
            enterpriseList:[],
            punishmentMeasureList:[],
        }
    },
    created(){
        this.getEnterpriseList()
    },
    methods:{
        showProductJudgeForm(title,value,punishmentMeasureList){
            this.dialogVisible = true
            this.title = title
            this.punishmentMeasureList = punishmentMeasureList
            if(this.title === '新增'){
                this.productJudgeForm = {
                    enterprisename:'',
                    enterprisenumber:'',
                    punishmentmeasure:'',
                    punishmentreason:'',
                }
            }else{
                let form = JSON.parse(JSON.stringify(value))
                this.productJudgeForm.enterprisename = form.enterprisename
                this.productJudgeForm.enterprisenumber = form.enterprisenumber
                this.productJudgeForm.punishmentmeasure = form.punishmentmeasure
                this.productJudgeForm.punishmentreason = form.punishmentreason
                this.productJudgeForm.id = form.id
            }
        },
        async getEnterpriseList(){
            let type = 1
            let res= await getEnterprise(type)
            if(res.data.code === '200'){
                this.enterpriseList = res.data.result
            }
        },
        async submit(){
            const formData = new FormData();
            for (const i in this.productJudgeForm) {
                if (
                    this.productJudgeForm[i] != undefined &&
                    this.productJudgeForm[i].toString() != ""
                ) {
                    formData.append(i, this.productJudgeForm[i]);
                }
            }
            const files1 = this.$refs["upload"].files;
            if (files1 && files1.length > 0) {
                for (let i = 0; i < files1.length; i++)
                    formData.append("file", files1[i]);
            }
            if(this.title === '新增'){
                let res = await addProductJudge(formData)
                if(res.data.code === '200'){
                    this.dialogVisible = false
                    this.$emit('getinfo')
                    this.$notify({
                        duration:2000,
                        type:'success',
                        title:'成功',
                        message:'新增成功'
                    })
                }else{
                    this.$message({
                        type:'warning',
                        message:res.data.message
                    })
                }
            }else{
                let res = await updateProductJudge(formData)
                if(res.data.code === '200'){
                    this.dialogVisible = false
                    this.$emit('getinfo')
                    this.$notify({
                        duration:2000,
                        type:'success',
                        title:'成功',
                        message:'修改成功'
                    })
                }else{
                    this.$message({
                        type:'warning',
                        message:res.data.message
                    })
                }
            }
        },
        giveEnterpriseNumber(){
            for( let i = 0;i<this.enterpriseList.length;i++){
                if(this.productJudgeForm.enterprisename === this.enterpriseList[i].enterprisename){
                    this.productJudgeForm.enterprisenumber = this.enterpriseList[i].enterprisenumber
                    console.log(this.productJudgeForm.enterprisenumber);
                }
            }
        }
    }
}
</script>
 
<style scoped>
/deep/.el-input__inner {
    width:400px;
}
/deep/textarea.el-textarea__inner{
    width:400px;
}
</style>