balance.js 4.6 KB

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