payment.js 3.4 KB

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