zhouwenxuan
2023-12-01 3451f5695d6fb65eeac2f4eedd9bf8cdd16a6d79
src/views/safetyReview/baseSet/business/components/businessDialog.vue
@@ -7,8 +7,8 @@
            :before-close="handleClose"
        >
            <el-form :model="state.form" size="default" ref="busRef" :rules="state.formRules" label-width="110px" >
                <el-form-item label="业务范围:" prop="business">
                    <el-input v-model.trim="state.form.business"></el-input>
                <el-form-item label="业务范围:" prop="label">
                    <el-input v-model.trim="state.form.label"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
@@ -24,24 +24,41 @@
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: {
        business: ''
        id: '',
        label: '',
        value: '',
        dictType: "sys_business_scope",
    },
    formRules:{
        business: [{ required: true, message: '请输入业务范围', trigger: 'blur' }],
        label: [{ required: true, message: '请输入业务范围', trigger: 'blur' }],
    },
})
const openDialog = (type, value) => {
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;
}
@@ -49,10 +66,46 @@
const onSubmit = async () => {
    const valid = await busRef.value.validate();
    if(valid){
        if(title.value === '新增'){
            const param = {
                dictType: "sys_business_scope",
                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;
        }
    }
}
@@ -64,7 +117,10 @@
}
const reset = () => {
    state.form = {
        business: ""
        id: '',
        label: '',
        value: '',
        dictType: "sys_business_scope",
    }
}
defineExpose({