1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<template>
<div class="app-content" style="height:75vh;overflow: auto;">
<div class="submit-btn upload-header">
<a :href="url.downloadUrl" download="ExpertInfo.xlsx">
<a-icon type="download"></a-icon> <span style="color:green;text-decoration:underline;">模板下载</span>
</a>
<FileUpload @beforeUpload="beforeUpload" />
<a-divider style="height: 1px; background-color: #e8e8e8;" />
</div>
<a-divider style="height: 1px; background-color: #e8e8e8;" />
<div class="upload-table">
<a-table :dataSource="tableData" :columns="columns" rowKey="index" :pagination="false" :loading="loading">
<template slot="stateSwitch" slot-scope="record">
<a-switch checked-children="正常" un-checked-children="注销" :checked="checkedState(record)" @change="switchChange($event, record)" />
</template>
<template slot="option" slot-scope="record">
<a-button type="primary" size="small" @click="recordClick(record, 'view')">查看</a-button>
<a-button type="primary" size="small" @click="recordClick(record, 'edit')">修改</a-button>
<a-button type="primary" size="small" @click="recordClick(record, 'reset')">重置密码</a-button>
</template>
</a-table>
</div>
<div class="upload-bottom" style="text-align:center;padding:6px 0">
<a-button type="primary" @click="dataImport" :disabled="disabled">导入</a-button>
</div>
</div>
</template>
<script>
import { isEmptyParams, readExcelFile, personGender, personBirthday, checkIdentitytionId, checkEmail, checkPhone } from "@/views/utils/common"
import moment from "moment"
export default {
name: "expertImport",
data () {
return {
columns: [
{ title: "姓名", dataIndex: "personName", align: 'center' },
{ title: "证件号", dataIndex: "certId", align: 'center' },
// { title: "性别", dataIndex: "sex" },
// { title: "出生日期", dataIndex: 'birthday' },
{ title: "手机号", dataIndex: "mobile", align: 'center' },
{ title: "邮箱", dataIndex: "email", align: 'center' },
{ title: "职称", dataIndex: "titleName", align: 'center' },
{ title: "专业", dataIndex: "specName", align: 'center' },
{ title: '单位', dataIndex: 'unitName', align: 'center' },
],
tableData: [],
disabled: true,
loading: false,
url: {
downloadUrl: '/downloadFile/ExpertInfo.xlsx',
}
};
},
created () {
},
methods: {
beforeUpload (file) {
this.tableData = []
let list = readExcelFile(file, 0)
let certList = []
let mobileList = []
let exportList = []
list.then((d) => {
//读取文件数据
d.forEach(e => {
let gender = personGender(e.证件号)
let birthday = personBirthday(e.证件号) + ' 00:00:00'
let expert = { personName: e.姓名, certId: e.证件号, sex: gender, birthday: moment(birthday).format('YYYY-MM-DD HH:mm:ss'), mobile: e.手机号, email: e.邮箱, specName: e.专业, titleName: e.职称, unitName: e.单位 }
exportList.push(expert)
certList.push(e.证件号)
mobileList.push(e.手机号)
})
let uniqueMobileList = [...new Set(mobileList)]
if (uniqueMobileList.length != exportList.length) {
this.$message.error('手机号出现重复!')
return false
}
let uniqueCertList = [...new Set(certList)]
if (uniqueCertList.length != exportList.length) {
this.$message.error('证件号出现重复!')
return false
}
if (exportList.length > 0) {
this.tableData = exportList
this.disabled = false
}
})
return false
},
dataImport () {
if (this.tableData.length == 0) {
this.$message.error('请选择Excel!')
return
}
let pars = isEmptyParams(this.tableData)
let par = { ...pars }
this.$api.expert.expertImport(this.tableData).then(({ data = {} }) => {
if (data) {
this.$message.info(data)
this.tableData = []
}
})
}
},
};
</script>
<style scoped lang="less">
.upload-header {
height: 30px;
}
.upload-table {
min-height: 150px;
max-height: calc(100% - 75px);
overflow-y: auto;
}
.upload-bottom {
height: 42px;
}
</style>