deguodaigou/pages/yue/yue.js
2019-12-30 08:40:11 +08:00

103 lines
2.3 KiB
JavaScript

import bin from "../../utils/bin"
Page({
data: {
money: "",
list: [],
number: 0,
show:false
},
onLoad(a) {
bin.request({
url: "User/validateOpenid"
}).then((res) => {
console.log(res)
if (res.data.code == 200) {
this.setData({
money: res.data.data.user_money
})
}
})
bin.getuserid().then((userid) => {
bin.request({
url: "User/account",
urldata: {
user_id: userid,
page: 0
}
}).then((res) => {
console.log(res)
for (let i in res.data.result) {
let linshi = res.data.result[i].change_time.split(" ")
res.data.result[i].date = linshi[0]
res.data.result[i].time = linshi[1]
}
this.setData({
list: res.data.result
})
})
})
},
number(a) {
console.log(a)
this.setData({
number: a.detail.value
})
},
recharge(){
if(this.data.number == 0){
wx.showToast({
title:"请输入充值金额",
icon:"none"
})
}else{
bin.getuserid().then((id)=>{
bin.request({
url:"User/user_recharge",
data:{
user_id:id,
account:this.data.number
}
}).then((res)=>{
let t =this;
console.log(res);
wx.requestPayment({
timeStamp:res.data.result.wdata.timeStamp + "",
nonceStr:res.data.result.wdata.nonceStr,
package:res.data.result.wdata.package,
signType: res.data.result.wdata.signType,
paySign:res.data.result.wdata.sign,
success(res){
// console.log(res)
wx.showToast({
title:"充值成功",
icon:"none"
})
t.setData({
show:false
})
t.onLoad()
},
fail(err){
wx.showToast({
title:"充值失败",
icon:"none"
})
}
})
})
})
}
},
showrecharge(){
console.log(123)
this.setData({
show:true
})
},
onClose(){
this.setData({
show:false
})
}
})