Pārlūkot izejas kodu

商品管理模块-商品列表增加商品导入功能

sunny 5 mēneši atpakaļ
vecāks
revīzija
43b30d701f
1 mainītis faili ar 55 papildinājumiem un 0 dzēšanām
  1. 55 0
      src/views/goodsManage/goodsList.vue

+ 55 - 0
src/views/goodsManage/goodsList.vue

@@ -37,6 +37,7 @@
                 @click="handleQuery">查找</el-button>
                 <el-button class="filter-item" icon="el-icon-refresh" @click="resetQuery">重置</el-button>
             <el-button class="filter-item" type="primary" @click="handleAdd" icon="el-icon-plus">添加</el-button>
+            <el-button class="filter-item" type="info" @click="handleImport" icon="el-icon-upload2">导入</el-button>
             <el-button class="filter-item" v-waves icon="el-icon-download" @click="handleDownLoad">导出</el-button>
         </div>
 
@@ -227,6 +228,21 @@
                 <el-button v-else type="primary" @click="updateData">确定</el-button>
             </div>
         </el-dialog>
+        <!-- 商品导入对话框 -->
+        <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
+        <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleProductTemplate" :auto-upload="false" drag>
+            <i class="el-icon-upload"></i>
+            <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+            <div class="el-upload__tip text-center" slot="tip">
+            <span>仅允许导入xls、xlsx格式文件。</span>
+            <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
+            </div>
+        </el-upload>
+        <div slot="footer" class="dialog-footer">
+            <el-button type="primary" @click="submitFileForm">确 定</el-button>
+            <el-button @click="upload.open = false">取 消</el-button>
+        </div>
+        </el-dialog>
 
     </div>
 </template>
@@ -234,6 +250,7 @@
 import { createItem, updateItem, goodsList, removeItem } from "@/api/goodsManage";
 import { listDept } from "@/api/goodsTypeList";
 import { listBrand } from '@/api/brand';
+import { getToken } from '@/utils/auth' // getToken from cookie
 import Treeselect from "@riophae/vue-treeselect";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
 import { dataTypeList } from "@/api/public";
@@ -245,6 +262,19 @@ export default {
     directives: { waves },
     data() {
         return {
+            // 商品导入参数
+            upload: {
+                // 是否显示弹出层(商品导入)
+                open: false,
+                // 弹出层标题(商品导入)
+                title: "",
+                // 是否禁用上传
+                isUploading: false,
+                // 设置上传的请求头部
+                headers: { Authorization: "Bearer " + getToken() },
+                // 上传的地址
+                url: process.env.BASE_API + "/product/import"
+            },
             tea_type:[],
             tea_level:[],
             tea_series:[],
@@ -363,6 +393,31 @@ export default {
         this.getList();
     },
     methods: {
+        /** 导入按钮操作 */
+    handleImport() {
+      this.upload.title = "商品导入";
+      this.upload.open = true;
+    },
+    /** 下载模板操作 */
+    importTemplate() {
+        window.location.href = process.env.BASE_API + '/product/down/productTemplate';
+    },
+    // 文件上传中处理
+    handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+    },
+    // 文件上传成功处理
+    handleProductTemplate(response, file, fileList) {
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.data + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
+      this.getList();
+    },
+    // 提交上传文件
+    submitFileForm() {
+      this.$refs.upload.submit();
+    },
         handleDownLoad(){
             window.location.href = process.env.BASE_API + '/product/export?productName=' + this.listQuery.productName + '&productShortForm=' + this.listQuery.productShortForm;
         },