Browse Source

供应商添加商品暂存

jiandexin1 1 year ago
parent
commit
6f830bac85
1 changed files with 96 additions and 4 deletions
  1. 96 4
      src/views/store/storegoods/index.vue

+ 96 - 4
src/views/store/storegoods/index.vue

@@ -24,8 +24,11 @@
 
 
       <template slot="isSale" slot-scope="scope" >
-        <el-tag v-if="scope.row.$isSale === '上架'" type="success">{{scope.row.$isSale}}</el-tag>
-        <el-tag v-if="scope.row.$isSale === '下架'" type="danger">{{scope.row.$isSale}}</el-tag>
+        <el-button type="success"
+                   icon="el-icon-upload"
+                   size="small"
+                   plain
+                   @click.stop="batchImportHandle()">批量导入</el-button>
       </template>
 
       <template slot="auditStatus" slot-scope="scope" >
@@ -55,6 +58,50 @@
 
     </avue-crud>
 
+    <el-dialog title="商品批量导入" @close="refreshChange"
+               append-to-body
+               :visible.sync="batchImportBox"
+               :before-close="handleClose"
+               width="600px">
+      <el-form :model="auditForm" label-width="80px">
+        <el-form-item label="商品文件:">
+          <el-upload
+              ref="upload"
+              class="upload-demo"
+              accept=".xls, .xlsx"
+              :action="importUrl"
+              :before-upload="beforeAvatarUpload"
+              :on-success="handleImportSuccess"
+              :on-error="handleImportError"
+              :limit="1"
+              :file-list="fileList"
+              :data="fileDa"
+              :headers="headers"
+              :auto-upload="false">
+            <el-button size="small" type="primary">选择文件</el-button>
+            <span style="color: #f54646; margin-left: 10px; padding-bottom: 30px" @click="downloadFile">点击下载文件模板,请勿修改模板表头</span>
+
+            <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
+          </el-upload>
+        </el-form-item>
+        <el-form-item label="供应商:">
+          <el-select v-model="fileDa.storeId" placeholder="请选择供应商">
+            <el-option
+                v-for="item in storeList"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id">
+            </el-option>
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <span style="color: #f54646" v-if="errorMsg">上传失败原因:{{errorMsg}}</span>
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="handleClose">取 消</el-button>
+        <el-button type="primary" @click="batchImport()">确 定</el-button>
+      </div>
+    </el-dialog>
+
     <el-dialog title="商品审核" @close="refreshChange"
                append-to-body
                :visible.sync="auditBox"
@@ -89,6 +136,7 @@
   import {getList, getDetail, add, update, remove, modifyState, audit, copy} from "@/api/mall/storegoodsinfo";
   import {mapGetters} from "vuex";
   import {getByParentId} from "../../../api/mall/categoryinfo";
+  import {getList as getStoreList} from "@/api/mall/store";
 
   export default {
 
@@ -101,6 +149,8 @@
         }
       }
       return {
+        batchImportBox: false,
+        fileList: [],
         option:  {
           height: 'auto',
           calcHeight: 30,
@@ -662,13 +712,55 @@
         }
       },
 
+      batchImportHandle() {
+        this.batchImportBox = true;
+        getStoreList(1, 1000, {state:1,auditState:1}).then(res => {
+          console.log(res.data)
+          this.storeList = res.data.data.records;
+        });
+      },
+
+      batchImport() {
+        if (!this.fileDa.storeId) {
+          this.$message.warning("请选择供应商");
+          return;
+        }
+        if (this.$refs.upload.uploadFiles.length < 1) {
+          this.$message.warning("请选择需要导入的文件");
+          return;
+        }
+        this.$refs.upload.submit();
+      },
+      handleImportSuccess(res) {
+        this.$message({
+          type: "success",
+          message: "导入成功!"
+        });
+        this.handleClose();
+      },
+      handleImportError(err) {
+        this.$message({
+          type: "error",
+          message: "导入失败,请查看失败原因!"
+        });
+        let msg = err.toString();
+        msg = msg.substring(7, msg.length);
+        this.errorMsg = JSON.parse(msg).msg;
+      },
+      downloadFile() {
+        window.location.href="http://www.gzzzyd.com/groupon/template.xlsx"
+      },
+
       handleClose() {
+        this.errorMsg = '';
+        this.fileList = [];
         this.categoryIdArr = [];
         this.auditBox = false;
+        this.batchImportBox = false;
         this.auditForm = {
           auditStatus: '',
-              id: '',
-              remark: ''
+          id: '',
+          remark: ''
         };
       },
       modifyGoodsStateBatch(state) {