|
@@ -505,22 +505,36 @@ Page({ |
|
@@ -505,22 +505,36 @@ Page({ |
|
505
|
})
|
505
|
})
|
|
506
|
},
|
506
|
},
|
|
507
|
// 筛选出合适的充值优惠
|
507
|
// 筛选出合适的充值优惠
|
|
508
|
- findClosest (list,price){
|
|
|
|
509
|
- let i=0;
|
|
|
|
510
|
- let changzhi=0;
|
|
|
|
511
|
- list.forEach((item,index)=>{
|
|
|
|
512
|
- if (index==0) {
|
|
|
|
513
|
- changzhi=Math.abs(price*1-item.recharge_money*1)
|
|
|
|
514
|
- i=index
|
|
|
|
515
|
- }else{
|
|
|
|
516
|
- if (changzhi*1-Math.abs((price*1-item.recharge_money*1))>0) {
|
|
|
|
517
|
- changzhi=Math.abs(price*1-item.recharge_money*1)
|
|
|
|
518
|
- i=index
|
|
|
|
519
|
- }
|
|
|
|
520
|
- }
|
|
|
|
521
|
- })
|
|
|
|
522
|
- return list[i]
|
|
|
|
523
|
- },
|
508
|
+ findClosest(list, price) {
|
|
|
|
509
|
+ if (list.length == 0) {
|
|
|
|
510
|
+ return false
|
|
|
|
511
|
+ }
|
|
|
|
512
|
+ list.sort((i, t) => i.recharge_money - t.recharge_money)
|
|
|
|
513
|
+ let min = Math.abs(list[0].recharge_money - price) // 最小差值
|
|
|
|
514
|
+ let cur = 0 // 当前值
|
|
|
|
515
|
+ let isMax1001 = false
|
|
|
|
516
|
+ list.forEach(item => {
|
|
|
|
517
|
+ item.recharge_money = item.recharge_money * 1
|
|
|
|
518
|
+ if (item.recharge_money >= price) {
|
|
|
|
519
|
+ if (!isMax1001) {
|
|
|
|
520
|
+ min = Math.abs(item.recharge_money - price)
|
|
|
|
521
|
+ cur = item
|
|
|
|
522
|
+ isMax1001 = true
|
|
|
|
523
|
+ } else {
|
|
|
|
524
|
+ if (Math.abs(item.recharge_money - price) <= min) {
|
|
|
|
525
|
+ min = Math.abs(item.recharge_money - price)
|
|
|
|
526
|
+ cur = item
|
|
|
|
527
|
+ }
|
|
|
|
528
|
+ }
|
|
|
|
529
|
+ } else {
|
|
|
|
530
|
+ if (Math.abs(item.recharge_money - price) <= min) {
|
|
|
|
531
|
+ min = Math.abs(item.recharge_money - price)
|
|
|
|
532
|
+ cur = item
|
|
|
|
533
|
+ }
|
|
|
|
534
|
+ }
|
|
|
|
535
|
+ })
|
|
|
|
536
|
+ return cur;
|
|
|
|
537
|
+ },
|
|
524
|
/**
|
538
|
/**
|
|
525
|
* 用户点击右上角分享
|
539
|
* 用户点击右上角分享
|
|
526
|
*/
|
540
|
*/
|