buy.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. var _request = require('../../../../utils/request.js')
  2. Page({
  3. data: {
  4. inputValue: '',
  5. balance: '',
  6. buttonClicked: false,
  7. orderId: '',
  8. path: '',
  9. luoboCount: '',
  10. countMoney: '0.00',
  11. bannerList:[]
  12. },
  13. onLoad: function (options) {
  14. this.data.orderId = options.orderId
  15. this.data.path = options.path
  16. // this.data.luoboCount = options.luoboCount
  17. // this.setData({
  18. // luoboCount: options.luoboCount
  19. // })
  20. // this.setData({
  21. // countMoney: options.countMoney
  22. // })
  23. this.checkbalance()
  24. this.getBanners()
  25. },
  26. bindKeyInput: function(e) {
  27. this.setData({
  28. inputValue: e.detail.value
  29. })
  30. if (!this.data.inputValue) {
  31. this.setData({
  32. countMoney:'0.00'
  33. })
  34. }
  35. },
  36. toWeixin (e) {
  37. var count = parseInt(e.currentTarget.dataset.text) || this.data.inputValue || this.data.luoboCount
  38. var that = this
  39. that.buttonClicked()
  40. var url = 'v1/balance_order/generate'
  41. var params = {
  42. count: count*100,
  43. payway: 'service_wxpay'
  44. }
  45. var success = function (val) {
  46. that.topay(val.data)
  47. }
  48. _request.$post(url, params, success)
  49. },
  50. topay (res) {
  51. var that = this
  52. var url = 'v1/pay'
  53. var params = {
  54. order_id: res.order_id,
  55. pay_way: res.pay_way
  56. }
  57. var success = function (val) {
  58. wx.requestPayment({
  59. 'timeStamp': val.data.pay_data.timeStamp,
  60. 'nonceStr': val.data.pay_data.nonceStr,
  61. 'package': val.data.pay_data.package,
  62. 'signType': val.data.pay_data.signType,
  63. 'paySign': val.data.pay_data.paySign,
  64. 'success':function(res){
  65. wx.showToast({
  66. title: '支付成功',
  67. icon: 'success',
  68. duration: 1000
  69. })
  70. that.checkbalance()
  71. wx.navigateTo({
  72. url: that.data.path + '?orderId=' + that.data.orderId
  73. })
  74. },
  75. 'fail':function(res){
  76. }
  77. })
  78. }
  79. _request.$post(url, params, success)
  80. },
  81. checkbalance () {
  82. var that = this
  83. var url = 'v1/user/balance/info'
  84. var params = {
  85. }
  86. var success = function (res) {
  87. var result = res.data.total
  88. that.setData({
  89. balance: result,
  90. invitemode: res.data.show_invite_mode
  91. })
  92. }
  93. _request.$get(url, params, success)
  94. },
  95. buttonClicked () {
  96. var that = this
  97. that.setData({
  98. buttonClicked: true
  99. })
  100. setTimeout(function () {
  101. that.setData({
  102. buttonClicked: false
  103. })
  104. }, 3000)
  105. },
  106. onShareAppMessage: function (val) {
  107. return _request.share({
  108. sc: 'xcx_user_rabbitbuy'
  109. })
  110. },
  111. getBanners: function () {
  112. var that = this
  113. var url = 'v1/ad/recharge_ad/items'
  114. var params = {
  115. cache: false
  116. }
  117. var success = function (res) {
  118. that.setData({
  119. bannerList: res.data
  120. })
  121. console.log('ad',res)
  122. }
  123. _request.$get(url, params, success)
  124. },
  125. })