| | |
| | | <el-form-item v-if="data.isAdmin"> |
| | | <el-button type="primary" style="margin-left: 30px" @click="searchClick">查询</el-button> |
| | | <el-button plain @click="reset">重置</el-button> |
| | | </el-form-item> |
| | | |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" style="margin-left: 15px" icon="Upload" @click="exportData">导入</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | </div> |
| | | <!-- 表格数据 --> |
| | |
| | | /> |
| | | </div> |
| | | <overviewDialog ref="noticeRef" @getList = "getList"></overviewDialog> |
| | | <el-dialog |
| | | v-model="data.exportDialog" |
| | | title="导入模板" |
| | | width="500px" |
| | | :before-close="handleCloseExport" |
| | | :close-on-press-escape="false" |
| | | :close-on-click-modal="false" |
| | | > |
| | | <el-form :model="state.form" size="default" ref="superRef" :rules="state.formRules" label-width="110px" > |
| | | <el-form-item label="企业名称:" v-if="data.isAdmin" style="margin-left: 20px"> |
| | | <el-select v-model="state.form.companyId" filterable placeholder="请选择" clearable> |
| | | <el-option |
| | | v-for="item in data.companyList" |
| | | :key="item.id" |
| | | style="width: 100%" |
| | | :label="item.name" |
| | | :value="item.id"> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="模板:" > |
| | | <el-button @click="downloadFileTable" size="default" :icon="Download" type="primary" plain>下载模板</el-button> |
| | | </el-form-item> |
| | | <el-form-item label="导入文件"> |
| | | <el-upload |
| | | accept=".doc,.docx" |
| | | :before-upload="beforeUpload" |
| | | v-model:file-list="state.exportFileList" |
| | | action="#" |
| | | :auto-upload="false" |
| | | :on-change="handleChange" |
| | | style="width: 100%" |
| | | > |
| | | <el-button :icon="Upload" size="default" type="primary">点击上传</el-button> |
| | | </el-upload> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="handleCloseExport" size="default">取 消</el-button> |
| | | <el-button type="primary" @click="onUpload" size="default">确定</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | |
| | | import {getCompany} from "@/api/onlineEducation/company"; |
| | | import Cookies from "js-cookie"; |
| | | import {delCom, getCom} from "@/api/companyInfo/overview"; |
| | | import {Download, Upload} from "@element-plus/icons-vue"; |
| | | import {uploadTemplate} from "@/api/staffManage/staff"; |
| | | import {uploadInOverview} from "@/api/companyInfo/basicInfo"; |
| | | const { proxy } = getCurrentInstance(); |
| | | const loading = ref(false); |
| | | const noticeRef = ref(); |
| | | const loadingCompany = ref(false) |
| | | const checkFiles = (rule, value, callback) => { |
| | | if (state.exportFileList.length == 0) { |
| | | callback(new Error('请上传导入文件')) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | const data = reactive({ |
| | | queryParams: { |
| | | pageNum: 1, |
| | |
| | | }, |
| | | companyList: [], |
| | | isAdmin: false, |
| | | companyName: '' |
| | | companyName: '', |
| | | exportDialog: false, |
| | | }); |
| | | const state = reactive({ |
| | | form: { |
| | | id: null, |
| | | filePath: '', |
| | | companyId: null |
| | | }, |
| | | formRules:{ |
| | | companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }], |
| | | filePath: [{ required: true, validator: checkFiles, trigger: 'blur' }] |
| | | }, |
| | | exportFileList: [], |
| | | }) |
| | | const dataList = ref([]); |
| | | const total = ref(0); |
| | | |
| | |
| | | } |
| | | }) |
| | | } |
| | | const exportData = () => { |
| | | data.exportDialog = true |
| | | |
| | | } |
| | | const handleCloseExport = () => { |
| | | getList() |
| | | state.form.companyId = null |
| | | state.exportFileList = [] |
| | | data.exportDialog = false |
| | | } |
| | | const downloadFileTable = () => { |
| | | const filePath = '/overviewExample.docx'; |
| | | const link = document.createElement('a'); |
| | | link.href = filePath; |
| | | link.download = filePath.substr(filePath.lastIndexOf('/') + 1); |
| | | link.click(); |
| | | } |
| | | const beforeUpload = (file) => { |
| | | state.exportFileList = [...state.exportFileList, file] |
| | | state.exportFileList = state.exportFileList.slice(-1) |
| | | return false; |
| | | } |
| | | const fileBinaryList = ref([]) |
| | | const handleChange = (file, files) => { |
| | | fileBinaryList.value = files; |
| | | }; |
| | | const onUpload = async () => { |
| | | if(state.exportFileList.length == 0){ |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: '请先上传表格文件' |
| | | }); |
| | | return |
| | | }else if( data.isAdmin && !state.form.companyId){ |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: '管理员请先选择企业' |
| | | }); |
| | | return |
| | | }else{ |
| | | const formData = new FormData(); |
| | | fileBinaryList.value.forEach((file) => { |
| | | formData.append('file', file.raw) |
| | | }) |
| | | formData.append('companyId',data.isAdmin ? state.form.companyId : data.queryParams.companyId) |
| | | // const param = { |
| | | // file: formData, |
| | | // companyId: data.isAdmin ? state.form.companyId : data.queryParams.companyId |
| | | // } |
| | | console.log('form',formData) |
| | | const res = await uploadInOverview(formData) |
| | | if(res.code == 200){ |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '导入成功' |
| | | }); |
| | | state.form.companyId = null |
| | | state.exportFileList = [] |
| | | data.exportDialog = false |
| | | await getList() |
| | | }else{ |
| | | ElMessage({ |
| | | type: 'error', |
| | | message: res.message |
| | | }); |
| | | await getList() |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | <style lang="scss"> |
| | | .pag-container{ |