historyFeeDetailImportList.vue
5.89 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
<div class="history-fee-detail-import-container">
<el-card class="box-card">
<div slot="header" class="flex justify-between">
<span>{{ $t('historyFeeDetailImport.assetInfo') }}</span>
<div class="card-header-right">
<el-button type="primary" size="small" @click="_openDownloadHcExcelTemplate">
<i class="el-icon-download"></i>{{ $t('historyFeeDetailImport.houseTemplate') }}
</el-button>
<el-button type="primary" size="small" @click="_openDownloadHcCarExcelTemplate">
<i class="el-icon-download"></i>{{ $t('historyFeeDetailImport.carTemplate') }}
</el-button>
</div>
</div>
<el-row :gutter="20">
<el-col :span="24">
<el-form label-position="left" label-width="120px" class="text-left">
<el-form-item :label="$t('historyFeeDetailImport.feeObject')">
<el-select v-model="historyFeeDetailImportInfo.objType" style="width:100%"
:placeholder="$t('historyFeeDetailImport.selectFeeObject')">
<el-option disabled value="" :label="$t('historyFeeDetailImport.requiredSelect')">
</el-option>
<el-option value="3333" :label="$t('historyFeeDetailImport.house')">
</el-option>
<el-option value="6666" :label="$t('historyFeeDetailImport.car')">
</el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('historyFeeDetailImport.selectFile')">
<el-upload class="upload-demo" action="" :auto-upload="false" :on-change="getExcelTemplate"
:show-file-list="false">
<el-button size="small" type="primary">
{{ $t('historyFeeDetailImport.clickUpload') }}
</el-button>
<div slot="tip" class="el-upload__tip">
{{ historyFeeDetailImportInfo.excelTemplate ?
historyFeeDetailImportInfo.excelTemplate.name :
$t('historyFeeDetailImport.requiredFile') }}
</div>
</el-upload>
</el-form-item>
<el-form-item :label="$t('historyFeeDetailImport.description')">
<div class="description-text">
{{ $t('historyFeeDetailImport.importTip') }}
</div>
</el-form-item>
</el-form>
</el-col>
</el-row>
<el-row>
<el-col :span="24" class="text-right">
<el-button type="primary" @click="_importData"
:disabled="!historyFeeDetailImportInfo.excelTemplate || !historyFeeDetailImportInfo.objType">
{{ $t('historyFeeDetailImport.import') }}
</el-button>
</el-col>
</el-row>
</el-card>
</div>
</template>
<script>
import { importData } from '@/api/system/historyFeeDetailImportApi'
import { getCommunityId } from '@/api/community/communityApi'
export default {
name: 'HistoryFeeDetailImportList',
data() {
return {
historyFeeDetailImportInfo: {
communityId: '',
excelTemplate: null,
objType: ''
}
}
},
created() {
this.historyFeeDetailImportInfo.communityId = getCommunityId()
},
methods: {
_openDownloadHcExcelTemplate() {
window.open('/import/importFeeDetail.xlsx')
},
_openDownloadHcCarExcelTemplate() {
window.open('/import/importCarFeeDetail.xlsx')
},
getExcelTemplate(file) {
this.historyFeeDetailImportInfo.excelTemplate = file.raw
},
async _importData() {
if (!this.validateForm()) {
return
}
const param = new FormData()
param.append('uploadFile', this.historyFeeDetailImportInfo.excelTemplate)
param.append('communityId', this.historyFeeDetailImportInfo.communityId)
param.append('objType', this.historyFeeDetailImportInfo.objType)
const _importAdapt = this.historyFeeDetailImportInfo.objType === '6666' ?
'importCarHistoryFeeDetail' : 'importRoomHistoryFeeDetail'
param.append('importAdapt', _importAdapt)
try {
const res = await importData(param)
if (res.code === 0) {
this.$message.success(this.$t('historyFeeDetailImport.importSuccess'))
this.historyFeeDetailImportInfo.excelTemplate = null
this.$router.push({
path: '/views/system/assetImportLogDetail',
query: {
logId: res.data.logId,
logType: _importAdapt
}
})
} else {
this.$message.error(res.msg)
}
} catch (error) {
this.$message.error(this.$t('historyFeeDetailImport.importError'))
}
},
validateForm() {
if (!this.historyFeeDetailImportInfo.excelTemplate) {
this.$message.error(this.$t('historyFeeDetailImport.fileRequired'))
return false
}
if (!this.checkFileType(this.historyFeeDetailImportInfo.excelTemplate.name)) {
this.$message.error(this.$t('historyFeeDetailImport.invalidFileType'))
return false
}
if (!this.checkFileSize(this.historyFeeDetailImportInfo.excelTemplate.size)) {
this.$message.error(this.$t('historyFeeDetailImport.fileSizeLimit'))
return false
}
return true
},
checkFileType(fileName) {
const fileExt = fileName.split('.').pop().toLowerCase()
return ['xls', 'xlsx'].includes(fileExt)
},
checkFileSize(fileSize) {
return fileSize <= 2 * 1024 * 1024 // 2MB
}
}
}
</script>
<style lang="scss" scoped>
.history-fee-detail-import-container {
padding: 20px;
.box-card {
margin-bottom: 20px;
}
.card-header-right {
float: right;
}
.description-text {
color: #606266;
font-size: 14px;
line-height: 1.5;
}
.text-right {
text-align: right;
margin-top: 20px;
}
.el-upload__tip {
margin-left: 10px;
display: inline-block;
vertical-align: middle;
}
}
</style>