payment.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/mall/payment/payment.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userinfo:[],
  9. now_money:0,
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. app.setBarColor();
  16. app.setUserInfo();
  17. this.getUserInfo();
  18. },
  19. getUserInfo:function(){
  20. var that = this;
  21. wx.request({
  22. url: app.globalData.url + '/routine/auth_api/get_user_info?uid=' + app.globalData.uid,
  23. method: 'GET',
  24. success: function (res) {
  25. that.setData({
  26. userinfo: res.data.data,
  27. now_money: res.data.data.now_money
  28. })
  29. }
  30. })
  31. },
  32. submitSub:function(e){
  33. var that = this;
  34. wx.request({
  35. url: app.globalData.url + '/routine/auth_api/get_form_id?uid=' + app.globalData.uid,
  36. method: 'GET',
  37. data: {
  38. formId: e.detail.formId
  39. },
  40. success: function (res) { }
  41. })
  42. if (!e.detail.value.number) {
  43. wx.showToast({
  44. title: '请输入充值金额',
  45. icon: 'none',
  46. duration: 1000,
  47. })
  48. return false;
  49. }
  50. wx.request({
  51. url: app.globalData.url + '/routine/auth_api/user_wechat_recharge?uid=' + app.globalData.uid,
  52. method: 'GET',
  53. data: {
  54. price: e.detail.value.number
  55. },
  56. success: function (res) {
  57. var jsConfig = res.data.data;
  58. if (res.data.code == 200) {
  59. wx.requestPayment({
  60. timeStamp: jsConfig.timeStamp,
  61. nonceStr: jsConfig.nonceStr,
  62. package: jsConfig.package,
  63. signType: jsConfig.signType,
  64. paySign: jsConfig.paySign,
  65. success: function (res) {
  66. wx.showToast({
  67. title: '支付成功',
  68. icon: 'success',
  69. duration: 1000,
  70. })
  71. that.setData({
  72. now_money: parseInt(that.data.now_money) + parseInt(e.detail.value.number)
  73. });
  74. setTimeout(function () {
  75. wx.navigateTo({
  76. url: '/pages/main/main?now=' + that.data.now_money + '&uid=' + app.globalData.uid,
  77. })
  78. }, 1200)
  79. },
  80. fail: function (res) {
  81. wx.showToast({
  82. title: '支付失败',
  83. icon: 'success',
  84. duration: 1000,
  85. })
  86. },
  87. complete: function (res) {
  88. if (res.errMsg == 'requestPayment:cancel') {
  89. wx.showToast({
  90. title: '取消支付',
  91. icon: 'none',
  92. duration: 1000,
  93. })
  94. }
  95. },
  96. })
  97. }else{
  98. wx.showToast({
  99. title: '支付失败',
  100. icon: 'none',
  101. duration: 1000,
  102. })
  103. }
  104. }
  105. })
  106. },
  107. /**
  108. * 生命周期函数--监听页面初次渲染完成
  109. */
  110. onReady: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面显示
  114. */
  115. onShow: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面隐藏
  119. */
  120. onHide: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面卸载
  124. */
  125. onUnload: function () {
  126. },
  127. /**
  128. * 页面相关事件处理函数--监听用户下拉动作
  129. */
  130. onPullDownRefresh: function () {
  131. },
  132. /**
  133. * 页面上拉触底事件的处理函数
  134. */
  135. onReachBottom: function () {
  136. },
  137. /**
  138. * 用户点击右上角分享
  139. */
  140. onShareAppMessage: function () {
  141. }
  142. })