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
<template>
<div class="app-content" style="height:75vh;overflow: auto;">
<div class="submit-btn upload-header">
<FileUpload @beforeUpload="beforeUpload" @cancel="onCancel" />
</div>
<a-divider style="height: 1px; background-color: #e8e8e8;" />
<div class="upload-table">
<a-spin :spinning="loading" style="width: 100%;height: 100%;">
<a-table :dataSource="tableData" :columns="columns" rowKey="id" :pagination="false">
</a-table>
</a-spin>
</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: "projectImport",
data () {
return {
columns: [],
columnsName: [],
tableData: [],
disabled: true,
loading: false,
};
},
created () {
},
methods: {
beforeUpload (file) {
this.loading = true
this.columns = []
this.tableData = []
this.columnsName = []
let list = []
readExcelFile(file, 0).then((data) => {
if (data) {
list = data
if (list.length > 0) {
for (var key in list[0]) {
if (!this.columnsName.includes(key)) {
this.columnsName.push(key)
let columns = { title: key, dataIndex: key, align: 'center' }
this.columns.push(columns)
} else {
alert('存在重复的列,请检查!')
this.columns = []
this.tableData = []
break
}
}
}
if (this.columns.length > 0) {
this.tableData = list
this.disabled = false
}
this.loading = false
} else this.loading = false
})
return false
},
dataImport () {
if (this.tableData.length == 0) {
this.$message.error('请选择Excel!')
return
}
this.loading = true
this.tableData.forEach(e => {
if (e.created)
e.created = e.created + ' 00:00:00'
if (e.startDate)
e.startDate = e.startDate + ' 00:00:01'
if (e.endDate)
e.endDate = e.endDate + ' 23:59:59'
})
this.$api.project.projectImport(this.tableData).then(({ data = {} }) => {
if (data) {
this.$message.success('成功!')
this.tableData = data
}
this.loading = false
})
},
onCancel () {
this.loading = true
this.columns = []
this.tableData = []
this.columnsName = []
this.loading = false
}
},
};
</script>
<style scoped lang="less">
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
.upload-header {
height: 30px;
}
.upload-table {
min-height: 150px;
max-height: calc(100% - 90px);
overflow-y: auto;
}
.upload-bottom {
height: 42px;
}
</style>