Browse Source

Signed-off-by: ljx <809268652@qq.com>企业实体显示分类和添加导入按钮

ljx 1 month ago
parent
commit
cb0027de06
2 changed files with 89 additions and 6 deletions
  1. 86 3
      src/views/enterprise/enterprise/index.vue
  2. 3 3
      src/views/etype/etype/index.vue

+ 86 - 3
src/views/enterprise/enterprise/index.vue

@@ -81,6 +81,16 @@
           v-hasPermi="['enterprise:enterprise:export']"
         >导出</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="info"
+          icon="el-icon-upload2"
+          size="mini"
+          @click="handleImport"
+          v-hasPermi="['enterprise:enterprise:import']"
+          >导入</el-button
+        >
+      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -90,6 +100,7 @@
       <el-table-column label="企业名称" align="center" prop="enterpriseName" />
       <el-table-column label="坐落地" align="center" prop="location" />
       <el-table-column label="行业代码" align="center" prop="code" />
+      <el-table-column label="企业分类" align="center" prop="typeName" />
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
@@ -136,12 +147,44 @@
         <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 { listEnterprise, getEnterprise, delEnterprise, addEnterprise, updateEnterprise, listEnterpriseWithType } from "@/api/enterprise/enterprise";
-
+import { getToken } from '@/utils/auth'
 export default {
   name: "Enterprise",
   data() {
@@ -180,6 +223,19 @@ export default {
           { required: true, message: "企业名称不能为空", trigger: "blur" }
         ],
       },
+      upload: {
+        // 是否显示弹出层(用户导入)
+        open: false,
+        // 弹出层标题(用户导入)
+        title: "",
+        // 是否禁用上传
+        isUploading: false,
+        // 是否更新已经存在的用户数据
+        // 设置上传的请求头部
+        headers: { Authorization: "Bearer " + getToken() },
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/enterprise/enterprise/importData",
+      },
       // 企业名称提示列表
       enterpriseNameSuggestions: []
     };
@@ -279,8 +335,35 @@ export default {
       this.download('enterprise/enterprise/export', {
         ...this.queryParams
       }, `enterprise_${new Date().getTime()}.xlsx`)
-    }
-  ,
+    },
+    handleImport() {
+      this.upload.title = "企业(分类)数据导入";
+      this.upload.open = true;
+    },
+    /** 下载模板操作 */
+    importTemplate() {
+      this.download(
+        "enterprise/enterprise/importTemplate",
+        {},
+        `enterprise_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();
+    },
   // 企业名称模糊查询
   performEnterpriseNameSearch() {
     const searchTerm = this.queryParams.enterpriseName;

+ 3 - 3
src/views/etype/etype/index.vue

@@ -339,7 +339,7 @@ export default {
     handleDelete(row) {
       const numbers = row.number || this.ids;
       this.$modal
-        .confirm('是否确认删除etype编号为"' + numbers + '"的数据项?')
+        .confirm('是否确认删除分类编号为"' + numbers + '"的数据项?')
         .then(function () {
           return delEtype(numbers);
         })
@@ -360,7 +360,7 @@ export default {
       );
     },
     handleImport() {
-      this.upload.title = "用户导入";
+      this.upload.title = "分类数据导入";
       this.upload.open = true;
     },
     /** 下载模板操作 */
@@ -368,7 +368,7 @@ export default {
       this.download(
         "etype/etype/importTemplate",
         {},
-        `user_template_${new Date().getTime()}.xlsx`
+        `type_template_${new Date().getTime()}.xlsx`
       );
     },
     // 文件上传中处理