<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>
|