index.vue
21.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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
<template>
<div class="equity-wrap">
<div class="equity-wrap contain">
<GLCombiForm ref="showSearch" :formObj="detailForm" :formData="detailFormData" @handleOk="detailSelect('select')" @handleRest="detailSelect('reset')">
<div slot="codeSlot">
<el-select v-model="detailForm.packageCode" remote reserve-keyword
@visible-change="visibleChangePackageCode" :remote-method="remoteMethodPackageCode"
v-el-select-loadmore="interestsLoadmore" clearable filterable>
<el-option v-for="(subItem, subIndex) in codeTypeList" :key="subIndex"
:label="subItem.packageName" :value="subItem.packageCode" />
</el-select>
</div>
</GLCombiForm>
<el-alert :closable="false" type="info" show-icon>总计{{ line.total }}张,已使用{{ line.usedAmount }}张</el-alert>
<GLTable ref="detailTable" :searchForm="detailForm" :tableParams="detailParams" :pageConf="detailPageConf" :getListApi="getDetailList" :beforeSearchFn="check" style="margin-top: 10px">
<span slot="auth-button" slot-scope="scope" :data="scope.scope">
<!-- <el-button type="text" @click="modify(scope.scope)" :disabled="scope.scope.status">修改</el-button> -->
<GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
</span>
</GLTable>
</div>
<!-- 详情弹窗 -->
<GLDialog class="gl-form-page gl-form-min" title="修改无忧卡" v-if="detailDialog" :visible.sync="detailDialog" mode="mid" :before-close="handleClose" @onOk="submitForm('detailForm')" @onCancel="cancelDetailDialog">
<glsx-combi-form ref="product" labelWidth="154px" defaultWidth="284px" formRef="detailForm" :formObj="detailDialogForm" :formData="addDialogFormData" :formRules="detailDialogRules">
<div slot="codeSlotDialog">
<el-select v-model="detailDialogForm.packageCode" remote reserve-keyword
@visible-change="visibleDialogChangePackageCode" :remote-method="remoteMethodDialogPackageCode"
v-el-select-loadmore-dialog="interestsLoadmoreDialog" clearable filterable>
<el-option v-for="(subItem, subIndex) in dialogCodeTypeList" :key="subIndex"
:label="subItem.packageName" :value="subItem.packageCode" />
</el-select>
</div>
</glsx-combi-form>
</GLDialog>
</div>
</template>
<script type="text/ecmascript-6">
import glsxCombiForm from '@/components/glsx-combi-form'
function date_format(date) {
var date2 = new Date(date)
var YY = date2.getFullYear() + '-'
var MM = (date2.getMonth() + 1 < 10 ? '0' + (date2.getMonth() + 1) : date2.getMonth() + 1) + '-'
var DD = date2.getDate() < 10 ? '0' + date2.getDate() : date2.getDate()
var hh = (date2.getHours() < 10 ? '0' + date2.getHours() : date2.getHours()) + ':'
var mm = (date2.getMinutes() < 10 ? '0' + date2.getMinutes() : date2.getMinutes()) + ':'
var ss = date2.getSeconds() < 10 ? '0' + date2.getSeconds() : date2.getSeconds()
return YY + MM + DD + ' ' + hh + mm + ss
}
const validatorActualPrice = (rule, value, callback) => {
if (value) {
var reg = /^[1-9]\d*$/
if (reg.test(value)) {
if (value > 200) {
callback('请输入200万以内的价格')
} else {
callback()
}
} else {
callback('请输入正整数')
}
} else {
callback('请输入具体价格')
}
}
export default {
name: '',
components: {
glsxCombiForm
},
data() {
return {
date_format,
buttonList: [
{
type: 'el-button',
name: row => {
return '修改'
},
attrs: {
type: 'text',
disabled: row => {
return row.scope.status
}
},
listeners: {
click: row => this.modify(row.scope)
}
},
{
type: 'el-button',
name: row => {
return '恢复未使用'
},
attrs: {
type: 'text'
},
condition: row => {
return row.scope.status == 1
},
listeners: {
click: row => this.clearStatus(row.scope)
}
}
],
line: {
total: '',
usedAmount: ''
},
getDetailList: this.$apis.worryDetailApi.getWorryDetailList,
detailDialog: false,
detailPageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
detailForm: {
seqNo: '',
batchType: '',
packageCode: '',
servicePeriod: '',
actualPrice: '',
status: '',
cardNumber: ''
},
detailFormData: [
{
type: 'input',
label: '序列号',
name: 'seqNo',
isClear: true
},
{
type: 'input',
label: '卡编号',
name: 'cardNumber',
isClear: true
},
{
label: '版本',
name: 'batchType',
type: 'select',
isClear: true,
optionList: [
{
confId: '',
confName: '全部'
},
{
confId: '1',
confName: '尊享版'
},
{
confId: '2',
confName: '畅享版'
}
],
optionId: 'confId',
optionLabel: 'confName'
},
{
label: '适用类型',
name: 'packageCode',
addHtml: 'codeSlot'
},
{
label: '状态',
name: 'status',
isClear: true,
type: 'select',
optionList: [
{
confId: '',
confName: '全部'
},
{
confId: '0',
confName: '未使用'
},
{
confId: '1',
confName: '已使用'
}
],
optionId: 'confId',
optionLabel: 'confName'
},
{
type: 'input',
label: '具体价格',
name: 'actualPrice',
isClear: true
},
{
label: '使用年限',
name: 'servicePeriod',
type: 'select',
isClear: true,
optionList: [
{
confId: '',
confName: '全部'
},
{
confId: '1',
confName: '1年'
},
{
confId: '2',
confName: '2年'
},
{
confId: '3',
confName: '3年'
},
{
confId: '4',
confName: '4年'
},
{
confId: '5',
confName: '5年'
}
],
optionId: 'confId',
optionLabel: 'confName'
}
],
detailDialogForm: {
batchType: '',
packageCode: '',
actualPrice: '',
servicePeriod: ''
},
addDialogFormData: [
{
label: '版本',
name: 'batchType',
type: 'select',
optionList: [
{
value: '1',
label: '尊享版'
},
{
value: '2',
label: '畅享版'
}
],
optionId: 'value',
optionLabel: 'label'
},
{
label: '适用类型',
name: 'packageCode',
addHtml: 'codeSlotDialog'
},
{
type: 'input',
label: '具体价格/万',
name: 'actualPrice',
isClear: true
},
{
label: '使用年限',
name: 'servicePeriod',
type: 'select',
isClear: true,
optionList: [
{
value: '1',
label: '1年'
},
{
value: '2',
label: '2年'
},
{
value: '3',
label: '3年'
},
{
value: '4',
label: '4年'
},
{
value: '5',
label: '5年'
}
],
optionId: 'value',
optionLabel: 'label'
}
],
editOptions: [
{
value: '',
label: '全部'
},
{
value: '1',
label: '尊享版'
},
{
value: '2',
label: '畅享版'
}
],
typeOptions: [
{
value: '',
label: '全部'
},
{
value: 'PC0005',
label: '盗抢全损无忧'
},
{
value: 'PC0006',
label: '轮胎无忧'
},
{
value: 'PC0007',
label: '整车全损无忧'
},
{
value: 'PC0008',
label: '碰撞无忧'
}
],
statusOptions: [
{
value: '',
label: '全部'
},
{
value: '0',
label: '未使用'
},
{
value: '1',
label: '已使用'
}
],
lifeOptions: [
{
value: '',
label: '全部'
},
{
value: '1',
label: '1年'
},
{
value: '2',
label: '2年'
},
{
value: '3',
label: '3年'
},
{
value: '4',
label: '4年'
},
{
value: '5',
label: '5年'
}
],
dialogEditOptions: [
{
value: '1',
label: '尊享版'
},
{
value: '2',
label: '畅享版'
}
],
dialogTypeOptions: [
{
value: 'PC0005',
label: '盗抢全损无忧'
},
{
value: 'PC0006',
label: '轮胎无忧'
},
{
value: 'PC0007',
label: '整车全损无忧'
},
{
value: 'PC0008',
label: '碰撞无忧'
}
],
dialogYearOptions: [
{
value: '1',
label: '1年'
},
{
value: '2',
label: '2年'
},
{
value: '3',
label: '3年'
}
],
detailDialogRules: {
batchType: [{ required: true, message: '请选择版本', trigger: 'change' }],
packageCode: [{ required: true, message: '请选择适用类型', trigger: 'change' }],
actualPrice: [{ validator: validatorActualPrice, trigger: 'blur' }],
servicePeriod: [{ required: true, message: '请选择适用年限', trigger: 'change' }]
},
detailParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list',
tableOption: {
width: 150
},
tableColumns: [
{
label: '卡编号',
prop: 'cardNumber',
width: 180
},
{
label: '序列号',
prop: 'seqNo',
width: 100
},
{
label: '版本',
prop: 'batchType',
formatter: cellValue => {
return {
1: '尊享版',
2: '畅享版'
}[cellValue.batchType]
}
},
{
label: '状态',
prop: 'status',
formatter: cellValue => {
return {
0: '未使用',
1: '已使用'
}[cellValue.status]
}
},
{
label: '适用类型',
prop: 'packageName',
width: 220
},
{
label: '使用时间',
prop: 'useDate',
formatter: cellValue => {
if (cellValue.useDate) {
return this.date_format(cellValue.useDate)
} else {
return ''
}
},
width: 220
},
{
label: '使用者',
prop: 'useMerchantName',
line: 1,
width: 200
},
{
label: '使用年限',
prop: 'servicePeriod',
width: 100
},
{
label: '具体价格',
prop: 'actualPrice',
width: 100
}
]
},
pageNum: 1,
pageSize: 20,
dialogPageNum: 1,
codeTypeList: [],
dialogCodeTypeList: []
}
},
directives: {
"el-select-loadmore": {
bind(el, binding) {
let triggered = false
const threshold = 50
const debounceTime = 300 // 防抖时间
const waitForDropdown = () => {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
if (SELECTWRAP_DOM) {
SELECTWRAP_DOM.addEventListener('scroll', function() {
const scrollBottom = this.scrollHeight - this.scrollTop - this.clientHeight
if (scrollBottom <= threshold && !triggered) {
triggered = true
binding.value() // 执行加载更多
// 无论是否是异步操作,都延迟重置
setTimeout(() => {
triggered = false
}, debounceTime)
}
})
}
}
waitForDropdown()
}
},
"el-select-loadmore-dialog": {
bind(el, binding) {
let isTriggered = false
const debounceTime = 300 // 防抖时间
const waitForDropdown = () => {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
if (SELECTWRAP_DOM) {
SELECTWRAP_DOM.addEventListener('scroll', function() {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 1
if (condition && !isTriggered) {
isTriggered = true
binding.value()
// 延迟重置触发状态
setTimeout(() => {
isTriggered = false
}, debounceTime)
}
})
} else {
// 如果没有找到下拉框DOM,延迟重试
setTimeout(waitForDropdown, 50)
}
}
waitForDropdown()
}
}
},
mounted() {
this.getTotal()
this.getTypelist()
},
methods: {
/**筛选条件适用类型开始 */
getTypelist() {
this.$apis.addWorryFree.getTypelistApi({
pageNum: this.pageNum,
pageSize: this.pageSize,
packageName: this.packageNameKeyword
}).then(res => {
let arr = this.codeTypeList.concat(res.list)
this.allPages = res.page
this.codeTypeList = arr
if (!this.codeTypeList?.find(val => val.packageCode == '' && val.packageName == '全部')) this.codeTypeList.unshift({ packageCode: '', packageName: '全部' })
})
},
interestsLoadmore() {
setTimeout(() => {
this.pageNum = this.pageNum + 1
if (this.allPages < this.pageNum) {
this.pageNum = this.allPages
return
}
this.getTypelist()
}, 10)
},
remoteMethodPackageCode(query) {
this.packageNameKeyword = query
this.pageNum = 1
this.codeTypeList = []
this.getTypelist() // 请求接口
},
visibleChangePackageCode(data) {
// 获取焦点重新渲染下拉框数据
if (data) {
if (this.packageNameKeyword) {
this.packageNameKeyword = ""
this.pageNum = 1
this.codeTypeList = []
this.getTypelist()
}
}
},
/**筛选条件适用类型结束 */
/**修改弹窗适用类型开始 */
getDialogTypeList(defaultSelect) {
this.$apis.addWorryFree.getTypelistApi({
pageNum: this.dialogPageNum,
pageSize: this.pageSize,
packageName: this.dialogPackageNameKeyword
}).then(res => {
let arr = this.dialogCodeTypeList.concat(res.list)
this.dialogAllPages = res.page
if (defaultSelect?.length) arr = defaultSelect.concat(arr)
this.dialogCodeTypeList = this.unique(arr)
})
},
// 根据packageCode去重
unique(arr) {
const res = new Map()
return arr.filter(
(a) => !res.has(a.packageCode) && res.set(a.packageCode, 1)
)
},
interestsLoadmoreDialog() {
setTimeout(() => {
this.dialogPageNum = this.dialogPageNum + 1
if (this.dialogAllPages < this.dialogPageNum) {
this.dialogPageNum = this.dialogAllPages
return
}
this.getDialogTypeList()
}, 10)
},
remoteMethodDialogPackageCode(query) {
this.dialogPackageNameKeyword = query
this.dialogAllPages = 1
this.dialogCodeTypeList = []
this.getDialogTypeList() // 请求接口
},
visibleDialogChangePackageCode(data) {
// 获取焦点重新渲染下拉框数据
if (data) {
if (this.dialogPackageNameKeyword) {
this.dialogPackageNameKeyword = ""
this.dialogPageNum = 1
this.dialogCodeTypeList = []
this.getDialogTypeList()
}
}
},
/**修改弹窗适用类型结束 */
// changePgCode(e){
// const arr = [{
// value: '1',
// label: '1年'
// },
// {
// value: '2',
// label: '2年'
// },
// {
// value: '3',
// label: '3年'
// }]
// const moreArr = [{
// value: '4',
// label: '4年'
// },
// {
// value: '5',
// label: '5年'
// }]
// const target = this.addDialogFormData.find(item => item.name=='servicePeriod')
// target.optionList = (e=='PC0005' || e=='PC0007') ? [ ...arr, ...moreArr] : [...arr]
// this.detailDialogForm.servicePeriod = ''
// },
check() {
return new Promise((resolve, reject) => {
var reg = /^[+]{0,1}(\d+)$/g
if (this.detailForm.actualPrice) {
if (!reg.test(this.detailForm.actualPrice)) {
this.$message.error('请输入1-200的数字')
reject()
} else if (this.detailForm.actualPrice > 200) {
this.$message.error('请输入1-200的数字')
reject()
}
}
resolve()
})
},
//获取详情总数
getTotal() {
this.$apis.worryDetailApi.getdetailTotal({}).then(res => {
this.line = res
})
},
// 详情table搜索
detailSelect(e) {
if (e == 'reset') {
this.detailForm = {
seqNo: '',
batchType: '',
packageCode: '',
servicePeriod: '',
actualPrice: '',
status: ''
}
// this.detailForm = {}
this.$refs.detailTable.refreshTable()
// this.detailForm.batchType = ''
// this.detailForm.packageCode = ''
// this.detailForm.status = ''
// this.detailForm.servicePeriod = ''
} else if (e == 'select') {
this.$refs.detailTable.refreshTable()
}
},
modify(e) {
// this.changePgCode(e.packageCode)
let obj = JSON.parse(JSON.stringify(e))
this.detailDialog = true
obj.servicePeriod = obj.servicePeriod + ''
this.detailDialogForm = obj
if (obj.batchType == '1') {
this.detailDialogForm.batchType = '尊享版'
} else {
this.detailDialogForm.batchType = '畅享版'
}
let defaultArr = [{ packageCode: obj.packageCode, packageName: obj.packageName }]
this.dialogCodeTypeList = []
this.dialogPageNum = 1
this.getDialogTypeList(defaultArr)
},
// 清空无忧卡使用状态
clearStatus(row) {
this.$apis.worryDetailApi.clearWorryStatus({ id: row.id }).then(res => {
console.log(res)
if (res.code == '0') {
this.$message({
message: '操作成功',
type: 'success'
})
this.$refs.detailTable.refreshTable()
} else {
this.$message({
message: '操作失败',
type: 'error'
})
}
})
},
// 详情table搜索回调方法
detailFormat() {},
// 关闭弹窗界面
cancelDetailDialog() {
this.detailDialog = false
this.detailDialogForm = {}
},
submitForm(formName) {
this.$refs.product.$refs[formName].validate(valid => {
if (valid) {
if (this.detailDialogForm.batchType == '尊享版') {
this.detailDialogForm.batchType = '1'
} else if (this.detailDialogForm.batchType == '畅享版') {
this.detailDialogForm.batchType = '2'
}
console.log(this.detailDialogForm.batchType)
this.$apis.worryDetailApi.modWorryDetailList(this.detailDialogForm).then(res => {
if (res.code == '0') {
this.$message({
message: '操作成功',
type: 'success'
})
this.detailDialog = false
this.detailDialogForm = {}
this.$refs.detailTable.refreshTable()
} else {
this.$message({
message: '新增失败',
type: 'error'
})
}
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.equity-wrap {
}
.addGood {
margin-bottom: 20px;
margin-left: 40px;
padding: 8px 16px;
}
.row-btns {
margin-top: 5px;
margin-bottom: 10px;
}
/deep/ .el-alert {
height: 40px;
background: #e6e9ff;
border: 1px solid #5850ff;
padding: 0 15px;
line-height: 40px;
p {
font-size: 14px;
color: rgba(0, 0, 0, 0.65);
}
.el-alert__description {
margin: 0;
}
.el-alert__icon {
color: #5850ff;
font-size: 18px;
width: 18px;
}
}
/deep/ .el-pagination {
margin-top: 20px;
}
</style>