outputValue.vue
13.4 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!-- 企微推送产值进度表 -->
<template>
<d2-container class="outputValue-list">
<div class="header" slot="header">
<d2-search ref="showSearch" class="show-search" :search-form="searchForm" :form-data="showFormData" />
<div class="up-btns">
<el-button :id="tableParams.btnId" size="small" type="primary">查询</el-button>
<el-button size="small" @click="handleReset">重置</el-button>
</div>
</div>
<div class="d2-container-content">
<d2-table-header>
<span slot="left">
<auth-button category="Button" :show-btn-ids="['9070301']" />
</span>
<auth-button category="Button" :show-btn-ids="['9070303']" />
</d2-table-header>
<d2-table ref="outputValueTable" :search-form="tableSearchForm" :table-params="tableParams"
:get-list-api="getListApi" :before-search-fn="beforeSearchFn">
<div slot="concatType" slot-scope="scope">
<p v-if="scope.scope.concatType == 1">督导</p>
<p v-if="scope.scope.concatType == 2">驻店</p>
</div>
<auth-button slot="auth-button" slot-scope="scope" :data="scope.scope" />
</d2-table>
</div>
<d2-dialog :title="'上传文件'" :is-visible="fileVisible" @closeDialog="handleImport" @confirmDialog="handleConfirmImport">
<slot>
<el-form :model="fileForm" ref="fileRuleForm" :rules="fileRules" label-width="120px">
<el-form-item label="导入文件:" prop="fileName">
<el-col :span="16">
<el-input readonly v-model="fileForm.fileName" />
</el-col>
<el-col :span="4" class="m-l-md">
<el-button class="import-btn">导入文件
<input type="file" id="fileUpload" class="import-input"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
@change="importFile($event)">
<el-link href="http://img01.glsx.com.cn/upload/salesexcel/企微推送对象导入模板.xlsx" type="primary"
class="import-template" icon="el-icon-link">模版下载</el-link>
</el-button>
</el-col>
</el-form-item>
</el-form>
</slot>
</d2-dialog>
<d2-dialog :title="chooseType" @closeDialog="handleObject" @confirmDialog="handleConfirmObject"
:is-visible="pushVisible">
<slot>
<el-form :model="pushForm" ref="pushForm" :rules="rules" style="margin-left: 59px;">
<el-form-item label="类型:" prop="concatType">
<el-select v-model="pushForm.concatType" clearable style="width: 280px;" placeholder="请选择"
@change="changeValue">
<el-option v-for="item in state" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="商户:" prop="merchantName">
<el-select v-model="pushForm.merchantName" clearable filterable style="width: 280px;" placeholder="请选择">
<el-option v-for="item in changeList" :key="item.merchantId" :label="item.merchantName"
:value="item.merchantName" />
</el-select>
</el-form-item>
<el-form-item label="姓名:" prop="name">
<el-input v-model="pushForm.name" style="width: 280px;" placeholder="请输入姓名" clearable />
</el-form-item>
<el-form-item label="手机号:" prop="phone" style="margin-left: -15px;">
<el-input v-model="pushForm.phone" style="width: 280px;" placeholder="请输入手机号" clearable />
</el-form-item>
</el-form>
</slot>
</d2-dialog>
</d2-container>
</template>
<script>
import { getMerchantPageSearch } from '../../api/publicAccount'
import { pushObject, addContact, modifyContact, importContact, removeContact } from '../../api/merchant'
import { mapActions, mapState, mapMutations } from 'vuex'
import { deepClone } from '@/common/util'
const state = [
{
value: 1,
label: '督导'
},
{
value: 2,
label: '驻店'
}
]
export default {
name: 'OutputValue',
data() {
return {
state,
// 上传文件数据
fileVisible: false,
fileForm: {},
// 搜索表格数据
tableSearchForm: {},
searchForm: {
name: '',
phone: '',
merchantId: ''
},
showFormData: [{
label: '姓名',
name: 'name',
type: 'input',
placeholder: '请输入姓名',
isClear: true,
keyFn: this.keyDowmGetList
}, {
label: '手机号',
name: 'phone',
type: 'input',
placeholder: '请输入手机号',
isClear: true,
keyFn: this.keyDowmGetList
}, {
label: '商户号',
name: 'merchantId',
type: 'input',
placeholder: '请输入商户号',
isClear: true,
keyFn: this.keyDowmGetList
}],
getListApi: pushObject,
tableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list',
tableOption: true,
tableColumns: [{
label: '姓名',
prop: 'name'
}, {
label: '手机号',
prop: 'phone'
}, {
label: '类型',
prop: '',
addHtml: 'concatType'
}, {
label: '商户名称',
prop: 'merchantName'
}, {
label: '商户号',
prop: 'merchantId'
}]
},
pushForm: {
concatType: '',
merchantName: '',
name: '',
phone: '',
merchantId: ''
},
chooseId: '',
pushVisible: false,
rules: {
concatType: [{ required: true, message: '请选择类型', trigger: 'change' }],
merchantName: [{ required: true, message: '请选择商户', trigger: 'change' }],
name: [{ required: true, message: '请输入姓名', trigger: 'change' }],
phone: [{ required: true, message: '请输入手机号', trigger: 'change' },
{
validator: (rule, value, callback) => {
const phoneReg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
return phoneReg.test(value) ? callback() : callback(new Error('请输入正确的联系号码'))
},
trigger: 'change'
}
]
},
fileRules: {
fileName: [{ required: true, message: '请上传文件', trigger: 'change' }]
},
changeList: [],
superviseList: [],
residentialList: [],
chooseType: ''
}
},
computed: {
...mapState({
updateList: (state) => state.d2admin.user.updateList
})
},
watch: {
updateRefesh(val) {
// console.log('val', val)
if (val == true) {
this.merchantData()
this.setUpdateRefesh('false')
}
}
},
methods: {
...mapActions('d2admin/user', ['actionSetDownloadList']),
...mapMutations('d2admin/user', ['setUpdateRefesh']),
// 上传文件,转码为base64
importFile(e) {
const size = e.target.files[0].size / 1024 / 1024
if (size < 9) {
this.$set(this.fileForm, 'fileName', e.target.files[0].name)
// // 转码base64
const reader = new FileReader()
reader.readAsDataURL(e.target.files[0])
reader.onload = event => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(',')
this.fileInfo = e.target.files[0].name.split('.')[1] + '@' + arrBase64[1]
document.getElementById('fileUpload').value = ''
}
} else {
this.notice.errorTips('上传文件不可超过9M')
}
},
beforeSearchFn() {
return new Promise(resolve => {
this.tableSearchForm = deepClone(this.searchForm)
resolve()
})
},
keyDowmGetList() {
this.$refs.outputValueTable.refreshTable()
},
handleConfirmImport() {
this.$refs.fileRuleForm.validate(valid => {
if (valid) {
var params = {
file: this.fileInfo
}
importContact(params).then(res => {
if (res) {
// 异步处理文件上传 把id传入处理轮询
const list = [...this.updateList, {
name: this.fileForm.fileName,
ifSuccess: false,
uuid: res,
type: 'upload'
// labelText: ''
}]
this.actionSetDownloadList({ list, type: 'updateList' })
this.notice.okTips('上传成功')
this.handleImport()
}
})
}
})
},
handleImport() {
// this.fileForm = {
// fileName: ''
// }
this.$refs.fileRuleForm && this.$refs.fileRuleForm.resetFields()
this.fileVisible = !this.fileVisible
},
merchantData(type) {
const superviseParams = {
currentPage: 1,
pageSize: 10000,
merchantTypeList: [6, 8]
}
const residentialParams = {
currentPage: 1,
pageSize: 10000,
merchantTypeList: [2]
}
getMerchantPageSearch(superviseParams).then(res => {
res.list.forEach(e => {
this.superviseList.push({ merchantId: e.merchantId, merchantName: e.merchantName })
if (type == 1) {
this.changeList = this.superviseList
}
})
})
getMerchantPageSearch(residentialParams).then(res => {
res.list.forEach(e => {
this.residentialList.push({ merchantId: e.merchantId, merchantName: e.merchantName })
if (type == 2) {
this.changeList = this.residentialList
}
})
})
},
// 新增
handleAdd() {
this.pushVisible = !this.pushVisible
this.chooseType = '新增推送对象'
this.merchantData()
},
// 编辑
handleEdit(row) {
this.pushVisible = !this.pushVisible
this.chooseType = '编辑推送对象'
this.pushForm = {
concatType: row.concatType,
merchantName: row.merchantName,
name: row.name,
phone: row.phone,
merchantId: row.merchantId
}
this.chooseId = row.id
this.merchantData(row.concatType)
},
// 删除
handleDelete(row) {
this.$confirm('数据删除后无法恢复,是否确认删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
removeContact({ id: row.id }).then(res => {
this.notice.okTips()
this.$refs.outputValueTable.refreshTable()
})
})
},
changeValue(e) {
this.changeList = []
this.pushForm.merchantName = ''
if (e == 1) {
this.changeList = this.superviseList
} else if (e == 2) {
this.changeList = this.residentialList
}
},
// 新增编辑推送对象弹窗
handleConfirmObject() {
this.$refs.pushForm.validate(valid => {
if (valid) {
if (this.pushForm.concatType == 1) {
this.superviseList.forEach(e => {
if (e.merchantName == this.pushForm.merchantName) {
this.pushForm.merchantId = e.merchantId
}
})
} else if (this.pushForm.concatType == 2) {
this.residentialList.forEach(e => {
if (e.merchantName == this.pushForm.merchantName) {
this.pushForm.merchantId = e.merchantId
}
})
}
if (this.chooseType == '新增推送对象') {
addContact({
merchantId: this.pushForm.merchantId,
merchantName: this.pushForm.merchantName,
name: this.pushForm.name,
phone: this.pushForm.phone,
concatType: this.pushForm.concatType
}).then(res => {
console.log(res)
this.handleObject()
})
}
if (this.chooseType == '编辑推送对象') {
modifyContact({
merchantId: this.pushForm.merchantId,
merchantName: this.pushForm.merchantName,
name: this.pushForm.name,
phone: this.pushForm.phone,
concatType: this.pushForm.concatType,
id: this.chooseId
}).then(res => {
console.log(res)
this.handleObject()
})
}
}
})
},
handleObject() {
this.pushForm = {
concatType: '',
merchantName: '',
name: '',
phone: '',
merchantId: ''
}
this.chooseType = ''
this.superviseList = []
this.residentialList = []
this.pushVisible = !this.pushVisible
this.$refs.outputValueTable.refreshTable()
},
handleReset() {
this.searchForm = {
name: '',
phone: '',
merchantId: ''
}
this.$refs.outputValueTable.refreshTable()
}
}
}
</script>
<style scoped>
.outputValue-list {
position: relative;
}
.outputValue-list .m-l-md {
margin-left: 20px;
}
.outputValue-list .import-btn {
position: relative;
}
.outputValue-list .import-input {
opacity: 0;
position: absolute;
right: 0;
top: 0;
width: 98px;
height: 36px;
cursor: pointer;
font-size: 0;
}
.outputValue-list .import-template {
position: absolute;
height: 20px;
top: 50px;
left: 0;
}
</style>