zhouwx
2024-04-16 42235ae8c08bcc09bb53a3631f988e74a0920db4
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
<template>
    <div class="notice">
        <el-dialog
            v-model="dialogVisible"
            :title="title"
            width="500px"
            :before-close="handleClose"
        >
            <el-form :model="state.form" size="default" ref="busRef" :rules="state.formRules" label-width="110px" >
                <el-form-item label="类型:" prop="label">
                    <el-input v-model.trim="state.form.label"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                    <span class="dialog-footer">
                        <el-button @click="handleClose" size="default">取 消</el-button>
                        <el-button type="primary"  @click="onSubmit" size="default" v-preReClick>确认</el-button>
                    </span>
            </template>
        </el-dialog>
    </div>
</template>
<script setup>
import {reactive, ref, toRefs} from 'vue'
import Editor from "@/components/Editor/index.vue";
import {ElMessage} from "element-plus";
import {addNotice} from "@/api/backManage/notice";
import {addDict, editDict, getDictDetail} from "@/api/backManage/evaluate";
 
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const state = reactive({
    form: {
        id: '',
        label: '',
        value: '',
        dictType: "sys_assess_type",
    },
    formRules:{
        label: [{ required: true, message: '请输入类型', trigger: 'blur' }],
    },
 
})
 
const openDialog = async (type, value) => {
    length.value = value.listLength
    title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ;
    if(type === 'edit') {
        state.form = value;
        const param = {
            dictId: value.id
        }
        const res = await getDictDetail(param);
        if(res.code === 200){
            state.form = res.data
        }else{
            ElMessage.warning(res.message)
        }
    }
    dialogVisible.value = true;
}
 
const onSubmit = async () => {
    const valid = await busRef.value.validate();
    if(valid){
        if(title.value === '新增'){
            const param = {
                dictType: "sys_assess_type",
                label: state.form.label,
                value: length.value.toString()
            }
            const res = await addDict(param)
            if(res.code === 200){
                ElMessage({
                    type: 'success',
                    message: '新增成功'
                });
            }else{
                ElMessage.warning(res.message)
            }
            emit("getList")
            busRef.value.clearValidate();
            reset();
            dialogVisible.value = false;
        }else if(title.value === '编辑'){
            const param = {
                id: state.form.id,
                dictType: state.form.dictType,
                label: state.form.label,
                value: state.form.value
            }
            const res = await editDict(param)
            if(res.code === 200){
                ElMessage({
                    type: 'success',
                    message: '新增成功'
                });
            }else{
                ElMessage.warning(res.message)
            }
            emit("getList")
            busRef.value.clearValidate();
            reset();
            dialogVisible.value = false;
        }
    }
}
 
const handleClose = () => {
    busRef.value.clearValidate();
    reset();
    dialogVisible.value = false;
 
}
const reset = () => {
    state.form = {
        id: '',
        label: '',
        value: '',
        dictType: "sys_assess_type",
    }
}
defineExpose({
    openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
    :deep(.el-form .el-form-item__label) {
        font-size: 15px;
    }
    .file {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
}
</style>