zhouwx
2024-12-04 80c8993820fc3f958397bebe9dbd72be6a449c55
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
<template>
    <div class="system-add-gas-container">
        <el-dialog
            :title="state.title"
            v-model="state.isShowUserDialog"
            width="550px"
        >
            <el-form :model="state.setForm" size="default" ref="gasRef" :rules=" state.title == '修改' ?state.setFormRules:''" label-width="150px">
                <el-form-item label="预警名称:" prop="name">
                    <span>{{state.setForm.name}}</span>
                </el-form-item>
                <el-form-item label="连续超过阈值点数:" prop="threshold">
                    <el-input v-model.trim="state.setForm.threshold" :disabled="state.disabled"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="handleClose" size="default" v-if="!state.disabled">取 消</el-button>
                    <el-button type="primary"  @click="onSubmit" size="default">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script setup lang="ts">
import {reactive, ref} from "vue";
import {SetState} from "/@/types/warning";
import { warningSetApi } from "/@/api/warningManage/warningSet";
import {ElMessage} from "element-plus/es";
 
const gasRef = ref();
const emit = defineEmits(["getSetData"]);
const state = reactive<SetState>({
    title: '',
    isShowUserDialog: false,
    disabled: false,
    setForm: {
        id: '',
        name: '',
        threshold: 0
    },
    setFormRules:{
        threshold: [{ required: true, message: '请填写连续超过阈值点数', trigger: 'blur' }],
    }
});
const openDialog = (type: string, value: any) => {
    state.isShowUserDialog = true;
    if (type === '查看') {
        state.disabled = true;
        state.title = '查看';
        state.setForm = JSON.parse(JSON.stringify(value));
    } else {
        state.disabled = false;
        state.title = '修改';
        state.setForm = JSON.parse(JSON.stringify(value));
    }
};
const onSubmit = async () => {
 
    if(state.title == '修改'){
        const valid = gasRef.value.validate();
        if(valid){
            const param = {
                id: state.setForm.id,
                threshold: state.setForm.threshold
            }
            let res = await warningSetApi().handelWarnSet(param);
            if(res.data.code == 100){
                ElMessage({
                    type: 'success',
                    message: '修改成功'
                });
            }else {
                ElMessage({
                    type: 'error',
                    message: res.data.msg
                });
            }
        }
        gasRef.value.clearValidate();
        state.isShowUserDialog = false;
        emit('getSetData');
    }else {
        state.isShowUserDialog = false;
        emit('getSetData');
    }
};
 
const handleClose = () => {
    gasRef.value.clearValidate();
    state.isShowUserDialog = false;
    emit('getSetData');
}
 
defineExpose({
    openDialog
});
</script>
<style scoped lang="scss">
 
</style>