From e6df5a867a614e257558f0ce549c1083ed22d5bc Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期二, 06 八月 2024 17:46:23 +0800
Subject: [PATCH] 点位导入导出

---
 src/views/system/point/index.vue |   78 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/src/views/system/point/index.vue b/src/views/system/point/index.vue
index 903556a..a83c625 100644
--- a/src/views/system/point/index.vue
+++ b/src/views/system/point/index.vue
@@ -29,8 +29,36 @@
           v-hasPermi="['point:remove']">鍒犻櫎</el-button>
       </el-col>
       <el-col :span="1.5">
-        <el-button type="warning" plain icon="el-icon-top" size="mini" @click="handleImportPoint"
-          v-hasPermi="['point:import']">瀵煎叆鐐逛綅</el-button>
+        <el-button type="primary" plain icon="el-icon-bottom" v-loading="download" size="mini" @click="handleExport"
+                   v-hasPermi="['point:export']">瀵煎嚭鐐逛綅</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-popover>
+          <div>
+            <el-select v-model="importUnitId" size="small" placeholder="璐熻矗鍗曚綅">
+              <el-option v-for="unit in unitList" :key="unit.id" :label="unit.value" :value="unit.id"></el-option>
+            </el-select>
+          </div>
+          <div>
+            <el-upload
+              ref="upload"
+              class="upload-demo"
+              drag
+              :action="importUrl"
+              :file-list="fileList"
+              :before-upload="beforeUpload"
+              >
+              <i class="el-icon-upload"></i>
+              <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div>
+              <div class="el-upload__tip" slot="tip">鍙兘涓婁紶xls/xlsx鏂囦欢</div>
+            </el-upload>
+          </div>
+          <div>
+            <el-button type="primary" size="small" v-model="upload" :disabled="! importUnitId || ! importFile"  @click="handleImport" style="width: 100%; margin-top: 5px"
+                       v-hasPermi="['point:import']">瀵煎叆</el-button>
+          </div>
+          <el-button type="primary" size="mini" plain icon="el-icon-top" slot="reference">瀵煎叆鐐逛綅</el-button>
+        </el-popover>
       </el-col>
       <el-col :span="1.5">
         <el-button type="danger" plain icon="el-icon-receiving" size="mini" @click="handleEditBatch"
@@ -156,7 +184,7 @@
 </template>
 
 <script>
-import { listPoint, getPoint, delPoint, addPoint, batchEdit, updatePoint } from "@/api/platform/point";
+import { listPoint, getPoint, delPoint, addPoint, batchEdit, updatePoint, exportData, importData } from "@/api/platform/point";
 import { unitSelect } from "@/api/platform/unit";
 import { getCascader } from '@/api/platform/region'
 import { cascader } from '@/api/system/dept'
@@ -166,6 +194,12 @@
   dicts: ['point_tag'],
   data() {
     return {
+      fileList: [],
+      importFile: null,
+      importUrl: '',
+      importUnitId: null,
+      download: false,
+      upload: false,
       deptOptions: [],
       // 鎵归噺淇敼琛ㄥ崟
       batchEditForm: {
@@ -240,9 +274,39 @@
     this.getDeptCascader();
   },
   methods: {
+    beforeUpload(file) {
+      this.importFile = file
+      this.fileList = [file]
+      return false
+    },
     // 鐐逛綅瀵煎叆
-    handleImportPoint() {
+    handleImport() {
+      this.upload =true;
+      let formData = new FormData()
+      formData.append("file", this.importFile)
+      importData(formData, this.importUnitId).then(res => {
+        this.$message.success("瀵煎叆鎴愬姛")
+        this.upload = false
+      })
+    },
+    // 鐐逛綅瀵煎嚭
+    handleExport() {
+      this.download = true
+      exportData(this.queryParams).then(res => {
+        // 灏嗕簩杩涘埗鏁版嵁杞崲涓� Blob 瀵硅薄
+        let blob = new Blob([res], { type: 'application/octet-stream' });
 
+        // 鍒涘缓涓嬭浇閾炬帴
+        let downloadLink = document.createElement('a');
+        downloadLink.href = URL.createObjectURL(blob);
+        downloadLink.setAttribute('download', "鐐逛綅鏇存崲杩愮淮鍗曚綅.xlsx"); // 璁剧疆涓嬭浇鏂囦欢鐨勬枃浠跺悕
+        downloadLink.style.display = 'none';
+        // 娣诲姞鍒伴〉闈㈠苟瑙﹀彂涓嬭浇
+        document.body.appendChild(downloadLink);
+        downloadLink.click();
+        document.body.removeChild(downloadLink);
+        this.download = false
+      })
     },
     cos(value) {
       console.log(value)
@@ -394,12 +458,6 @@
       }).catch(() => {
       });
     },
-    /** 瀵煎嚭鎸夐挳鎿嶄綔 */
-    handleExport() {
-      this.download('x/point/export', {
-        ...this.queryParams
-      }, `point_${new Date().getTime()}.xlsx`)
-    }
   }
 };
 </script>

--
Gitblit v1.8.0