Kxc0822a
2022-03-22 b2333b4b48e68e740d3c6db22a7280f54debd907
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<template>
    <div class="app-container">
        <div class="filter-container">
            <div class="basic_search">
                <span>设备名称:</span>
                <el-input v-model="name" style="width:200px">
                </el-input>
            </div>
            <div class="basic_search">
                <span style="margin-left: 20px;">状态:</span>
                <el-select v-model="state" placeholder="请选择状态">
                    <el-option label="未处理" value="shanghai"></el-option>
                    <el-option label="已处理" value="beijing"></el-option>
                </el-select>
            </div>
            <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-refresh" @click="refreshHandle">刷新</el-button>
            <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-plus" @click="showCreateHandle">新增</el-button>
            <el-button class="filter-item" type="primary" icon="el-icon-search" @click="queryHandle" />
        </div>
        <div class="table_content">
            <el-table
                v-loading="listLoading"
                :key="tableKey"
                :data="roleData"
                border
                fit
                highlight-current-row
                style="width: 100%;"
            >
                <el-table-column label="设备名称" prop="name" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.name }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="状态" prop="state" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.state }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="报警时间" prop="time" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.time }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="报警信息" prop="information" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.information }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remarks" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.remarks }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" width="280" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="showEditHandle(scope.row)">编辑</el-button>
                        <el-button type="danger" size="mini" @click="deleteHandle(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <br>
        </div>
        <el-dialog :title="dialogStatus==='create'?'新增':'编辑'" :visible.sync="dialogFormVisible" :modal-append-to-body="false" :close-on-click-modal="false" width="700px">
            <el-form ref="dataForm" :rules="dataFormRules" :model="dataForm" label-position="right" label-width="120px" style="margin-left:50px;margin-right:50px;" element-loading-text="保存中...">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="设备名称" prop="name">
                            <el-input v-model.trim="dataForm.name"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="状态" prop="state">
                            <el-select v-model="dataForm.state" placeholder="请选择状态">
                                <el-option label="未处理" value="shanghai"></el-option>
                                <el-option label="已处理" value="beijing"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="仪表量上限" prop="volume">
                            <el-input v-model.trim="dataForm.volume"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="报警时间" prop="time">
                            <el-input v-model.trim="dataForm.time"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="报警信息" prop="information">
                            <el-input type="textarea" v-model.trim="dataForm.information"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="备注" prop="remarks">
                            <el-input type="textarea" v-model.trim="dataForm.remarks"/>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="dialogStatus==='create'?createHandle():updateHandle()">确认</el-button>
            </div>
        </el-dialog>
        <div style="clear: both;"/>
    </div>
</template>
 
<script>
    import { mapGetters } from 'vuex'
    import { roleList, createRole, deleteRole, updateRole, getRole, updateRolePermission} from '@/api/role'
    import { permissionList } from '@/api/permission'
    import { parseTime, computePageCount } from '@/utils'
    import { parseError } from '@/utils/messageDialog'
    import Cookies from 'js-cookie'
    import { Message, MessageBox } from 'element-ui'
    import { initRouter } from '@/utils/router'
    export default {
        name: 'RoleTable',
        filters: {
        },
        computed: {
            ...mapGetters([
                'userType'
            ])
        },
        data() {
            return {
                tableKey: 0,
                roleData: null,
                listLoading: true,
                dataForm: {
                    state: '',
                    name:'',
                    volume:'',
                    information:'',
                    time:'',
                    remarks: ''
                },
                queryForm: {
                    name: ''
                },
                dialogFormVisible: false,
                dialogStatus: '',
                dataFormRules: {
                    name: [{ required: true, message: '角色名不能为空', trigger: 'blur' }]
                },
                treeLoading: false,
                selectAllFlag: false,
                hasMenuTree: [],
                editRolePermId: '',
                company:'',
                region:'',
            }
        },
        created() {
            this.getRoleList()
        },
        methods: {
            getRoleList() {
                const _this = this
                const params = {}
                const userName = Cookies.get('userName')
                params['operator'] = userName
                for (const i in _this.queryForm) {
                    if (_this.queryForm[i] != undefined && _this.queryForm[i].toString() != '') {
                        params[i] = _this.queryForm[i]
                    }
                }
                _this.listLoading = true
                roleList(params).then(response => {
                    const res = response.data
                    if (res.code == 200) {
                        _this.roleData = res.result
                    } else {
                        parseError({ error: res.message, vm: _this })
                    }
                    _this.listLoading = false
                }).catch(error => {
                    _this.listLoading = false
                    parseError({ error: error, vm: _this })
                })
            },
            createHandle: function() {
                const _this = this
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        const userName = Cookies.get('userName')
                        _this.dataForm['operator'] =userName
                        createRole(_this.dataForm).then(response => {
                            const res = response.data
                            if (res.code == 200) {
                                _this.dialogFormVisible = false
                                _this.$message({
                                    message: '创建成功',
                                    type: 'success'
                                })
                                _this.getRoleList()
                            } else {
                                parseError({ error: res.message, vm: _this })
                            }
                        }).catch(error => {
                            parseError({ error: error, vm: _this })
                        })
                    }
                })
            },
            deleteHandle: function(row) {
                const _this = this
                MessageBox.confirm('确定删除角色' + row.name + '信息', '确定删除', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    _this.deleteAction(row)
                }).catch(() => {
                    console.log('已取消删除')
                })
            },
            deleteAction: function(row) {
                const _this = this
                const params = {}
                params['id'] = row.id
                const userName = Cookies.get('userName')
                params['operator'] = userName
                deleteRole(params).then(response => {
                    const res = response.data
                    if (res.code == 200) {
                        _this.$message({
                            message: '删除成功',
                            type: 'success'
                        })
                        _this.getRoleList()
                    } else {
                        parseError({ error: res.message, vm: _this })
                    }
                }).catch(error => {
                    parseError({ error: error, vm: _this })
                })
            },
            refreshHandle: function() {
                this.getRoleList()
            },
            queryHandle: function() {
                this.getRoleList()
            },
            resetDataForm() {
                this.dataForm = {
                    name: '',
                    id: '',
                }
            },
            showCreateHandle() {
                this.resetDataForm()
                this.dialogStatus = 'create'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].clearValidate()
                })
            },
            updateHandle() {
                this.$refs['dataForm'].validate((valid) => {
                    const _this = this
                    if (valid) {
                        const userName = Cookies.get('userName')
                        _this.dataForm['operator'] = userName
                        updateRole(_this.dataForm).then(response => {
                            const res = response.data
                            if (res.code == 200) {
                                _this.dialogFormVisible = false
                                _this.$message({
                                    message: '更新成功',
                                    type: 'success'
                                })
                                _this.getRoleList()
                            } else {
                                parseError({ error: res.message, vm: _this })
                            }
                        }).catch(error => {
                            parseError({ error: error, vm: _this })
                        })
                    }
                })
            },
            showEditHandle: function(row) {
                this.resetDataForm()
                this.dialogStatus = 'editor'
                this.dataForm.name = row.name
                this.dataForm.id = row.id
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].clearValidate()
                })
            },
            handleSizeChange: function(val) {
                this.getRoleList()
            },
            handleCurrentChange: function(val) {
                this.getRoleList()
            },
            getPermissionList() {
                const _this = this
                const params = {}
                params['userId'] = Cookies.get('userId')
                permissionList(params).then(response => {
                    const res = response.data
                    if (res.code == 200) {
                    } else {
                        parseError({ error: res.message, vm: _this })
                    }
                })
            },
            setNodeChecked(nodeId) {
                const node = this.$refs.menuTree.getNode(nodeId)
                if (!node.checked) {
                    this.$refs.menuTree.setChecked(nodeId, true)
                }
                if (node) {
                    if (node.data.parentid == 0 || node.data.parentid) {
                        this.setNodeChecked(node.data.parentid)
                    }
                }
            },
            cancelNodeChecked(nodeId) {
                const checkNodes = this.$refs.menuTree.getCheckedNodes()
                const childNode = []
                for (const checkNode of checkNodes) {
                    if (checkNode.parentid == nodeId) {
                        childNode.push(checkNode)
                    }
                }
                if (childNode.length > 0) {
                    for (const child of childNode) {
                        this.$refs.menuTree.setChecked(child.id, false)
                        this.cancelNodeChecked(child.id)
                    }
                }
            }
        }
    }
</script>
<style scoped>
    .basic_search{
        display:inline-block;
        padding-bottom: 10px;
    }
    .filter-container .filter-item{
        margin-bottom: 0;
    }
</style>