recharge.js 4.0 KB

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