whiteListImport.vue
4.25 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
186
187
188
189
190
191
192
<template>
<div class="whiteListImport">
<el-form
ref="recordRef"
label-width="154px"
:rules="configRules"
:model="recordForm"
>
<el-form-item
label="导入白名单:"
prop="exportUrl"
class="m-t-20"
>
<div class="activity-link">
<div class="upload-btn">
<el-button size="small">
<i class="el-icon-plus"></i>
上传文件
</el-button>
<input
type="file"
style="opacity: 0"
ref="file"
accept="*"
@change="uploadFile"
/>
</div>
<a
href="https://img01.glsx.com.cn/weapp/resource/saas/scrm/xlsx/白名单模板.xlsx"
target="_blank"
>下载导入模板</a>
<template v-if="recordForm.exportUrl">
<div class="file-info flex">
{{ fileName }}
<div class="el-icon-success"></div>
</div>
</template>
<template v-if="fileError">
<div class="file-info flex error">
<a
:href="fileError"
target="_blank"
>下载失败列表</a>
<div class="el-icon-error"></div>
</div>
</template>
</div>
</el-form-item>
</el-form>
</div>
</template>
<script>
import commonFun from "../common/fun";
export default {
name: "whiteListImport",
props: {
DetailObj: {
type: Object,
default: () => {
}
}
},
data() {
return {
recordForm: {
activityRedEnvelopeId: this.DetailObj.id,
exportUrl: ''
},
configRules: {
exportUrl: [
{
required: true,
message: '请导入白名单',
}
],
},
fileName: '',
fileError: ''
}
},
methods: {
handleClose() {
this.recordForm = this.$options.data.call(this).recordForm
this.fileError = ''
this.$refs.recordRef.resetFields()
this.$emit('update:show', false)
},
handleConfirm() {
this.$refs.recordRef.validate(async (valid) => {
if (valid) {
try {
const {recordForm} = this,
res = await this.$apis.redenvelope.whiteListImport(recordForm)
if (res) {
this.$message({
message: '导入成功',
type: 'success'
})
this.handleClose()
this.$parent.handleClose()
}
} catch (error) {
this.$message.error(error)
}
}
})
},
async uploadFile(e) {
try {
const {url, name} = await commonFun.uploadFile(e, this),
{activityRedEnvelopeId} = this.recordForm
this.$refs.file.value = ''
const res = await this.$apis.redenvelope.checkImportWhiteList({activityRedEnvelopeId, exportUrl: url})
if (res) {
if (res.totalCount == 0 || res.failCount > 0) {
this.fileError = res.errorUrl
this.$message.error('导入失败')
this.recordForm.exportUrl = ''
return
}
this.$message({
message: '导入成功',
type: 'success'
})
this.fileError = ''
this.recordForm.exportUrl = url
this.fileName = name
}
} catch (error) {
if (error) this.$message.error(error)
}
}
}
}
</script>
<style scoped lang='scss'>
.whiteListImport {
margin-top: 20px;
}
.activity-link {
display: flex;
width: 500px;
.upload-btn {
position: relative;
width: 110px;
height: 32px;
.el-button--small {
width: 100%;
height: 100%;
}
input {
cursor: pointer;
position: absolute;
height: 100%;
width: 100%;
top: 0px;
left: 0px;
font-size: 0px;
}
}
a,
.error {
margin-left: 8px;
color: #5850ff;
font-size: 14px;
cursor: pointer;
}
.file-info {
margin-left: 8px;
.el-icon-success {
margin-left: 8px;
color: #67c23a;
}
.el-icon-error {
margin-left: 8px;
color: red;
}
}
}
</style>