outmoney.js 3.6 KB

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