toCash.js
6.13 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
// integration/pages/point/toCash/toCash.js
import MineApi from '../../../api'
import api from '~/api/api'
import Dialog from '@vant/weapp/dialog/dialog';
Page({
data: {
sumbitScore: '',
showRate: false,
showModal: false,
tabData: ['阳光激励兑换', '微信兑换'],
tabIndex: 0,
user: {}
},
onLoad() {
this.getStaffInfo();
},
tabClick(e) {
let {
tabData,
score
} = this.data
this.setData({
tabIndex: e.detail,
sumbitScore: tabData[e.detail] != '阳光激励兑换' ? score.wechatMotivationWithdrawalScore : score?.motivationWithdrawalScore
})
},
toShowBindModal(e) {
const {
name
} = e.detail
this.setData({
[name]: true
})
},
toCloseModal(e) {
const {
name
} = e.currentTarget.dataset
this.setData({
[name]: false
});
},
async toBindWechat(e) {
let _this = this
if (e.detail.errMsg === "getPhoneNumber:ok") {
wx.$util.showLoading();
wx.login({
success({
code
}) {
if (code) {
console.log(code,wx.getAccountInfoSync().miniProgram.appId)
api
.ssoLogin({
code,
appId: wx.getAccountInfoSync().miniProgram.appId
})
.then(res => {
if (res.code == '0') {
let {
user
} = _this.data;
let para = {
staffUuid: user.staffUuid,
openId: res.data.openId,
appId: wx.getAccountInfoSync().miniProgram.appId
}
MineApi.wechatBindApi(para).then((res) => {
if (res.code == 0) {
wx.$util.showToast('绑定成功')
_this.getStaffInfo();
}
});
}
})
} else {
wx.$util.showToast('登录失败')
}
}
})
}
},
getStaffInfo() {
const userStorage = wx.$util.getUserInfo()
let para = {
staffUuid: userStorage.uuid,
};
MineApi.getStaffDetailApi(para).then((res) => {
wx.hideLoading();
const temp = this.handleUserInfo(res.data)
this.setData({
user: temp
})
});
},
handleUserInfo(data) {
const userStorage = wx.$util.getUserInfo()
const USERINFO = {
...data,
staffUuid: userStorage.uuid,
};
return USERINFO;
},
toSumbitData() {
if (this.submit) return wx.$api.showToast('有一笔兑换正在进行')
let {
sumbitScore,
tabIndex,
user,
score: {
existWechatMotivationWithdrawal
},
rateInfo,
tabData,
} = this.data
let withDrawType = 3
let rateQuery = {}
const money = this.accSub(Number(sumbitScore), 0)
if (tabData[tabIndex] == '微信兑换' && !user?.openId) { // 微信兑换方式未绑定微信提示
this.setData({
showModal: true
})
return
}
if (existWechatMotivationWithdrawal && tabData[tabIndex] == '微信兑换') {
withDrawType = 4
}
if (money <= 0) return wx.$api.showToast(`您的积分不足,请确认后重新申请兑换`)
// if(rateInfo){
// rateQuery = {
// withdrawalRate:rateInfo,
// arrivedAmount:money
// }
// this.tixianQuery = {
// sumbitScore,
// withDrawType,
// rateQuery
// }
// this.toShowModal(sumbitScore)
// return
// }
this.comfirmSumbit(sumbitScore, withDrawType)
},
// 提现确认模块
comfirmSumbit(sumbitScore, withDrawType, rateQuery = {}) {
let {
tabIndex,
tabData,
} = this.data;
Dialog.confirm({
title: '提示',
message: `请确认是否将${sumbitScore}积分进行兑换`,
}).then(() => {
if (this.submit) return
this.submit = true
wx.$api.showLoading('提交中')
MineApi.WithdrawalApi({
withdrawalScore: sumbitScore,
withDrawType,
withdrawalSource: 2,
wechatAppId: wx.getAccountInfoSync().miniProgram.appId,
sourceFrom: 1 // 来源 0:活动 1:阳光激励
}).then(res => {
wx.hideLoading();
if (res.code == 0) {
wx.$router.redirectTo(`integration.success`, {
title: tabData[tabIndex]
})
} else {
wx.$api.showToast(res.message)
this.submit = false
}
}).catch((err) => {
wx.$api.showToast(JSON.stringify(err))
this.submit = false
})
}).catch(() => {
this.submit = false
});
},
onRoute(options) {
console.log(options)
let {
tabData
} = this.data
if (!options.score.existWechatMotivationWithdrawal) {
tabData.findIndex(v => v == '微信兑换') > -1 && tabData.splice(tabData.findIndex(v => v == '微信兑换'), 1)
}
this.setData({
tabData,
score: options.score,
sumbitScore: options?.score?.motivationWithdrawalScore
})
},
/**添加手续费提示 */
toShowModal(sumbitScore) {
const Rate = Number(this.data.rateInfo)
const money = this.accSub(Number(sumbitScore), (Number(sumbitScore) * Rate))
const obj = {
count: sumbitScore,
money: money,
rate: `${Rate*100}%`
}
this.setData({
showRate: true,
rateMoney: obj
})
},
/**获取手续费 */
getRateInfo() {
const userStorage = wx.$storage.get("userInfo");
MineApi.getRate({
merchantId: userStorage.merchantId
}).then(res => {
this.setData({
rateInfo: res
})
})
},
toJump() {
this.comfirmSumbit(this.tixianQuery.sumbitScore, this.tixianQuery.withDrawType, this.tixianQuery.rateQuery)
},
accSub(arg1, arg2) {
let r1, r2, m, n;
try {
r1 = arg1.toString().split(".")[1].length;
} catch (e) {
r1 = 0;
}
try {
r2 = arg2.toString().split(".")[1].length;
} catch (e) {
r2 = 0;
}
m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
n = (r1 >= r2) ? r1 : r2;
return ((arg1 * m - arg2 * m) / m).toFixed(n);
}
})