<template> <div class="app-content" style="height: 65vh;overflow: auto;"> <a-spin :spinning="loading" style="width: 100%;height: 100%;"> <div style="width:100%; height: 36px;"> <up-load @beforeUpload="beforeUpload" :format="['xls', 'xlsx']" /> </div> <div style="width:100%;height: calc(100% - 72px);overflow: auto;"> <a-table :dataSource="tableData" :columns="columns" :pagination="false" :loading="loading" bordered size="small"> <template slot="msg" slot-scope="record"> <span v-if="!!record.msg " style="color: red;"> {{ record.msg }} </span> </template> </a-table> </div> <div style="text-align:center;width:100%; height: 36px;"> <a :href="url" download="memberInfo.xlsx" style="margin-right: 30px;"> <a-icon type="download"></a-icon> <span style="color:green;text-decoration:underline;">项目组成员模板下载</span> </a> <a-button type="primary" @click="dataImport" :disabled="disabled">导入</a-button> </div> </a-spin> </div> </template> <script> import { isEmptyParams, readExcelFile, personGender, personBirthday, checkIdentitytionId, checkEmail, checkPhone } from "@/views/utils/common" import { checkCertId } from "@/views/utils/validate" import { getTitle, getDegree } from "@/views/report/project/config" import moment from "moment" export default { name: "expertImport", data () { return { columns: [ { title: "姓名", dataIndex: "name", align: 'center' }, { title: "出生日期", dataIndex: "birthday", align: 'center' }, { title: "性别", dataIndex: "sex", align: 'center' }, { title: "职称", dataIndex: "titleName", align: 'center' }, { title: "学位", dataIndex: "degreeName", align: 'center' }, { title: '工作单位', dataIndex: 'workUnit', align: 'center' }, { title: '手机号', dataIndex: 'mobile', align: 'center' }, { title: '电子邮箱', dataIndex: 'email', align: 'center' }, { title: '证件号码', dataIndex: 'certId', align: 'center' }, { title: '项目分工', dataIndex: 'projWork', align: 'center' }, { title: '每年工作(月)', dataIndex: 'forMonths', align: 'center' }, { title: '验证结果', scopedSlots: { customRender: 'msg' }, align: 'center' }, ], tableData: [], disabled: true, errorState: false, loading: false, url: '/downloadFile/memberInfo.xlsx', }; }, created () { }, methods: { moment, beforeUpload (file) { this.errorState = false this.tableData = [] let list = readExcelFile(file, 0) let memberList = [] list.then((d) => { //读取文件数据 d.forEach(e => { let msg = '' let certId = e.证件号码 let gender = e.性别 let birthday = moment(e.出生日期).format('YYYY-MM-DD HH:mm:ss') let title = null let degree = null if (!!!e.姓名) { msg = ';姓名不能为空!' } if (!!!e.出生日期) { msg += ';出生日期不能为空!' } if (!!!e.性别) { msg += ';性别不能为空!' } if (!!!e.职称) { msg += ';职称不能为空!' } else { title = getTitle(e.职称) } if (!!!e.学位) { msg += ';学位不能为空!' } else { degree = getDegree(e.学位) } if (!!!e.工作单位) { msg += ';工作单位不能为空!' } if (!!!e.手机号) { msg += ';手机号不能为空!' } if (!!!e.电子邮箱) { msg += ';电子邮箱不能为空!' } if (!!!e.证件号码) { msg += ';证件号码不能为空!' } if (!!!e.项目分工) { msg += ';项目分工不能为空!' } if (!!!e.每年工作) { msg += ';每年工作不能为空!' } if (!!msg) { this.errorState = true } let member = { name: e.姓名, birthday: birthday, sex: gender, title: title, titleName: e.职称, degree: degree, degreeName: e.学位, workUnit: e.工作单位, mobile: e.手机号, email: e.电子邮箱, certId: certId, projWork: e.项目分工, forMonths: e.每年工作, msg: msg, fileId: null, downloadId: null, fileName: null, downloadUrl: null } memberList.push(member) }) if (memberList.length > 0) { this.tableData = memberList this.disabled = this.errorState ? true : false } }) return false }, dataImport () { if (this.tableData.length == 0) { this.$message.error('请选择加载Excel!') return } this.$emit('import', this.tableData) } }, }; </script> <style scoped lang="less"> ::v-deep .ant-spin-container { width: 100%; height: 100%; } </style>