index.js
3 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
import { IMG_URL } from '~/utils/constantData'
import MineApi from '~/api/mineApi/index'
import Dialog from '@vant/weapp/dialog/dialog';
Page({
data: {
IMGURL: IMG_URL,
withdrawalScore: 0,
sumbitScore: ''
},
toSumbitData() {
let { sumbitScore,withdrawalScore } = this.data
let isString = typeof sumbitScore == 'string'
if (!sumbitScore) return wx.$api.showToast('请输入有效的积分值')
if (sumbitScore == 0) return wx.$api.showToast('请输入有效的积分值')
if(isString&&sumbitScore.indexOf('.')==(sumbitScore.length-1)) return wx.$api.showToast('请输入有效的积分值')
if(sumbitScore<0.3) return wx.$api.showToast('单次最低提现积分不得低于0.3,请确认后重新申请提现')
if(Number(sumbitScore)>Number(withdrawalScore)) return wx.$api.showToast(`您的积分不足,请确认后重新申请提现`)
Dialog.confirm({
title: '提示',
message: `请确认是否将${sumbitScore}积分进行提现`,
}).then(() => {
wx.$api.showLoading('提交中')
MineApi.WithdrawalApi({ withdrawalScore: sumbitScore }).then(res => {
wx.hideLoading();
if (res.code == 0) {
wx.$eventbus.emit('REFRESH_WITHDRALWAL')
wx.$router.redirectTo('packageMine.withdrawalSuccess.index')
} else {
wx.$api.showToast(res.message)
}
})
}).catch(()=>{
});
},
onRoute(options) {
this.setData({
withdrawalScore: options.withdrawalScore,
user: options.user,
})
},
toFillCount(e) {
let { value } = e.detail
let { withdrawalScore, sumbitScore } = this.data
sumbitScore = this.priceVerify(value, withdrawalScore)
this.setData({
sumbitScore: sumbitScore || ''
})
},
// 失焦校验
checkNum(e) {
let { value } = e.detail
if (value[value.length - 1] == ".") {
this.setData({
sumbitScore: ''
})
}
},
toTixianAll() {
let { withdrawalScore } = this.data
this.setData({
sumbitScore: withdrawalScore
})
},
// 价格输入校验规则(提现积分值:最小值需大于0)
priceVerify(price, max, min = 0) {
let result = 0
// 1.限制小数点为2位
price = price.replace(/[^\d.]/g, "")
price = price.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
// 2.禁止第一位为小数点
if (price.indexOf('.') == 0) {
price = ''
}
// 3.如果第一位是0,那第二位开始禁止为数值,只可以为小数点
if (price.indexOf('0') == 0 && price.length > 1) {
if (price.indexOf('.') != 1) {
price = '0'
}
if (price[2] == '.') {
price = '0.'
}
}
// if (price.indexOf('.') != -1) {
// price = price.slice(0, price.indexOf('.'))
// }
result = price
// 4.判断最大值和最小值
if (price) {
price = Number(price)
max = Number(max)
if (max && price > max) {
result = max
}
if (min && price < min) {
result = min
}
}
return result
}
})