payment.js 3.2 KB

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