balance.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // pages/balance/balance.js
  2. const app = getApp();
  3. const util = require('../../utils/utils')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isShow: false,
  10. inpurShow: false,
  11. money: '', //选择的金额
  12. inputValue: null, //输入框内金额(10~1000)
  13. currentNow: 0, //当前选择金额
  14. moneyList: [], //可选择的金额列表
  15. id: '',
  16. Index: 0,
  17. title: app.globalData.title,
  18. balance: '',
  19. index1: ''
  20. },
  21. frameShow: function () {
  22. // this.setData({
  23. // isShow: true
  24. // })
  25. },
  26. hideFrame: function () {
  27. this.setData({
  28. isShow: false
  29. })
  30. },
  31. //获取余额
  32. getBalance: util.throttle(function (e) {
  33. app.request("/me", '', "GET").then(res => {
  34. 200 == res.status && my.setStorageSync({ 'key': "userInfo", data: res.data }), this.setData({
  35. balance: res.data.wallet_money
  36. })
  37. })
  38. }, 1000),
  39. //验证输入金额
  40. ckInp(e) {
  41. var self = this
  42. this.setData({
  43. money: e.detail.value,
  44. id: 0
  45. })
  46. },
  47. //选择充值金额
  48. changeMoney: function (e) {
  49. this.setData({
  50. money: null
  51. })
  52. let idx = e.currentTarget.dataset.idx
  53. if (idx == -1) {
  54. this.setData({
  55. currentNow: idx,
  56. index1: idx
  57. })
  58. } else {
  59. this.setData({
  60. currentNow: idx,
  61. money: this.data.moneyList[idx].recharge_money,
  62. id: this.data.moneyList[idx].id,
  63. Index: idx
  64. })
  65. }
  66. },
  67. //立即充值
  68. pay: util.throttle(function (e) {
  69. var reg = new RegExp("^([1-9]|[1-9]\\d|1000)$");
  70. // var reg = new RegExp("^[1-9]\d{0,3}|10000$")
  71. var self = this;
  72. console.log(self.data.money)
  73. console.log(self.data.inputValue)
  74. if (self.data.money == '' && self.data.inputValue == null) {
  75. my.showToast({
  76. content: '请选择或者输入充值金额',
  77. icon: 'none',
  78. duration: 2000
  79. })
  80. } else if (!reg.test(self.data.money)) {
  81. my.showToast({
  82. content: '请输入1-1000的整数',
  83. icon: 'none',
  84. duration: 2000,
  85. })
  86. self.setData({
  87. inputValue: null
  88. })
  89. } else {
  90. if (app.globalData.req) {
  91. let data = {
  92. money: self.data.inputValue || self.data.money,
  93. area_id: my.getStorageSync({ 'key': 'home' }).data.id,
  94. config_id: self.data.id
  95. }
  96. app.request('/rechange/pay', data, 'POST', app.globalData.req).then(res => {
  97. if (res.status == 200) {
  98. my.tradePay({
  99. tradeNO: res.data.tradeNo,
  100. success(resp) {
  101. my.navigateTo({
  102. url: '/pages/mine/mine',
  103. })
  104. },
  105. fail: function () {
  106. // my.showToast({
  107. // content: '支付失败',
  108. // icon: 'none'
  109. // })
  110. }
  111. })
  112. }
  113. })
  114. } else {
  115. my.showToast({
  116. content: '您的操作过于频繁,请稍后再试~',
  117. icon: 'none'
  118. })
  119. }
  120. }
  121. }, 1000),
  122. onLoad: function (options) {
  123. this.getBalance()
  124. var that = this;
  125. var data = {
  126. 'area_id': my.getStorageSync({ 'key': 'home' }).data.id
  127. }
  128. my.showLoading({
  129. content: '加载中...',
  130. mask: true
  131. })
  132. app.request('/pages/recharge', data, 'Get').then(res => {
  133. if (res.status == 200) {
  134. console.log(res)
  135. my.hideLoading({
  136. complete: (res) => { },
  137. })
  138. if (res.data.data != '') {
  139. that.setData({
  140. moneyList: res.data.data,
  141. money: res.data.data[0].recharge_money,
  142. id: res.data.data[0].id
  143. })
  144. }
  145. }
  146. })
  147. },
  148. onReady: function () {
  149. },
  150. onShow: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面隐藏
  154. */
  155. onHide: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面卸载
  159. */
  160. onUnload: function () {
  161. },
  162. /**
  163. * 页面相关事件处理函数--监听用户下拉动作
  164. */
  165. onPullDownRefresh: function () {
  166. },
  167. /**
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom: function () {
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. }
  177. })