Browse Source

企业分类导入功能

littleblue55 1 month ago
parent
commit
3bd538c264
2 changed files with 181 additions and 52 deletions
  1. 9 9
      src/api/etype/etype.js
  2. 172 43
      src/views/etype/etype/index.vue

+ 9 - 9
src/api/etype/etype.js

@@ -1,6 +1,6 @@
 import request from '@/utils/request'
 
-// 查询etype列表
+// 查询企业分类列表
 export function listEtype(query) {
   return request({
     url: '/etype/etype/list',
@@ -9,15 +9,15 @@ export function listEtype(query) {
   })
 }
 
-// 查询etype详细
-export function getEtype(number) {
+// 查询企业分类详细
+export function getEtype(id) {
   return request({
-    url: '/etype/etype/' + number,
+    url: '/etype/etype/' + id,
     method: 'get'
   })
 }
 
-// 新增etype
+// 新增企业分类
 export function addEtype(data) {
   return request({
     url: '/etype/etype',
@@ -26,7 +26,7 @@ export function addEtype(data) {
   })
 }
 
-// 修改etype
+// 修改企业分类
 export function updateEtype(data) {
   return request({
     url: '/etype/etype',
@@ -35,10 +35,10 @@ export function updateEtype(data) {
   })
 }
 
-// 删除etype
-export function delEtype(number) {
+// 删除企业分类
+export function delEtype(id) {
   return request({
-    url: '/etype/etype/' + number,
+    url: '/etype/etype/' + id,
     method: 'delete'
   })
 }

+ 172 - 43
src/views/etype/etype/index.vue

@@ -1,6 +1,13 @@
 <template>
   <div class="app-container">
-    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
+    <el-form
+      :model="queryParams"
+      ref="queryForm"
+      size="small"
+      :inline="true"
+      v-show="showSearch"
+      label-width="68px"
+    >
       <el-form-item label="分类编码" prop="number">
         <el-input
           v-model="queryParams.number"
@@ -18,8 +25,16 @@
         />
       </el-form-item>
       <el-form-item>
-        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
-        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
+        <el-button
+          type="primary"
+          icon="el-icon-search"
+          size="mini"
+          @click="handleQuery"
+          >搜索</el-button
+        >
+        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
+          >重置</el-button
+        >
       </el-form-item>
     </el-form>
 
@@ -32,7 +47,8 @@
           size="mini"
           @click="handleAdd"
           v-hasPermi="['etype:etype:add']"
-        >新增</el-button>
+          >新增</el-button
+        >
       </el-col>
       <el-col :span="1.5">
         <el-button
@@ -43,7 +59,8 @@
           :disabled="single"
           @click="handleUpdate"
           v-hasPermi="['etype:etype:edit']"
-        >修改</el-button>
+          >修改</el-button
+        >
       </el-col>
       <el-col :span="1.5">
         <el-button
@@ -54,7 +71,8 @@
           :disabled="multiple"
           @click="handleDelete"
           v-hasPermi="['etype:etype:remove']"
-        >删除</el-button>
+          >删除</el-button
+        >
       </el-col>
       <el-col :span="1.5">
         <el-button
@@ -64,16 +82,38 @@
           size="mini"
           @click="handleExport"
           v-hasPermi="['etype:etype:export']"
-        >导出</el-button>
+          >导出</el-button
+        >
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="info"
+          icon="el-icon-upload2"
+          size="mini"
+          @click="handleImport"
+          v-hasPermi="['etype:etype:import']"
+          >导入</el-button
+        >
       </el-col>
-      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
+      <right-toolbar
+        :showSearch.sync="showSearch"
+        @queryTable="getList"
+      ></right-toolbar>
     </el-row>
 
-    <el-table v-loading="loading" :data="etypeList" @selection-change="handleSelectionChange">
+    <el-table
+      v-loading="loading"
+      :data="etypeList"
+      @selection-change="handleSelectionChange"
+    >
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="分类编码" align="center" prop="number" />
       <el-table-column label="分类名称" align="center" prop="name" />
-      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+      <el-table-column
+        label="操作"
+        align="center"
+        class-name="small-padding fixed-width"
+      >
         <template slot-scope="scope">
           <el-button
             size="mini"
@@ -81,20 +121,22 @@
             icon="el-icon-edit"
             @click="handleUpdate(scope.row)"
             v-hasPermi="['etype:etype:edit']"
-          >修改</el-button>
+            >修改</el-button
+          >
           <el-button
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
             v-hasPermi="['etype:etype:remove']"
-          >删除</el-button>
+            >删除</el-button
+          >
         </template>
       </el-table-column>
     </el-table>
-    
+
     <pagination
-      v-show="total>0"
+      v-show="total > 0"
       :total="total"
       :page.sync="queryParams.pageNum"
       :limit.sync="queryParams.pageSize"
@@ -116,12 +158,49 @@
         <el-button @click="cancel">取 消</el-button>
       </div>
     </el-dialog>
+    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
+      <el-upload
+        ref="upload"
+        :limit="1"
+        accept=".xlsx, .xls"
+        :headers="upload.headers"
+        :action="upload.url"
+        :disabled="upload.isUploading"
+        :on-progress="handleFileUploadProgress"
+        :on-success="handleFileSuccess"
+        :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-link type="primary" style="font-size: 12px" @click="importTemplate"
+            >点击此处下载文件上传模板</el-link>
+        </div>
+        <div class="el-upload__tip" style="color: red" slot="tip">
+          提示:仅允许导入“xls”或“xlsx”格式文件!
+        </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>
 
 <script>
-import { listEtype, getEtype, delEtype, addEtype, updateEtype } from "@/api/etype/etype";
-
+import {
+  listEtype,
+  getEtype,
+  delEtype,
+  addEtype,
+  updateEtype,
+} from "@/api/etype/etype";
+import { getToken } from '@/utils/auth'
 export default {
   name: "Etype",
   data() {
@@ -149,19 +228,32 @@ export default {
         pageNum: 1,
         pageSize: 10,
         number: null,
-        name: null
+        name: null,
       },
       // 表单参数
       form: {},
       // 表单校验
       rules: {
         number: [
-          { required: true, message: "分类编码不能为空", trigger: "blur" }
+          { required: true, message: "分类编码不能为空", trigger: "blur" },
         ],
         name: [
-          { required: true, message: "分类名称不能为空", trigger: "blur" }
-        ]
-      }
+          { required: true, message: "分类名称不能为空", trigger: "blur" },
+        ],
+      },
+      upload: {
+        // 是否显示弹出层(用户导入)
+        open: false,
+        // 弹出层标题(用户导入)
+        title: "",
+        // 是否禁用上传
+        isUploading: false,
+        // 是否更新已经存在的用户数据
+        // 设置上传的请求头部
+        headers: { Authorization: "Bearer " + getToken() },
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/etype/etype/importData",
+      },
     };
   },
   created() {
@@ -171,7 +263,7 @@ export default {
     /** 查询etype列表 */
     getList() {
       this.loading = true;
-      listEtype(this.queryParams).then(response => {
+      listEtype(this.queryParams).then((response) => {
         this.etypeList = response.rows;
         this.total = response.total;
         this.loading = false;
@@ -185,8 +277,9 @@ export default {
     // 表单重置
     reset() {
       this.form = {
+        id: null,
         number: null,
-        name: null
+        name: null,
       };
       this.resetForm("form");
     },
@@ -202,9 +295,9 @@ export default {
     },
     // 多选框选中数据
     handleSelectionChange(selection) {
-      this.ids = selection.map(item => item.number)
-      this.single = selection.length!==1
-      this.multiple = !selection.length
+      this.ids = selection.map((item) => item.number);
+      this.single = selection.length !== 1;
+      this.multiple = !selection.length;
     },
     /** 新增按钮操作 */
     handleAdd() {
@@ -215,8 +308,8 @@ export default {
     /** 修改按钮操作 */
     handleUpdate(row) {
       this.reset();
-      const number = row.number || this.ids
-      getEtype(number).then(response => {
+      const number = row.number || this.ids;
+      getEtype(number).then((response) => {
         this.form = response.data;
         this.open = true;
         this.title = "修改etype";
@@ -224,16 +317,16 @@ export default {
     },
     /** 提交按钮 */
     submitForm() {
-      this.$refs["form"].validate(valid => {
+      this.$refs["form"].validate((valid) => {
         if (valid) {
-          if (this.form.number != null) {
-            updateEtype(this.form).then(response => {
+          if (this.form.id != null) {
+            updateEtype(this.form).then((response) => {
               this.$modal.msgSuccess("修改成功");
               this.open = false;
               this.getList();
             });
           } else {
-            addEtype(this.form).then(response => {
+            addEtype(this.form).then((response) => {
               this.$modal.msgSuccess("新增成功");
               this.open = false;
               this.getList();
@@ -245,19 +338,55 @@ export default {
     /** 删除按钮操作 */
     handleDelete(row) {
       const numbers = row.number || this.ids;
-      this.$modal.confirm('是否确认删除etype编号为"' + numbers + '"的数据项?').then(function() {
-        return delEtype(numbers);
-      }).then(() => {
-        this.getList();
-        this.$modal.msgSuccess("删除成功");
-      }).catch(() => {});
+      this.$modal
+        .confirm('是否确认删除etype编号为"' + numbers + '"的数据项?')
+        .then(function () {
+          return delEtype(numbers);
+        })
+        .then(() => {
+          this.getList();
+          this.$modal.msgSuccess("删除成功");
+        })
+        .catch(() => {});
     },
     /** 导出按钮操作 */
     handleExport() {
-      this.download('etype/etype/export', {
-        ...this.queryParams
-      }, `etype_${new Date().getTime()}.xlsx`)
-    }
-  }
+      this.download(
+        "etype/etype/export",
+        {
+          ...this.queryParams,
+        },
+        `etype_${new Date().getTime()}.xlsx`
+      );
+    },
+    handleImport() {
+      this.upload.title = "用户导入";
+      this.upload.open = true;
+    },
+    /** 下载模板操作 */
+    importTemplate() {
+      this.download(
+        "etype/etype/importTemplate",
+        {},
+        `user_template_${new Date().getTime()}.xlsx`
+      );
+    },
+    // 文件上传中处理
+    handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+    },
+    // 文件上传成功处理
+    handleFileSuccess(response, file, fileList) {
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
+      this.getList();
+    },
+    // 提交上传文件
+    submitFileForm() {
+      this.$refs.upload.submit();
+    },
+  },
 };
 </script>