addPayMerchant.vue
18.9 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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!-- 新增支付商户 -->
<template>
<div class="payMerchants marketing edit-box">
<!-- 基本信息 -->
<div class="container edit-container">
<p class="edit-title" id="basic">基本信息</p>
<glsx-combi-form class="edit-form-container" ref="editFormRef" :isEdit="true" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
<template slot="affiliationMerchant" slot-scope="scope">
<el-select style="width: 432px" remote reserve-keyword :remote-method="remoteMethod" v-model="editForm[scope.scope.name]" @visible-change="visibleChange" placeholder="请选择所属商户" @change="changeSelect" filterable>
<el-option v-for="(subItem, subIndex) in merchantsList" :key="subIndex" :label="subItem['merchantName']" :value="subItem['merchantNo']"></el-option>
</el-select>
</template>
<template slot="applyIds" slot-scope="scope">
<el-checkbox-group v-model="editForm.applyIds">
<el-checkbox v-for="value in scope.scope.applyIdsList" :key="value.appType" :label="value.appType">{{ value.appName }}</el-checkbox>
</el-checkbox-group>
</template>
</glsx-combi-form>
</div>
<!-- 配置信息 -->
<div class="container edit-container crowd-config">
<p class="edit-title" id="config">配置信息</p>
<glsx-combi-form class="edit-form-container" ref="configEditFormRef" :isEdit="true" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="configEditFormData" :formRules="editRule">
<template slot="certificateFile" slot-scope="scope">
<div class="upload-box">
<p class="tips-text m-t-10">
请上传从微信支付平台获取的两个PEM格式的证书文件,如何获取证书串、密钥和证书文件,点击
<el-button style="padding: 0" @click="goLinkPage" type="text">查看操作指引</el-button>
</p>
<div class="upload-file-content">
<div>
<el-upload action="" drag class="upload-file" accept=".PEM, .pem" :show-file-list="false" :http-request="handleCertificateUpload" :before-upload="e => handleCertificateBeforeUpload(e, scope.scope, 1)" :file-list="fileKeyList">
<i class="el-icon-upload"></i>
<div class="el-upload__text">
<div>
将文件拖到此处,或
<el-button type="text" style="padding: 0">点击上传</el-button>
</div>
<div class="tips-upload">请上传后缀为_key.pem的证书</div>
</div>
</el-upload>
<div class="file-list-box" v-for="(item, index) in fileKeyList" :key="index">
<div class="file-name-box">{{ item.name }}</div>
<i class="el-icon-delete" @click="delFile(1)"></i>
</div>
</div>
<div>
<el-upload action="" drag class="upload-file" accept=".PEM, .pem" :show-file-list="false" :http-request="handleCertificateUpload" :before-upload="e => handleCertificateBeforeUpload(e, scope.scope, 2)" :file-list="fileCertList">
<i class="el-icon-upload"></i>
<div class="el-upload__text">
<div>
将文件拖到此处,或
<el-button type="text" style="padding: 0">点击上传</el-button>
</div>
<div class="tips-upload">请上传后缀为_cert.pem的证书</div>
</div>
</el-upload>
<div class="file-list-box" v-for="(item, index) in fileCertList" :key="index">
<div class="file-name-box">{{ item.name }}</div>
<i class="el-icon-delete" @click="delFile(2)"></i>
</div>
</div>
</div>
</div>
</template>
</glsx-combi-form>
</div>
<GLFooter>
<el-button @click="handleCancel" size="medium">取消</el-button>
<el-button type="primary" @click="handleConfirm" size="medium" :loading="loading">保存</el-button>
</GLFooter>
<!-- 支付测试弹窗 -->
<collectionTest :isShowTestDialog="isShowTestDialog" :dialogData="dialogData" @handleDialogClose="handleDialogClose"></collectionTest>
</div>
</template>
<script>
import collectionTest from './components/collectionTestDialog'
export default {
components: {
collectionTest
},
name: 'addPayMerchant',
data() {
var validatorFileList = (rule, value, cb) => {
if (!this.fileCertList.length || !this.fileKeyList.length) {
cb(new Error('请上传证书文件'))
} else {
cb()
}
}
return {
editForm: {
payMerchantAccount: '',
payMerchantName: '',
merchantType: '0',
affiliationMerchant: '',
applyIds: [],
certificateString: '',
secretKey: ''
},
editRule: {
payMerchantAccount: [{ required: true, message: '请输入微信支付商户号', trigger: 'change' }],
merchantType: [{ required: true, message: '请选择所属商户类型', trigger: 'change' }],
affiliationMerchant: [{ required: true, message: '请输入所属商户', trigger: 'change' }],
applyIds: [{ required: true, message: '请选择应用ID', trigger: 'change' }],
certificateString: [{ required: true, message: '请输入证书串', trigger: 'change' }],
secretKey: [{ required: true, message: '请输入密钥', trigger: 'change' }],
certificateFile: [{ required: true, validator: validatorFileList, trigger: 'change' }]
},
editFormData: [
{
label: '微信支付商户号',
name: 'payMerchantAccount',
type: 'input',
isDisabled: false
},
{
label: '微信支付商户名',
name: 'payMerchantName',
type: 'input',
isDisabled: false
},
{
label: '所属商户类型',
name: 'merchantType',
type: 'radio',
width: '320px',
optionId: 'confId',
optionLabel: 'confName',
optionList: [
{
confId: '0',
confName: '广联'
},
{
confId: '1',
confName: '服务商'
},
{
confId: '2',
confName: '流量方'
}
],
isDisabled: false,
handleRadioChange: (value, targetItem) => {
this.changeRadio(value)
}
},
{
label: '所属商户',
name: 'affiliationMerchant',
addHtml: 'affiliationMerchant',
isHide: true
},
{
label: '应用ID',
name: 'applyIds',
addHtml: 'applyIds',
optionId: 'appType',
optionLabel: 'appName',
isDisabled: false,
applyIdsList: []
}
],
editStatus: false,
configEditFormData: [
{
label: '证书串',
name: 'certificateString',
type: 'input',
isDisabled: false
},
{
label: '密钥',
name: 'secretKey',
type: 'input',
isDisabled: false
},
{
label: '证书文件',
name: 'certificateFile',
addHtml: 'certificateFile'
}
],
fileCertList: [],
fileKeyList: [],
editChildRef: 'editChildRef',
isShowTestDialog: false,
dialogData: [],
jumpH5Path: '',
merchantsList: [],
queryMerchantName: ''
}
},
mounted() {
// 获取应用id
this.$apis.payMerchantManage.getlistAppInfoApi({}).then(res => {
this.editFormData.find(v => v.name == 'applyIds').applyIdsList = res
})
if (process.env.NODE_ENV == 'development') {
// 本地打开修改dj-scrm-wx-work-main-xxx
this.jumpH5Path = `${this.$request.baseURL}/dj-scrm-wx-work-main-zxw/#/testPayMerchant/index`
} else {
this.jumpH5Path = `${window.location.origin}/scrm-wx-merchant-activity/#/testPayMerchant/index`
}
},
watch: {
editForm: {
handler(val) {
this.editStatus = true
},
deep: true
}
},
methods: {
remoteMethod(query) {
this.queryMerchantName = query
this.getMerchantsList(this.editForm['merchantType']) // 请求接口
},
changeRadio(value) {
this.merchantsList = []
this.queryMerchantName = ''
this.editForm.affiliationMerchant = ''
this.editFormData[3].isHide = !(value == '1' || value == '2')
if (value == '0') return
this.getMerchantsList(value)
},
getMerchantsList(value) {
this.$apis.payMerchantManage
.getBusinessListApi({
// 商户类型,2-流量方,7-服务商
merchantType: value == '1' ? 7 : value == '2' ? 2 : '',
currentPage: 1,
pageSize: 200,
merchantName: this.queryMerchantName
})
.then(res => {
this.merchantsList = res
})
},
changeSelect(val) {
this.editForm.merchantName = this.merchantsList.find(v => v.merchantNo == val).merchantName
},
visibleChange(data) {
// 获取焦点重新渲染下拉框数据
if (data) this.queryMerchantName = ''
},
handleConfirm() {
let validList = []
var validFlag = true
var flag = true
this.$nextTick(() => {
this.$refs.editFormRef.$refs[this.editChildRef].validate((valid, errorObj) => {
validList = [
{ valid: !valid, errorObj: errorObj },
{ valid: !flag, errorObj: { goodsId: '' } }
]
this.$refs.configEditFormRef.$refs[this.editChildRef].validate((configValid, configErrorObj) => {
validList.push({ valid: !configValid, errorObj: configErrorObj })
if (this.checkValid(validList)) {
if (!this.fileCertList.length || !this.fileKeyList.length) {
validFlag = true
}
} else {
validFlag = false
}
validFlag && this.confirmEvent()
})
})
})
},
confirmEvent() {
let params = {
merchantNo: this.editForm.affiliationMerchant,
merchantName: this.editForm.merchantName,
mchId: this.editForm.payMerchantAccount,
mchName: this.editForm.payMerchantName,
mchBelong: this.editForm.merchantType,
appTypes: this.editForm.applyIds.join(','),
merchantSerialNo: this.editForm.certificateString,
apiKey: this.editForm.secretKey,
apiclientKeyPemPath: this.fileKeyList[0]?.url,
apiclientCertPemPath: this.fileCertList[0]?.url
}
this.$apis.payMerchantManage.creatPayMerchantApi(params).then(res => {
if (res.code == '0') {
this.secondConfirm('提示', '<p style="text-align: center;font-size:16px;font-weight: blod;">保存成功</p><p style="font-size:14px; color: #666;">为确保完成正常收款,请继续进行收款测试</p>', res.data)
} else {
this.$message({
message: res.message,
type: 'error'
})
}
})
},
secondConfirm(title, txt, data) {
this.$confirm(txt, title, {
confirmButtonText: '收款测试',
dangerouslyUseHTMLString: true,
iconClass: 'el-icon-warning',
showCancelButton: false,
distinguishCancelAndClose: true,
closeOnClickModal: false,
customClass: 'confirmDialog',
callback: action => {
if (action == 'confirm') {
this.dialogData = []
// 获取收款测试码
let fetchArr = []
let tilteList = this.editFormData.find(v => v.name == 'applyIds').applyIdsList
this.editForm.applyIds.forEach(val => {
if (val == 'MINIAPP') {
let itemTitle = tilteList.find(v => val == v.appType).appName
fetchArr.push(this.getWeappQrcode(data['MINIAPP'].payMannerId, itemTitle))
}
if (val == 'BIZ') {
let itemTitle = tilteList.find(v => val == v.appType).appName
fetchArr.push(this.getBizQrcode(data['BIZ'].payMannerId, itemTitle))
}
})
return new Promise(resolve => {
Promise.all(fetchArr).then(() => {
this.isShowTestDialog = !this.isShowTestDialog
resolve()
})
})
}
if (action == 'close') {
this.goback()
}
}
})
},
cancelJump() {
this.$router.push({
path: '/seckillActivity/index'
})
},
handleCancel() {
if (this.editStatus) {
this.$confirm('当前有内容信息未保存,是否继续返回?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
this.goback()
})
.catch(() => {})
} else {
this.goback()
}
},
handleTestConfirm() {
this.isShowTestDialog = !this.isShowTestDialog
},
handleConfirmDialogClose() {
this.goback()
},
goback() {
this.$router.go(-1)
},
handleDialogClose() {
this.dialogData = []
this.isShowTestDialog = !this.isShowTestDialog
this.goback()
},
checkValid(validList) {
for (let i = 0; i < validList.length; i++) {
let item = validList[i]
if (item.valid) {
this.whereToGo(Object.keys(item.errorObj)[0])
return false
}
}
return true
},
whereToGo(id) {
document.getElementById(id).scrollIntoView()
},
// 获取微信小程序收款测试码
getWeappQrcode(payMannerId, itemTitle) {
return new Promise((resolve, reject) => {
this.$apis.payMerchantManage
.createWeappQrcodeApi({
appId: 'wxe10067a63c1856ac',
qrcodeType: 'QR_WXA_UNLIMIT',
path: 'pages/crowdfunding/testPayMerchant/testPayMerchant',
scene: `${payMannerId},1`,
channelName: 'DJ'
})
.then(res => {
if (res.code == '0') {
this.dialogData.push({
title: itemTitle,
url: res.data
})
resolve()
} else {
this.$message.error(res.message)
resolve()
}
})
})
},
// 获取公众号收款测试码
getBizQrcode(payMannerId, itemTitle) {
return new Promise((resolve, reject) => {
this.$apis.payMerchantManage
.creatBizQrcodeApi({
payMannerId: payMannerId,
path: this.jumpH5Path
})
.then(res => {
if (res.code == '0') {
this.dialogData.push({
title: itemTitle,
url: res.data
})
resolve()
} else {
this.$message.error(res.message)
resolve()
}
})
})
},
handleCertificateUpload() {},
handleCertificateBeforeUpload(file, targetItem, num) {
this.certificateUpload(file, targetItem, num)
},
// 上传文件
certificateUpload(e, targetItem, num) {
var reader = new FileReader()
var file = e
if (file.name.indexOf('.pem') == -1) {
return this.$message.error('上传的文件格式不对!')
}
// 默认1MB
const limitSize = 1
const isLt = file.size / 1024 / 1024 < limitSize
if (!isLt) {
this.$message.error('上传的文件大小不能超过' + limitSize + 'MB!')
this.fileList = []
return true
}
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.loading = true
this.$apis.payMerchantManage.uploadCertApi({ file: base64 }).then(res => {
if (res.code == '0') {
if (num == 1) {
if (this.fileKeyList.length > 1) this.fileKeyList = []
this.fileKeyList.push({
name: file.name,
url: res.data
})
this.$refs.configEditFormRef.$refs[this.editChildRef].validateField("certificateFile")
}
if (num == 2) {
if (this.fileCertList.length > 1) this.fileCertList = []
this.fileCertList.push({
name: file.name,
url: res.data
})
this.$refs.configEditFormRef.$refs[this.editChildRef].validateField("certificateFile")
}
} else {
this.$message.error(res.message)
}
this.loading = false
})
}
},
// 删除证书文件
delFile(num) {
if (num == 1) {
this.fileKeyList.splice(0, 1)
} else {
this.fileCertList.splice(0, 1)
}
},
// 跳转操作指引
goLinkPage() {
window.open('https://img02.glsx.com.cn/weapp/resource/saas/scrm/pdf/获取证书、密钥操作指引.pdf')
}
}
}
</script>
<style lang="scss" scoped>
.upload-file {
margin: 12px 68px 0 0;
width: 300px;
height: 160px;
border: 1px;
}
.upload-file-content {
display: flex;
justify-content: space-between;
}
.upload-box {
width: 800px;
margin-top: -5px;
}
.tips-text {
font-size: 14px;
color: #999999;
height: 22px;
line-height: 22px;
}
.file-name-box {
display: inline-block;
width: 320px;
height: 24px;
margin-top: 8px;
line-height: 24px;
background: #f5f7fa;
border-radius: 4px;
padding: 0 12px;
margin-right: 10px;
}
</style>
<style lang="scss">
.confirmDialog {
.el-message-box__content {
.el-message-box__container {
.el-message-box__status.el-icon-warning {
color: var(--primaryColor, #5850ff);
}
.el-message-box__message {
padding: 95px 0 0 0;
}
}
}
.el-message-box__btns button:first-child {
color: #fff;
background-color: var(--primaryColor, #5850ff);
border-color: var(--primaryColor, #5850ff);
opacity: 1;
}
.el-message-box__btns button:first-child:hover {
opacity: 0.7;
}
// .el-message-box__btns {
// .el-button--primary {
// color: #fff;
// background-color: var(--primaryColor, #5850ff);
// border-color: var(--primaryColor, #5850ff);
// }
// }
}
.el-upload {
width: 100%;
height: 100%;
background: #f7f7f7;
border: 1px dashed #e5e5e5;
border-radius: 4px;
}
.el-upload-dragger {
border: none;
background: transparent;
height: 100%;
width: 100%;
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
.el-icon-upload {
margin: 0;
}
.el-upload__text {
font-weight: bold;
.tips-upload {
font-size: 14px;
color: #999999;
font-weight: 400;
}
}
}
</style>