From c562fa2e66f4972ae23fa57ef7412da6e18991ed Mon Sep 17 00:00:00 2001
From: lyfO_o <764716047@qq.com>
Date: 星期二, 12 七月 2022 14:31:51 +0800
Subject: [PATCH] Merge remote-tracking branch 'remotes/origin/shf' into master

---
 src/views/doublePreventAction/riskLevelManage/event/index.vue |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 112 insertions(+), 4 deletions(-)

diff --git a/src/views/doublePreventAction/riskLevelManage/event/index.vue b/src/views/doublePreventAction/riskLevelManage/event/index.vue
index a8bc8ca..4183aa5 100644
--- a/src/views/doublePreventAction/riskLevelManage/event/index.vue
+++ b/src/views/doublePreventAction/riskLevelManage/event/index.vue
@@ -2,12 +2,19 @@
     <div class="app-container">
         <div class="filter-container">
             <div class="basic_search">
-                <span>单位名称:</span>
-                <el-input v-model="listQuery.filter.riskUintName" style="width:200px">
+                <span>事件名称:</span>
+                <el-input v-model="listQuery.filter.riskEventName" style="width:200px">
+                </el-input>
+            </div>
+            <div class="basic_search">
+                <span>单元名称:</span>
+                <el-input v-model="listQuery.filter.riskUnitName" 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
@@ -77,6 +84,32 @@
                 <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>
 
@@ -84,7 +117,13 @@
     import { mapGetters } from 'vuex'
     import { computePageCount } from '@/utils'
     import { addRiskEvent, deleteRiskEvent, getRiskEventList, updateRiskEvent } from '@/api/riskLevelManage'
-    import {getAnalyseUnitList} from "../../../../api/riskLevelManage";
+    const exampleFile = require('@/assets/example/riskEvent.xlsx')
+    import {
+        exportRiskEvent,
+        getAnalyseUnitList,
+        importRiskEvent
+    } from "../../../../api/riskLevelManage";
+    import {parseError} from "../../../../utils/messageDialog";
     export default {
         name: 'index',
         filters: {
@@ -114,6 +153,7 @@
                 title:'',
                 company:'',
                 code:'',
+                importDialogFormVisible:false,
                 riskEventVisible:false,
                 riskEventFormRules:{
                     riskUnitId: [{ required: true, message: '安全风险分析单元名称不能为空', trigger: 'change' }],
@@ -166,7 +206,6 @@
             async getAnalyseUnitData(){
                 let res = await getAnalyseUnitList({pageSize:1000,pageIndex:1,filter:{ riskUnitName:''}})
                 if(res.data.code === '200'){
-                    debugger
                     this.analyseUnitList = res.data.result.records
                 }else{
                     this.$message({
@@ -265,6 +304,75 @@
                     })
                 })
             },
+
+            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()
             },

--
Gitblit v1.9.2