Sfoglia il codice sorgente

物料基本分类导入,价格目录更改数据字典

黄梓星 1 anno fa
parent
commit
145e6e5331

+ 9 - 0
src/api/classify/basic.js

@@ -40,3 +40,12 @@ export function edit(data) {
     data: data
   })
 }
+// 物料基本分类模板下载
+export function downLoadClassify(data) {
+  return request({
+    url: `/system/classify/download`,
+    method: 'post',
+    data: data,
+    responseType: 'blob'
+  })
+}

+ 103 - 2
src/views/material/classify/index.vue

@@ -5,6 +5,8 @@
 
       <el-row :gutter="10" class="mb10">
         <div>
+          <el-button type="primary" size="mini" @click="mbDownload">模板下载</el-button>
+          <el-button type="primary" size="mini" @click="importMb">导入</el-button>
           <el-button type="primary" size="mini" plain @click="addClassify">新增</el-button>
           <el-button type="primary" size="mini" plain @click="editClassify">修改</el-button>
           <el-button type="primary" size="mini" plain @click="refreshData">{{refreshName ? '全部分类': '过滤停用'}}</el-button>
@@ -140,10 +142,10 @@
             <el-row :gutter="20">
               <el-col :span="24">
                 <el-form-item v-if="!disable">
-                  <el-button type="primary" @click="submitForm('ruleForm')"
+                  <el-button size="mini" type="primary" @click="submitForm('ruleForm')"
                     >保存</el-button
                   >
-                  <el-button @click="resetForm('ruleForm')">取消</el-button>
+                  <el-button size="mini" @click="resetForm('ruleForm')">取消</el-button>
                 </el-form-item>
               </el-col>
             </el-row>
@@ -151,22 +153,71 @@
         </el-col>
       </el-row>
     </el-card>
+
+    <!-- 导入对话框 -->
+    <el-dialog title="数据导入" :visible.sync="upload.open" width="400px">
+      <el-upload
+      ref="upload"
+      :limit="1"
+      accept=".xlsx, .xls"
+      :headers="upload.headers"
+      :action="upload.url + '?updateSupport=' + upload.updateSupport"
+      :disabled="upload.isUploading"
+      :on-progress="handleFileUploadProgress"
+      :on-success="handleFileSuccess"
+      :on-error="errorFile"
+      :auto-upload="false"
+      drag
+      >
+      <i class="el-icon-upload"></i>
+      <div class="el-upload__text">
+        将文件拖到此处,或
+        <em>点击上传</em>
+      </div>
+      <!-- <div class="el-upload__tip" slot="tip">
+        <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
+      </div> -->
+      <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
+      </el-upload>
+      <div slot="footer">
+      <el-button size="mini" type="primary" @click="submitFile">确 定</el-button>
+      <el-button size="mini" @click="upload.open = false">取 消</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
 <script>
+// 导入的token
+import { getToken } from "@/utils/auth";
 import {
   getTree,
   getDetail,
   add,
   delClassify,
   edit,
+  downLoadClassify,
 } from "@/api/classify/basic";
 export default {
   name: "classify",
   dicts: ["material_enable", "sys_assist_condtion"],
   data() {
     return {
+      // 导入参数
+      upload: {
+        // 是否显示弹出层(导入)
+        open: false,
+        // 弹出层标题(导入)
+        title: "数据导入",
+        // 是否禁用上传
+        isUploading: false,
+        // 是否更新已经存在的用户数据
+        updateSupport: 1,
+        // 设置上传的请求头部
+        headers: { Authorization: "Bearer " + getToken() },
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/system/classify/import"
+      },
       loading: false,
       filterText: "",
       data: [],
@@ -406,6 +457,56 @@ export default {
         this.getTreeData();
       }
     },
+    // 模板下载
+    mbDownload() {
+      this.$modal.loading("正在下载模板,请稍后...");
+      downLoadClassify({}).then(res => {
+        this.$modal.closeLoading();
+        const blob = new Blob([res], {
+          type: "application/vnd.ms-excel;charset=UTF-8",
+        });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
+        const downloadElement = document.createElement("a"); //创建a标签
+        const href = window.URL.createObjectURL(blob); // 创建下载的链接
+        // var temp = res.headers["content-disposition"]; 
+        // var fileName = decodeURIComponent(temp.split("filename=")[1]); // 中文需要转码 (前端乱码)
+        // var name = fileName.split(";")[0]; //切割成文件名
+        downloadElement.href = href;  //下载地址
+        downloadElement.download = '物料基本分类模板'+ this.parseTime(new Date().getTime()) + ".xlsx"; // 下载后文件名
+        document.body.appendChild(downloadElement);
+        downloadElement.click(); // 点击下载
+        document.body.removeChild(downloadElement); // 下载完成移除元素
+        window.URL.revokeObjectURL(href); // 释放blob对象
+        this.download.open = false
+      }).catch(err => {
+        this.$modal.closeLoading();
+      })
+    },
+    // 文件导入
+    importMb() {
+      this.upload.open = true
+    },
+    // 文件上传中处理
+    handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+      this.$modal.loading("正在导入数据,请稍后...");
+    },
+    // 文件上传成功处理
+    handleFileSuccess(response, file, fileList) {
+      this.$modal.closeLoading();
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
+      this.getTreeData();
+    },
+    errorFile(err) {
+      this.$modal.closeLoading();
+      this.$modal.notifyError("文件已变动,请重新上传");
+    },
+    // 提交上传文件
+    submitFile() {
+      this.$refs.upload.submit();
+    },
   },
 };
 </script>

+ 5 - 5
src/views/purchase/catalogue/columns.js

@@ -46,15 +46,15 @@ export default function useColumns() {
     },
     {
       item: { width: 100, key: "status", title: "有效状态" },
-      attr: { is: "el-dict-tag", dictName: "is_effective" },
+      attr: { is: "el-dict-tag", dictName: "price_invalid" },
     },
     {
       item: { width: 100, key: "enableStatus", title: "启用状态" },
-      attr: { is: "el-dict-tag", dictName: "is_effective" },
+      attr: { is: "el-dict-tag", dictName: "price_enable" },
     },
     {
       item: { width: 100, key: "materialStatus", title: "物料启用状态" },
-      attr: { is: "el-dict-tag", dictName: "is_effective" },
+      attr: { is: "el-dict-tag", dictName: "material_enable" },
     },
     {
       item: { width: 100, key: "isDistribution", title: "配送价" },
@@ -167,11 +167,11 @@ export default function useColumns() {
     },
     {
       item: { width: 100, key: "status", title: "有效状态" },
-      attr: { is: "el-select", dictName: "is_effective" },
+      attr: { is: "el-select", dictName: "price_invalid" },
     },
     {
       item: { width: 100, key: "enableStatus", title: "启用状态", span: 4 },
-      attr: { is: "el-select", dictName: "is_effective" },
+      attr: { is: "el-select", dictName: "price_enable" },
     },
     {
       item: { width: 100, key: "createTime", title: "价格日期", span: 8 },

+ 3 - 3
src/views/purchase/catalogue/see/columns.js

@@ -45,15 +45,15 @@ export default function useColumns() {
     },
     {
       item: { width:100,key: "status", title: "有效状态" },
-      attr: { is: "el-dict-tag", dictName: "is_effective" },
+      attr: { is: "el-dict-tag", dictName: "price_invalid" },
     },
     {
       item: { width:100,key: "enableStatus", title: "启用状态" },
-      attr: { is: "el-dict-tag", dictName: "is_effective" },
+      attr: { is: "el-dict-tag", dictName: "price_enable" },
     },
     {
       item: { width:100,key: "materialStatus", title: "物料启用状态" },
-      attr: { is: "el-dict-tag", dictName: "is_effective" },
+      attr: { is: "el-dict-tag", dictName: "material_enable" },
     },
     {
       item: { width:100,key: "isDistribution", title: "配送价" },