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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
    <div class="system-add-menu-container">
        <el-dialog :title="title" v-model="isShowInspectTargetDialog" width="600px">
            <el-form :model="inspectTargetForm" :rules="inspectTargetFormRules" ref="inspectTargetFormRef" 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="指标名称" prop="quota">
                            <el-input class="input-length" v-model.trim="inspectTargetForm.quota" placeholder="请输入指标名称" 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="指标类型" prop="quotaTypeId">
                            <el-select
                                class="input-length"
                                v-model="inspectTargetForm.quotaTypeId"
                                @change="changeQuotaUnit"
                                placeholder="请选择指标类型"
                                clearable
                                filterable
                            >
                                <el-option v-for="item in quotaTypeList" :key="item.id" :label="item.type" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="指标单位" prop="quotaUnit">
                            <el-input
                                class="input-length"
                                v-model.trim="inspectTargetForm.quotaUnit"
                                type="textarea"
                                placeholder="请输入指标单位"
                                maxlength="150"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="isShowInspectTargetDialog = !isShowInspectTargetDialog" size="default">取 消</el-button>
                    <el-button type="primary" @click="submitInspectTarget" v-throttle size="default">确 实</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script lang="ts">
import { inspectPointApi } from '/@/api/intellectInspectSystem/inspectPointManage';
 
interface stateType {
    isShowInspectTargetDialog: Boolean;
    inspectTargetForm: {
        quota: string;
        quotaTypeId: number | null;
        quotaUnit: string;
    };
    title: string;
    quotaTypeList: Array<quotaTypeState>;
    inspectTargetFormRules: {};
}
interface quotaTypeState {
    id: number;
    type: string;
    unit: string;
}
import { reactive, toRefs, ref, computed } from 'vue';
import { inspectTargetApi } from '/@/api/intellectInspectSystem/inspectTargetManage';
import { ElMessage } from 'element-plus';
export default {
    name: 'inspectTargetDialog',
    setup(props: any, context: any) {
        const inspectTargetFormRef = ref();
        const state = reactive<stateType>({
            title: '',
            quotaTypeList: [],
            isShowInspectTargetDialog: false,
            inspectTargetForm: {
                quota: '',
                quotaTypeId: null,
                quotaUnit: ''
            },
            inspectTargetFormRules: {
                quota: [{ required: true, message: '请填写指标名称', trigger: 'blur' }],
                quotaTypeId: [{ required: true, message: '请选择指标类型', trigger: 'change' }],
                quotaUnit: [{ required: true, message: '请选择指标单位', trigger: 'blur' }]
            }
        });
 
        //打开模态框
        const openInspectTargetDialog = (type: string, value: { id: number }, quotaTypeList: []) => {
            state.isShowInspectTargetDialog = true;
            state.quotaTypeList = quotaTypeList;
            setTimeout(() => {
                inspectTargetFormRef.value.clearValidate();
            });
            if (type === '新增') {
                state.title = '新增巡检指标';
                state.inspectTargetForm = {
                    quota: '',
                    quotaTypeId: null,
                    quotaUnit: ''
                };
            } else {
                state.title = '修改巡检指标';
                inspectTargetApi()
                    .getInspectTargetById(value.id)
                    .then((res) => {
                        if (res.data.code === '200') {
                            state.inspectTargetForm = JSON.parse(JSON.stringify(res.data.data));
                        } else {
                        }
                    })
                    .catch((error) => {});
            }
        };
 
        const changeQuotaUnit = () => {
            state.inspectTargetForm.quotaUnit = JSON.parse(JSON.stringify(state.quotaTypeList)).find(
                (item: any) => item.id === state.inspectTargetForm.quotaTypeId
            ).unit;
        };
 
        //新增修改提交
        const submitInspectTarget = async () => {
            inspectTargetFormRef.value.validate(async (valid: Boolean) => {
                if (valid) {
                    if (state.title === '新增巡检指标') {
                        let res = await inspectTargetApi().addInspectTarget(state.inspectTargetForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '巡检指标新增成功',
                                duration: 2000
                            });
                            state.isShowInspectTargetDialog = false;
                            context.emit('refreshInspectTarget');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    } else {
                        let res = await inspectTargetApi().modInspectTarget(state.inspectTargetForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '生巡检指标修改成功',
                                duration: 2000
                            });
                            state.isShowInspectTargetDialog = false;
                            context.emit('refreshInspectTarget');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    }
                } else {
                    ElMessage({
                        type: 'warning',
                        message: '请完善基本信息'
                    });
                }
            });
        };
 
        return {
            ...toRefs(state),
            changeQuotaUnit,
            inspectTargetFormRef,
            submitInspectTarget,
            openInspectTargetDialog
        };
    }
};
</script>
 
<style scoped>
.input-length {
    width: 85%;
}
</style>