Your Name
2022-08-24 bc2747387df0693aa46a55bb556985aaf881d843
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<template>
    <div class="app-container">
        <div class="filter-container">
            <div class="basic_search">
                <span>事件名称:</span>
                <el-input v-model="listQuery.riskEventName" style="width:200px">
                </el-input>
            </div>
            <el-button class="filter-item" style="margin-left: 10px;margin-top: 10px" type="primary" icon="el-icon-refresh" @click="refreshHandle">搜索</el-button>
            <el-button class="filter-item" style="margin-left: 10px;margin-top: 10px" type="primary" icon="el-icon-plus" @click="showRiskEvent('','新增')">新增</el-button>
            <el-button class="filter-item" style="margin-left: 10px;margin-top: 10px" type="primary"  @click="showImportDialog()">导入</el-button>
<!--            <el-button class="filter-item" style="margin-left: 10px;margin-top: 10px" type="primary" @click="exportToExcel">导出</el-button>-->
        </div>
        <div class="table_content">
            <el-table
                v-loading="listLoading"
                :key="tableKey"
                :data="riskEventData"
                border
                fit
                highlight-current-row
                style="width: 100%;"
            >
                <el-table-column type="index" label="序号" width="60" />
                <el-table-column prop="riskUnitName" label="安全风险分析单元名称" width="180" show-overflow-tooltip></el-table-column>
                <el-table-column prop="riskEventName" label="安全风险事件名称" width="180" show-overflow-tooltip></el-table-column>
                <el-table-column prop="createByUserName" label="创建人" show-overflow-tooltip></el-table-column>
                <el-table-column prop="gmtCreate" label="创建时间" show-overflow-tooltip></el-table-column>
                <el-table-column prop="lastEditUserName" label="最后修改人" show-overflow-tooltip></el-table-column>
                <el-table-column prop="gmtModitify" label="最后修改时间" show-overflow-tooltip></el-table-column>
                <el-table-column label="操作" align="center" width="280" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button type="text" @click="showRiskEvent(scope.row,'编辑')">编辑</el-button>
                        <el-button type="text" style="color: red" @click="deleteById(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <br>
            <el-pagination
                v-show="recordTotal>0"
                :current-page="listQuery.pageIndex"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="listQuery.pageSize"
                :total="recordTotal"
                layout="total, sizes, prev, pager, next, jumper"
                background
                style="float:right;"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
            />
            <br>
        </div>
        <el-dialog :title="title" :visible.sync="riskEventVisible" :modal-append-to-body="false" :close-on-click-modal="false" width="600px">
            <el-form ref="riskEventForm" :rules="riskEventFormRules" :model="riskEventForm" label-position="right" label-width="165px">
                <el-form-item label="安全风险分析单元名称" prop="riskUnitId">
                    <el-select v-model="riskEventForm.riskUnitId" placeholder="请输入安全风险分析单元名称" class="analyseUnit_box">
                        <el-option
                            v-for="item in analyseUnitList"
                            :key="item.riskUnitName"
                            :value="item.id"
                            :label="item.riskUnitName"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="安全风险事件名称" prop="riskEventName">
                    <el-input v-model="riskEventForm.riskEventName" placeholder="请输入安全风险事件名称" class="analyseUnit_box"></el-input>
                </el-form-item>
            </el-form>
            <div  align="right">
                <el-button @click="riskEventVisible = false">取消</el-button>
                <el-button type="primary" @click="submitRiskEvent()">确认</el-button>
            </div>
        </el-dialog>
        <el-dialog
            :visible.sync="importDialogFormVisible"
            :modal-append-to-body="false"
            :close-on-click-modal="false"
            title="用户导入"
            width="700px"
        >
            <el-form
                ref="importForm"
                label-position="right"
                label-width="120px"
                style="margin-left:50px;width:500px;"
                element-loading-text="导入中..."
            >
                <el-form-item label="导入文件:">
                    <input ref="importLabInput" type="file" accept=".xls, .xlsx" >
                </el-form-item>
                <el-form-item label="excel参考模板:">
                    <el-button type="text" @click="viewHandle">下载模板</el-button>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="importDialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="importToTable()">导入</el-button>
            </div>
        </el-dialog>
    </div>
</template>
 
<script>
    import { mapGetters } from 'vuex'
    import { computePageCount } from '@/utils'
    import { addRiskEvent, deleteRiskEvent, getRiskEventList, updateRiskEvent } from '@/api/riskLevelManage'
    const exampleFile = require('@/assets/example/riskEvent.xlsx')
    import {
        exportRiskEvent, getAllSafetyRiskAnalyseUnitList,
        getAnalyseUnitList,
        importRiskEvent
    } from "../../../../api/riskLevelManage";
    import {parseError} from "../../../../utils/messageDialog";
    export default {
        name: 'index',
        filters: {
            parseMain(type){
                if(type === 1){
                    return "是"
                }else if(type === 0){
                    return "否"
                }
            },
        },
        computed: {
            ...mapGetters([
                'userType'
            ])
        },
        data() {
            return {
                tableKey: 0,
                riskEventData: [],
                analyseUnitList:[],
                listLoading: false,
                pageSize: 10,
                recordTotal: 0,
                currentPage: 1,
                pageTotal: 0,
                title:'',
                company:'',
                code:'',
                importDialogFormVisible:false,
                riskEventVisible:false,
                riskEventFormRules:{
                    riskUnitId: [{ required: true, message: '安全风险分析单元名称不能为空', trigger: 'change' }],
                    riskEventName: [{ required: true, message: '安全风险事件名称不能为空', trigger: 'blur' }],
 
                },
                riskEventForm:{
                    riskEventName: null,
                    riskUnitId: null
                },
                listQuery:{
                    pageIndex: 1,
                    pageSize: 10,
                    riskEventName: null
                },
            }
        },
        created() {
            this.getRiskEventData()
            this.getAnalyseUnitData()
        },
        methods: {
            async getRiskEventData(){
                this.listLoading = true
                let res = await getRiskEventList(this.listQuery)
                if(res.data.code === '200'){
                    if(res.data.data.length === 0 && res.data.count > 0){
                        this.listQuery.pageIndex = 1
                        await this.getData()
                    }else{
                        this.recordTotal = res.data.count
                        this.riskEventData = res.data.data
                    }
                }else{
                    this.$message({
                        message:res.data.message,
                        type:'warning'
                    })
                }
                this.listLoading = false
            },
            async getData(){
                this.listLoading = true
                let res = await getRiskEventList(this.listQuery)
                if(res.data.code === '200'){
                    this.recordTotal = res.data.count
                    this.riskEventData = res.data.data
                }else{
                    this.$message({
                        message:res.data.message,
                        type:'warning'
                    })
                }
                this.listLoading = false
            },
            async getAnalyseUnitData(){
                let res = await getAllSafetyRiskAnalyseUnitList()
                if(res.data.code === '200'){
                    this.analyseUnitList = JSON.parse(JSON.stringify(res.data.data))
                }else{
                    this.$message({
                        message:res.data.message,
                        type:'warning'
                    })
                }
            },
            showRiskEvent(value,type){
                this.riskEventVisible = true
                this.$nextTick(() =>{
                    this.$refs["riskEventForm"].clearValidate()
                })
                if(type === '新增'){
                    this.title = '新增'
                    this.riskEventForm = {
                        riskUnitId: "",
                        riskEventName: "",
                    }
                }else{
                    this.title = '修改'
                    for( let key in this.riskEventForm){
                        this.riskEventForm[key] = JSON.parse(JSON.stringify(value))[key]
                    }
                    this.riskEventForm.id = JSON.parse(JSON.stringify(value)).id
                }
            },
            submitRiskEvent(){
                this.$refs["riskEventForm"].validate((valid) =>{
                    if(valid){
                        if(this.title === '新增'){
                            addRiskEvent(this.riskEventForm).then((res)=>{
                                if(res.data.code === '200'){
                                    this.riskEventVisible = false
                                    this.getRiskEventData()
                                    this.$notify({
                                        type:'success',
                                        duration:2000,
                                        message:'新增成功',
                                        title:'成功'
                                    })
                                }else{
                                    this.$message({
                                        type:'warning',
                                        message:res.data.message
                                    })
                                }
                            })
                        }else{
                            updateRiskEvent(this.riskEventForm).then((res)=>{
                                if(res.data.code === '200'){
                                    this.riskEventVisible = false
                                    this.getRiskEventData()
                                    this.$notify({
                                        type:'success',
                                        duration:2000,
                                        title:'成功',
                                        message:'编辑成功'
                                    })
                                }else{
                                    this.$message({
                                        type:'warning',
                                        message:res.data.message
                                    })
                                }
                            })
                        }
                    }else{
                        this.$message({
                            message:'请完善基本信息',
                            type:'warning'
                        })
                    }
                })
            },
            deleteById(val){
                this.$confirm('删除此条信息,是否继续','提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    type:'warning',
                }).then(()=> {
                    deleteRiskEvent({id:val.id}).then( (res)=>{
                        if(res.data.code === '200'){
                            this.getRiskEventData()
                            this.$notify({
                                title:'成功',
                                message:'删除成功',
                                type:'success',
                                duration:2000,
                            })
                        }else{
                            this.$message({
                                type:'warning',
                                message:res.data.message
                            })
                        }
                    })
                })
            },
 
            viewHandle() {
                window.open(exampleFile, '_blank')
            },
 
            showImportDialog(){
                this.importDialogFormVisible = true
            },
 
            importToTable(){
                const formData = new FormData()
                const files = this.$refs['importLabInput'].files
                if (files && files.length > 0) {
                    formData.append('file', files[0])
                }
                importRiskEvent(formData).then((response) => {
                    const res = response.data
                    if (res.code == 200) {
                        this.importDialogFormVisible = false
                        this.$message({
                            message: '导入成功',
                            type: 'success'
                        })
                        this.getRiskEventData()
                    } else {
                        parseError({ error: res.message, vm: this })
                    }
                }).catch((error) => {
                    parseError({ error: error, vm: this })
                })
            },
 
            exportToExcel() {
                exportRiskEvent(this.listQuery.filter).then(res=>{
                    if (res.data.code === '200') {
                        if(res.data.result === null ||res.data.result === [] || res.data.result.length === 0){
                            this.$message({
                                type:'warning',
                                message:'无数据可导出'
                            })
                        }
                        else{
                            let allData = res.data.result
                            import('@/vendor/Export2Excel').then((excel) => {
                                const tHeader = [
                                    '安全风险分析单元名称',
                                    '安全风险事件名称',
                                ]
                                const filterVal = [
                                    'riskUnitName',
                                    'riskEventName',
                                ]
                                const data = this.formatJson(filterVal, allData)
                                excel.export_json_to_excel({
                                    header: tHeader,
                                    data,
                                    filename: '安全风险事件数据'
                                })
                            })
 
                        }
                    }
                })
            },
 
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => v[j]))
            },
 
            refreshHandle(){
                this.getRiskEventData()
            },
            handleSizeChange(val){
                this.listQuery.pageSize = val
                this.getRiskEventData()
            },
            handleCurrentChange(val){
                this.listQuery.pageIndex = val
                this.getRiskEventData()
            },
        }
    }
</script>
<style scoped>
    .basic_search{
        display:inline-block;
        padding-bottom: 10px;
    }
    .analyseUnit_input{
        width:200px;
    }
    .analyseUnit_box{
        width:90%;
    }
</style>