recharge.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. const app = getApp();
  2. const util = require('../../../utils/utils.js')
  3. Page({
  4. data: {
  5. money: '', //选择的金额
  6. inputValue: null, //输入框内金额(10~1000)
  7. currentNow: 0, //当前选择金额
  8. moneyList: [], //可选择的金额列表
  9. id: '',
  10. Index: 0
  11. },
  12. //选择充值金额
  13. choice: function (e) {
  14. this.setData({
  15. inputValue: null
  16. })
  17. let idx = e.currentTarget.dataset.idx
  18. this.setData({
  19. currentNow: idx,
  20. money: this.data.moneyList[idx].recharge_money,
  21. id: this.data.moneyList[idx].id
  22. })
  23. },
  24. //使用输入框时去掉选择
  25. enter() {
  26. this.setData({
  27. currentNow: null,
  28. money: ''
  29. })
  30. },
  31. //验证输入金额
  32. ckInp(e) {
  33. var self = this
  34. // let reg = /^(\+?\d{2,4}|\+?1000)$/;
  35. this.setData({
  36. inputValue: e.detail.value,
  37. id: 0
  38. })
  39. },
  40. //立即支付
  41. pay: util.throttle(function (e) {
  42. var reg = new RegExp("^([1-9]|[1-9]\\d|1000)$");
  43. var self = this;
  44. console.log(self.data.money)
  45. console.log(self.data.inputValue)
  46. if (self.data.money == '' && self.data.inputValue == null) {
  47. wx.showToast({
  48. title: '请选择或者输入充值金额',
  49. icon: 'none',
  50. duration: 2000
  51. })
  52. } else if (!reg.test(self.data.inputValue) && self.data.money == '') {
  53. wx.showToast({
  54. title: '请输入1-1000的整数',
  55. icon: 'none',
  56. duration: 2000,
  57. })
  58. self.setData({
  59. inputValue: null
  60. })
  61. } else {
  62. // wx.navigateTo({
  63. // url: '/pages/personal/rechSuce/rechSuce',
  64. // })
  65. //充值接口
  66. self.setData({
  67. tap: false
  68. })
  69. if (app.globalData.req) {
  70. let data = {
  71. money: self.data.inputValue || self.data.money,
  72. area_id: wx.getStorageSync('home').id,
  73. config_id: self.data.id
  74. }
  75. app.request('/rechange/pay', data, 'POST', app.globalData.req).then(res => {
  76. if (res.statusCode == 200) {
  77. let timeStamp = res.data.timeStamp.toString();
  78. wx.requestPayment({
  79. timeStamp: timeStamp,
  80. nonceStr: res.data.nonceStr,
  81. package: res.data.package,
  82. signType: res.data.signType,
  83. paySign: res.data.paySign,
  84. success(res) {
  85. wx.navigateTo({
  86. url: '/pages/personal/rechSuce/rechSuce',
  87. })
  88. },
  89. fail: function () {
  90. wx.showToast({
  91. title: '支付失败',
  92. icon: 'none'
  93. })
  94. }
  95. })
  96. }
  97. })
  98. } else {
  99. wx.showToast({
  100. title: '您的操作过于频繁,请稍后再试~',
  101. icon: 'none'
  102. })
  103. }
  104. }
  105. }, 1000),
  106. agreement: util.throttle(function (e) {
  107. //充值条约。
  108. wx.navigateTo({
  109. url: '/pages/agreement/agreement',
  110. })
  111. }, 1000),
  112. onLoad: function (options) {
  113. var that = this;
  114. var data = {
  115. 'area_id': wx.getStorageSync('home').id
  116. }
  117. wx.showLoading({
  118. title: '加载中...',
  119. mask:true
  120. })
  121. app.request('/pages/recharge', data, 'Get').then(res => {
  122. if (res.statusCode == 200) {
  123. console.log(res)
  124. wx.hideLoading({
  125. complete: (res) => {},
  126. })
  127. if (res.data.data != '') {
  128. that.setData({
  129. moneyList: res.data.data,
  130. money: res.data.data[0].recharge_money,
  131. id: res.data.data[0].id
  132. })
  133. }
  134. }
  135. })
  136. },
  137. onReady: function () {
  138. },
  139. onShow: function () {
  140. },
  141. onHide: function () {
  142. },
  143. onUnload: function () {
  144. },
  145. onPullDownRefresh: function () {
  146. },
  147. onReachBottom: function () {
  148. },
  149. onShareAppMessage: function () {
  150. }
  151. })