Your Name
2022-07-28 d472b2904009d1785edd337627a4816843f10899
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
<template>
    <div class="system-add-menu-container">
        <el-dialog :title="title" v-model="isShowRFIDDialog" width="600px">
            <el-form :model="RFIDForm" :rules="RFIDFormRules" ref="RFIDFormRef" size="default" label-width="120px">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="RFID名称" prop="rfidName">
                            <el-input class="input-length" v-model.trim="RFIDForm.rfidName" placeholder="请输入RFID名称" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="RFID编码" prop="rfid">
                            <el-input class="input-length" v-model.trim="RFIDForm.rfid" placeholder="请输入RFID编码" clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="isShowRFIDDialog = !isShowRFIDDialog" size="default">取 消</el-button>
                    <el-button type="primary" @click="submitRFID" v-throttle size="default">确 实</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script lang="ts">
interface stateType {
    isShowRFIDDialog: Boolean;
    RFIDForm: {
        rfid: string;
        rfidName: string;
    };
    title: string;
    RFIDFormRules: {};
}
interface levelListState {}
import { reactive, toRefs, ref } from 'vue';
import { RFIDApi } from '/@/api/intellectInspectSystem/RFID';
import { ElMessage } from 'element-plus';
export default {
    name: 'RFIDDialog',
    setup(props: any, context: any) {
        const RFIDFormRef = ref();
        const state = reactive<stateType>({
            title: '',
            isShowRFIDDialog: false,
            RFIDForm: {
                rfid: '',
                rfidName: ''
            },
            RFIDFormRules: {
                rfid: [{ required: true, message: '请填写RFID编码', trigger: 'blur' }],
                rfidName: [{ required: true, message: '请填写RFID名称', trigger: 'change' }],
                riskLevel: [{ required: true, message: '请选择风险等级', trigger: 'change' }],
                location: [{ required: true, message: '请填写区域位置', trigger: 'blur' }]
            }
        });
 
        //打开模态框
        const openRFIDDialog = (type: string, value: object) => {
            state.isShowRFIDDialog = true;
            setTimeout(() => {
                RFIDFormRef.value.clearValidate();
            });
            if (type === '新增') {
                state.title = '新增巡检指标';
                state.RFIDForm = {
                    rfid: '',
                    rfidName: ''
                };
            } else {
                state.title = '修改巡检指标';
                state.RFIDForm = JSON.parse(JSON.stringify(value));
            }
        };
 
        //新增修改提交
        const submitRFID = async () => {
            RFIDFormRef.value.validate(async (valid: Boolean) => {
                if (valid) {
                    if (state.title === '新增巡检指标') {
                        let res = await RFIDApi().addRFID(state.RFIDForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '巡检指标新增成功',
                                duration: 2000
                            });
                            state.isShowRFIDDialog = false;
                            context.emit('refreshRFID');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    } else {
                        let res = await RFIDApi().modRFID(state.RFIDForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '巡检指标修改成功',
                                duration: 2000
                            });
                            state.isShowRFIDDialog = false;
                            context.emit('refreshRFID');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    }
                } else {
                    ElMessage({
                        type: 'warning',
                        message: '请完善基本信息'
                    });
                }
            });
        };
 
        return {
            ...toRefs(state),
            RFIDFormRef,
            submitRFID,
            openRFIDDialog
        };
    }
};
</script>
 
<style scoped>
.input-length {
    width: 85%;
}
</style>