From 5bb5c0c4cc1227b0a3f7f4ae926a3e8324022bf9 Mon Sep 17 00:00:00 2001 From: 马宇豪 <978517621@qq.com> Date: 星期五, 19 七月 2024 14:37:01 +0800 Subject: [PATCH] 新增导入 --- src/views/Admin/contactBook/contactors.vue | 77 +++++++++++++++++++++++++++++++++++++- 1 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/views/Admin/contactBook/contactors.vue b/src/views/Admin/contactBook/contactors.vue index 9dc8b3c..42e7129 100644 --- a/src/views/Admin/contactBook/contactors.vue +++ b/src/views/Admin/contactBook/contactors.vue @@ -53,6 +53,18 @@ </a-col> <contactors-mod ref="contactMod" @refresh="getUserList()"></contactors-mod> </a-row> + <a-modal v-model="visible" title="导入通讯录" ok-text="导入通讯录" :confirmLoading="uploadLoading" cancel-text="取消" @ok="uploadFile" centered :afterClose="clearMod"> + <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :colon="false"> + <a-form-model-item label="通讯录表格模板" extra="导入通讯录须依据此模板"> + <a-button type="primary" @click="downloadFile">下载模板</a-button> + </a-form-model-item> + <a-form-model-item label="通讯录表格文件"> + <a-upload :file-list="fileList" :remove="handleRemove" :before-upload="beforeUpload" accept=".xlsx,.xls"> + <a-button> <a-icon type="upload"/> 点击上传 </a-button> + </a-upload> + </a-form-model-item> + </a-form-model> + </a-modal> </div> </template> @@ -68,6 +80,9 @@ } from "@/api/contactBook"; import subMenu from "@/views/Admin/contactBook/subMenu"; import contactorsMod from "@/views/Admin/components/contactorsMod" +import {importUser} from "@/api/user"; +import importNew from "@/assets/importNew.xlsx"; +import exampleFile from "@/assets/example.xlsx"; export default { name: 'sameLevel', @@ -77,6 +92,12 @@ }, data () { return { + visible: false, + uploadLoading: false, + fileList: [], + labelCol: { span: 8 }, + wrapperCol: { span: 14 }, + importNew, openKeys: [], areaVal: [], unittype: null, @@ -184,6 +205,59 @@ } }, methods:{ + downloadFile(){ + const link = document.createElement('a') + link.href = exampleFile + link.target = '_blank' + link.download = '通讯录导入模板.xlsx' + link.click() + }, + + handleRemove(file) { + const index = this.fileList.indexOf(file) + const newFileList = this.fileList.slice() + newFileList.splice(index, 1) + this.fileList = newFileList; + }, + beforeUpload(file) { + this.fileList = [...this.fileList, file] + this.fileList = this.fileList.slice(-1) + return false; + }, + + async uploadFile(){ + if(!this.currentId || !this.search.searchParams.orgStructureId){ + this.$message.warning('请先在页面左侧单位架构处选择需要导入人员的单位') + return + } + if(this.fileList.length == 0){ + this.$message.warning('请先上传通讯录表格'); + return + }else{ + this.uploadLoading = true + const { fileList } = this; + const formData = new FormData(); + fileList.forEach((file) => { + formData.append('file', file) + }) + formData.append('districtId', this.currentId) + formData.append('orgStructureId', this.search.searchParams.orgStructureId) + const res = await importUser(formData) + if(res.data.code == 100){ + this.$message.success(res.data.msg,2); + this.fileList = [] + this.uploadLoading = false + this.visible = false + await this.getUserList() + }else{ + this.$message.warning(res.data.msg); + this.uploadLoading = false + } + } + }, + clearMod(){ + this.fileList = [] + }, async getStructure(){ const t = this const res = await getStructure() @@ -231,7 +305,6 @@ handleClick(e) { - console.log(e) this.currentId = e.keyPath[1]?e.keyPath[1].split('-')[0]:e.keyPath[0].split('-')[0] this.search = { pageIndex: 1, @@ -261,7 +334,7 @@ }, massImport(){ - this.$message.warning('批量导入请联系管理人员') + this.visible = true }, resetSearch(){ -- Gitblit v1.9.2