trans.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // pages/trans/trans.js
  2. const app = getApp()
  3. const link = app.globalData.url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. openId:"",
  10. amount:"",
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. var that = this
  17. that.openId = wx.getStorageSync('openId')
  18. console.log(that.openId)
  19. wx.request( {
  20. url: link + "/v1/forward/lhf",
  21. header: {
  22. "Content-Type": "application/json",
  23. "function":"/v1/user/trans/list"
  24. },
  25. method: "POST",
  26. data: { openId: that.openId,pidStatus:1,pageIndex:1,pageSize:999 },
  27. complete: function( res ) {
  28. console.log(res)
  29. if( res == null || res.data == null ) {
  30. console.error( '网络请求失败' );
  31. return;
  32. }
  33. that.setData({
  34. transList: res.data.data.rows,
  35. })
  36. }
  37. })
  38. },
  39. tixian:function (){
  40. var that = this
  41. wx.showModal({
  42. title: '提现',
  43. content: '提现金额:'+that.amount,
  44. showCancel: true,//是否显示取消按钮
  45. cancelText:"取消",//默认是“取消”
  46. //cancelColor:'skyblue',//取消文字的颜色
  47. confirmText:"提现",//默认是“确定”
  48. //confirmColor: 'skyblue',//确定文字的颜色
  49. success: function (res) {
  50. if (res.cancel) {
  51. //点击取消,默认隐藏弹框
  52. } else {
  53. wx.request( {
  54. url: link + "/v1/forward/lhf",
  55. header: {
  56. "Content-Type": "application/json",
  57. "function":"/v1/user/trans/create"
  58. },
  59. method: "POST",
  60. data: { openId: that.openId,amount:that.amount,pidStatus:1 },
  61. complete: function( res ) {
  62. console.log(res)
  63. if( res == null || res.data == null ) {
  64. console.error( '网络请求失败' );
  65. return;
  66. }
  67. if (res.data.code == 401){
  68. wx.navigateTo({
  69. url:"/pages/pay/pay"
  70. })
  71. return
  72. }
  73. that.openId = wx.getStorageSync('openId')
  74. console.log(that.openId)
  75. wx.request( {
  76. url: link + "/v1/forward/lhf",
  77. header: {
  78. "Content-Type": "application/json",
  79. "function":"/v1/user/trans/get"
  80. },
  81. method: "POST",
  82. data: { openId: that.openId,pidStatus:1 },
  83. complete: function( res ) {
  84. console.log(res)
  85. if( res == null || res.data == null ) {
  86. console.error( '网络请求失败' );
  87. return;
  88. }
  89. that.amount = res.data.data.wallet.availableAmount
  90. that.setData({
  91. wallet: res.data.data,
  92. })
  93. }
  94. })
  95. }
  96. })
  97. }
  98. },
  99. fail: function (res) { },//接口调用失败的回调函数
  100. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  101. })
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady: function () {
  107. },
  108. /**
  109. * 编辑
  110. */
  111. update:function () {
  112. wx.navigateTo({
  113. url:"/pages/pay/pay"
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. var that = this
  121. that.openId = wx.getStorageSync('openId')
  122. console.log(that.openId)
  123. wx.request( {
  124. url: link + "/v1/forward/lhf",
  125. header: {
  126. "Content-Type": "application/json",
  127. "function":"/v1/user/trans/get"
  128. },
  129. method: "POST",
  130. data: { openId: that.openId,pidStatus:1 },
  131. complete: function( res ) {
  132. console.log(res)
  133. if( res == null || res.data == null ) {
  134. console.error( '网络请求失败' );
  135. return;
  136. }
  137. that.amount = res.data.data.wallet.availableAmount
  138. that.setData({
  139. wallet: res.data.data,
  140. })
  141. }
  142. })
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload: function () {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh: function () {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. }
  169. })