Переглянути джерело

feature:公海添加导入功能

sunxinyuan 1 рік тому
батько
коміт
9171ce46a2
2 змінених файлів з 89 додано та 0 видалено
  1. 4 0
      src/api/customer/index.js
  2. 85 0
      src/views/customer/openSea.vue

+ 4 - 0
src/api/customer/index.js

@@ -102,4 +102,8 @@ export default {
   bidList(query) {
     return micro_request.postRequest(basePath, 'CustCustomerBidRecord', 'List', query)
   },
+  // 导入
+  import(query) {
+    return micro_request.postRequest(basePath, 'Customer', 'Import', query)
+  },
 }

+ 85 - 0
src/views/customer/openSea.vue

@@ -94,6 +94,21 @@
         <el-button v-permissions="['cust:open:receive']" icon="el-icon-plus" type="primary" @click="handleReceive">
           领取
         </el-button>
+        <el-upload
+          ref="uploadRef"
+          :accept="fileSettings.types"
+          action="#"
+          :before-upload="
+            (file) => {
+              return beforeUpload(file)
+            }
+          "
+          :file-list="fileList"
+          :http-request="uploadRequest"
+          :show-file-list="false"
+          style="margin: 0 10px 10px 0 !important">
+          <el-button icon="el-icon-upload2" :loading="importLoading" type="primary">导入</el-button>
+        </el-upload>
       </vab-query-form-left-panel>
       <vab-query-form-right-panel :span="12">
         <!--        <el-button icon="el-icon-download" @click="exportData" />-->
@@ -210,6 +225,8 @@
   import Pick from './components/Pick'
   import TableTool from '@/components/table/TableTool'
   import downloadFileByByte from '@/utils/base64ToFile'
+  import axios from 'axios'
+  import asyncUploadFile from '@/utils/uploadajax'
 
   export default {
     name: 'OpenSeaCustomer',
@@ -333,6 +350,15 @@
             disableCheck: false,
           },
         ],
+        fileList: [],
+        fileSettings: {
+          // 文件配置信息
+          fileSize: 52428800,
+          fileTypes: '.xlsx',
+          pictureSize: 52428800,
+          types: '.xlsx',
+        },
+        importLoading: false,
       }
     },
     watch: {
@@ -409,6 +435,7 @@
         }
         this.fetchData()
       },
+
       handleSizeChange(val) {
         this.queryForm.pageSize = val
         this.fetchData()
@@ -504,6 +531,64 @@
         //   })
         //   .catch((err) => console.log(err))
       },
+      beforeUpload(file) {
+        let flag1 = file.size < this.fileSettings.fileSize
+        if (!flag1) {
+          this.$message.warning('文件过大,请重新选择!')
+          return false
+        }
+        let flag2 = this.fileSettings.fileTypes.split(',').includes('.' + file.name.split('.').pop())
+        if (!flag2) {
+          this.$message.warning('文件类型不符合,请重新选择!')
+          return false
+        }
+        return true
+      },
+      uploadRequest(option) {
+        this.importLoading = true
+        let _this = this
+        let url = process.env.VUE_APP_UPLOAD_WEED
+        axios
+          .post(url)
+          .then((res) => {
+            if (res.data && res.data.fid && res.data.fid !== '') {
+              option.action = `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}`
+              let fileUrl = `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}` // 资料存储url
+              asyncUploadFile(option).then(async () => {
+                console.log('fileUrl', fileUrl)
+                const params = {
+                  excelUrl: fileUrl,
+                }
+                const [err, res] = await to(api.import(params))
+                if (err) {
+                  this.importLoading = false
+                  return
+                }
+                if (res.code == 200) {
+                  this.importLoading = false
+                  _this.fetchData()
+                  _this.$message({
+                    type: 'success',
+                    message: '操作成功',
+                  })
+                }
+              })
+            } else {
+              this.importLoading = false
+              _this.$message({
+                type: 'warning',
+                message: '未上传成功!请刷新界面重新上传!',
+              })
+            }
+          })
+          .catch(function () {
+            this.importLoading = false
+            _this.$message({
+              type: 'warning',
+              message: '未上传成功!请重新上传!',
+            })
+          })
+      },
     },
   }
 </script>