chargemoney.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/chargemoney/chargemoney.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. chargemoney_select: null,
  8. userInfo: {},
  9. isLogin: false
  10. },
  11. bindMoneyTap(e) {
  12. let chargemoney_select = e.currentTarget.id;
  13. this.setData({
  14. chargemoney_select
  15. });
  16. },
  17. saveMoney(e) {
  18. //console.log(e);
  19. let chargemoney_select = e.detail.value;
  20. this.setData({
  21. chargemoney_select
  22. });
  23. },
  24. beginChargemoney(e) {
  25. //console.log(this.data.chargemoney_select);
  26. let that = this;
  27. if (this.data.chargemoney_select) {
  28. wx.showLoading({
  29. title: '充值中...',
  30. mask: true
  31. });
  32. wx.login({
  33. success(res) {
  34. console.log(res);
  35. if (res.code) {
  36. // 发起网络请求
  37. wx.request({
  38. url: getApp().globalData.postHeadAgreement +'://cdgl.xinyhy.cn/restapi/wechatpay/dopaychargmoney',
  39. data: {
  40. //outTradeNo: new Date().getTime(), //订单号
  41. totalFee: that.data.chargemoney_select, //钱
  42. //totalFee:0.01,
  43. code: res.code
  44. },
  45. header: {
  46. 'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
  47. },
  48. method: 'POST',
  49. success(res1) {
  50. //console.log(res1);
  51. wx.requestPayment({
  52. timeStamp: res1.data.timeStamp,
  53. nonceStr: res1.data.nonceStr,
  54. package: res1.data.package,
  55. signType: res1.data.signType,
  56. paySign: res1.data.paySign,
  57. success(res2) {
  58. console.log(res2);
  59. wx.request({
  60. url: getApp().globalData.postHeadAgreement +'://cdgl.xinyhy.cn/restapi/pileLog/wechatrechargeback',
  61. data: {
  62. userId: that.data.userInfo.userId,
  63. rechargeMoney: that.data.chargemoney_select
  64. //rechargeMoney: 0.01,
  65. },
  66. method: 'POST',
  67. success(res3) {
  68. wx.hideLoading();
  69. let {
  70. data
  71. } = res3;
  72. if (data && data.code == 200) {
  73. wx.showModal({
  74. showCancel: false,
  75. content: '充值成功'
  76. });
  77. } else {
  78. wx.showModal({
  79. showCancel: false,
  80. content: '充值失败'
  81. });
  82. }
  83. }
  84. });
  85. },
  86. fail(res3) {
  87. wx.hideLoading();
  88. console.log(res3);
  89. }
  90. });
  91. }
  92. });
  93. } else {
  94. wx.hideLoading();
  95. console.log('登录失败!' + res.errMsg)
  96. }
  97. }
  98. })
  99. }
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function(options) {
  105. let userInfo = wx.getStorageSync('userInfo');
  106. let isLogin = wx.getStorageSync('isLogin');
  107. // 页面显示
  108. if (userInfo && isLogin) {
  109. //console.log(userInfo);
  110. //userInfo.flag = true;
  111. this.setData({
  112. userInfo: userInfo,
  113. isLogin: isLogin
  114. });
  115. }
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady: function() {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function() {
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide: function() {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function() {
  136. },
  137. /**
  138. * 页面相关事件处理函数--监听用户下拉动作
  139. */
  140. onPullDownRefresh: function() {
  141. },
  142. /**
  143. * 页面上拉触底事件的处理函数
  144. */
  145. onReachBottom: function() {
  146. },
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function() {
  151. }
  152. })