Ver Fonte

bugfix 导入

yuwandanmian há 1 ano atrás
pai
commit
5a7abfb41b

+ 9 - 0
src/api/excel.js

@@ -29,3 +29,12 @@ export function illnessExport(data) {
     data: data
   })
 }
+
+// 疾病库导入
+export function illnessImport(data) {
+  return request_blob({
+    url: `/disease/diseaseImport`,
+    method: 'post',
+    data: data
+  })
+}

+ 30 - 22
src/views/knowledge/illness/components/TableBox.vue

@@ -1,7 +1,16 @@
 <template>
   <div class="app-container">
     <div class="btn-box">
-      <el-button type="primary" icon="el-icon-upload" @click="onExcelDownload">导入</el-button>
+      <el-upload
+        class="upload-btn"
+        :multiple="false"
+        :limit="1"
+        :show-file-list="false"
+        action="#"
+        :before-upload="beforeUpload"
+      >
+        <el-button type="primary" size="small" icon="el-icon-upload">导入</el-button>
+      </el-upload>
       <el-button type="primary" icon="el-icon-download" @click="onExport">导出</el-button>
       <el-button type="primary" plain icon="el-icon-download" @click="onTemplateExport">模板导出</el-button>
     </div>
@@ -153,7 +162,7 @@
 
 <script>
 import { illnessDelete } from '@/api/knowledge'
-import { illnessTemplateExport, illnessExport } from '@/api/excel'
+import { illnessTemplateExport, illnessImport } from '@/api/excel'
 
 export default {
   props: {
@@ -176,9 +185,20 @@ export default {
       }
     }
   },
+  computed: {
+    actionUrl() {
+      return `${process.env.VUE_APP_BASE_API}/disease/diseaseImport`
+    }
+  },
   methods: {
-    onExcelDownload() {
-      this.$emit('download')
+    beforeUpload(file) {
+      console.log(file, '导入')
+      illnessImport({ file }).then(res => {
+        if (res.data.c === 0) {
+          this.$emit('refresh')
+          this.$message.success('成功')
+        }
+      })
     },
     // 删除
     onDelConfirm(row) {
@@ -203,7 +223,7 @@ export default {
       illnessTemplateExport().then(res => {
         const content = res.data // 后台返回二进制数据
         const blob = new Blob([content])
-        const fileName = `疾病库模板.csv`
+        const fileName = `疾病库模板.xlsx`
         if ('download' in document.createElement('a')) { // 非IE下载
           const elink = document.createElement('a')
           elink.download = fileName
@@ -220,23 +240,7 @@ export default {
     },
     // 模板导出
     onExport() {
-      illnessExport().then(res => {
-        const content = res.data // 后台返回二进制数据
-        const blob = new Blob([content])
-        const fileName = `疾病库.csv`
-        if ('download' in document.createElement('a')) { // 非IE下载
-          const elink = document.createElement('a')
-          elink.download = fileName
-          elink.style.display = 'none'
-          elink.href = URL.createObjectURL(blob)
-          document.body.appendChild(elink)
-          elink.click()
-          URL.revokeObjectURL(elink.href) // 释放URL 对象
-          document.body.removeChild(elink)
-        } else { // IE10+下载
-          navigator.msSaveBlob(blob, fileName)
-        }
-      })
+      this.$emit('export')
     }
   }
 }
@@ -247,4 +251,8 @@ export default {
   text-align: right;
   margin-bottom: 15px;
 }
+.upload-btn {
+  display: inline-block;
+  margin-right: 10px;
+}
 </style>

+ 104 - 31
src/views/knowledge/illness/index.vue

@@ -1,7 +1,22 @@
 <template>
   <div>
-    <SearchBoxVue :data="searchData" :codes="tableShowCode" @search="handleSearch" @reset="handleReset" @codesChange="handleCodesChange" @create="handleCreate" />
-    <TableBoxVue :loading="loading" :data="tableData" :codes="tableShowCode" style="margin-top: -40px;" @download="handleDownLoad" @edit="handleEdit" @refresh="handleRefresh" />
+    <SearchBoxVue
+      :data="searchData"
+      :codes="tableShowCode"
+      @search="handleSearch"
+      @reset="handleReset"
+      @codesChange="handleCodesChange"
+      @create="handleCreate"
+    />
+    <TableBoxVue
+      :loading="loading"
+      :data="tableData"
+      :codes="tableShowCode"
+      style="margin-top: -40px"
+      @export="handleExport"
+      @edit="handleEdit"
+      @refresh="handleRefresh"
+    />
     <pagination
       :auto-scroll="false"
       :total="paginationData.total"
@@ -10,14 +25,18 @@
       @pagination="handlePagination"
     />
     <!-- 新建、编辑 -->
-    <CreateDaialogVue v-if="createData.bSwitch" :data="createData" @refresh="handleRefresh" />
+    <CreateDaialogVue
+      v-if="createData.bSwitch"
+      :data="createData"
+      @refresh="handleRefresh"
+    />
   </div>
 </template>
 
 <script>
 import SearchBoxVue from './components/SearchBox.vue'
 import TableBoxVue from './components/TableBox.vue'
-import { userSearchLogExport } from '@/api/excel'
+import { illnessExport } from '@/api/excel'
 import { illnessList } from '@/api/knowledge'
 import CreateDaialogVue from './components/CreateDaialog.vue'
 import { dateFormat } from '@/filters/index'
@@ -143,20 +162,31 @@ export default {
         page,
         page_size
       }
-      params.createStartTime = createStartTime ? dateFormat(createStartTime, 'YYYYMMDD') : ''
-      params.createEndTime = createEndTime ? dateFormat(createEndTime, 'YYYYMMDD') : ''
-      params.updateStartTime = updateStartTime ? dateFormat(updateStartTime, 'YYYYMMDD') : ''
-      params.updateEndTime = updateEndTime ? dateFormat(updateEndTime, 'YYYYMMDD') : ''
+      params.createStartTime = createStartTime
+        ? dateFormat(createStartTime, 'YYYYMMDD')
+        : ''
+      params.createEndTime = createEndTime
+        ? dateFormat(createEndTime, 'YYYYMMDD')
+        : ''
+      params.updateStartTime = updateStartTime
+        ? dateFormat(updateStartTime, 'YYYYMMDD')
+        : ''
+      params.updateEndTime = updateEndTime
+        ? dateFormat(updateEndTime, 'YYYYMMDD')
+        : ''
       this.loading = true
-      illnessList(params).then(res => {
-        const { p } = res
-        this.paginationData.total = p.count
-        this.tableData = p.list
-      }).catch(error => {
-        console.log(error)
-      }).finally(() => {
-        this.loading = false
-      })
+      illnessList(params)
+        .then((res) => {
+          const { p } = res
+          this.paginationData.total = p.count
+          this.tableData = p.list
+        })
+        .catch((error) => {
+          console.log(error)
+        })
+        .finally(() => {
+          this.loading = false
+        })
     },
     // 分页
     handlePagination(param) {
@@ -195,22 +225,65 @@ export default {
       }
     },
     // 导出
-    handleDownLoad() {
-      const { name, dep_id, time, keyword } = this.searchData
+    handleExport() {
+      const {
+        FLAG,
+        KSMC,
+        JBMC,
+        BM,
+        JBBM,
+        JBZD,
+        ZZ,
+        TZ,
+        YP,
+        ZL,
+        JC,
+        JJ,
+        BFZ,
+        CKWX,
+        createStartTime,
+        createEndTime,
+        updateStartTime,
+        updateEndTime,
+        SSMC,
+        SSBM
+      } = this.searchData
       const params = {
-        name,
-        dep_id,
-        keyword
-      }
-      if (time && time.length) {
-        params.start_time = time[0]
-        params.end_time = time[1]
+        FLAG,
+        KSMC,
+        JBMC,
+        BM,
+        JBBM,
+        JBZD,
+        ZZ,
+        TZ,
+        YP,
+        ZL,
+        JC,
+        JJ,
+        BFZ,
+        CKWX,
+        SSMC,
+        SSBM
       }
-      userSearchLogExport(params).then(res => {
+      params.createStartTime = createStartTime
+        ? dateFormat(createStartTime, 'YYYYMMDD')
+        : ''
+      params.createEndTime = createEndTime
+        ? dateFormat(createEndTime, 'YYYYMMDD')
+        : ''
+      params.updateStartTime = updateStartTime
+        ? dateFormat(updateStartTime, 'YYYYMMDD')
+        : ''
+      params.updateEndTime = updateEndTime
+        ? dateFormat(updateEndTime, 'YYYYMMDD')
+        : ''
+      illnessExport(params).then((res) => {
         const content = res.data // 后台返回二进制数据
         const blob = new Blob([content])
-        const fileName = `科研探索日志.csv`
-        if ('download' in document.createElement('a')) { // 非IE下载
+        const fileName = `疾病库.csv`
+        if ('download' in document.createElement('a')) {
+          // 非IE下载
           const elink = document.createElement('a')
           elink.download = fileName
           elink.style.display = 'none'
@@ -219,7 +292,8 @@ export default {
           elink.click()
           URL.revokeObjectURL(elink.href) // 释放URL 对象
           document.body.removeChild(elink)
-        } else { // IE10+下载
+        } else {
+          // IE10+下载
           navigator.msSaveBlob(blob, fileName)
         }
       })
@@ -242,5 +316,4 @@ export default {
 </script>
 
 <style lang="scss" scoped>
-
 </style>