123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- // pages/balance/balance.js
- const app = getApp();
- const util = require('../../utils/utils')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isShow: false,
- inpurShow: false,
- money: '', //选择的金额
- inputValue: null, //输入框内金额(10~1000)
- currentNow: 0, //当前选择金额
- moneyList: [], //可选择的金额列表
- id: '',
- Index: 0,
- title: app.globalData.title,
- balance: '',
- index1: ''
- },
- frameShow: function () {
- // this.setData({
- // isShow: true
- // })
- },
- hideFrame: function () {
- this.setData({
- isShow: false
- })
- },
- skipXieyi: function () {
- my.navigateTo({
- url: '/pages/agreement/agreement',
- })
- },
- //获取余额
- getBalance: util.throttle(function (e) {
- app.request("/me", '', "GET").then(res => {
- 200 == res.status && my.setStorageSync({ 'key': "userInfo", data: res.data }), this.setData({
- balance: res.data.wallet_money
- })
- })
- }, 1000),
- //验证输入金额
- ckInp(e) {
- var self = this
- this.setData({
- money: e.detail.value,
- id: 0
- })
- },
- //选择充值金额
- changeMoney: function (e) {
- this.setData({
- money: null
- })
- let idx = e.currentTarget.dataset.idx
- if (idx == -1) {
- this.setData({
- currentNow: idx,
- index1: idx
- })
- } else {
- this.setData({
- currentNow: idx,
- money: this.data.moneyList[idx].recharge_money,
- id: this.data.moneyList[idx].id,
- Index: idx
- })
- }
- },
- //立即充值
- pay: util.throttle(function (e) {
- var reg = new RegExp("^([1-9]|[0-9]{0,3}|1000)$");
- // var reg = new RegExp("^[1-9]\d{0,3}|10000$")
- var self = this;
- console.log(self.data.money)
- console.log(self.data.inputValue)
- if (self.data.money == '' && self.data.inputValue == null) {
- my.showToast({
- content: '请选择或者输入充值金额',
- icon: 'none',
- duration: 2000
- })
- } else if (!reg.test(self.data.money)) {
- my.showToast({
- content: '请输入1-1000的整数',
- icon: 'none',
- duration: 2000,
- })
- self.setData({
- inputValue: null
- })
- } else {
- if (app.globalData.req) {
- console.log(self.data.id, 'area_id')
- console.log(self.data.id, 'area_id')
- let data = {}
- if (my.getStorageSync({ 'key': 'home' }).data) {
- data = {
- money: self.data.inputValue || self.data.money,
- area_id: my.getStorageSync({ 'key': 'home' }).data.id,
- config_id: self.data.id
- }
- }else{
- data = {
- money: self.data.inputValue || self.data.money,
- config_id: self.data.id
- }
- }
- app.request('/rechange/pay', data, 'POST', app.globalData.req).then(res => {
- if (res.status == 200) {
- my.tradePay({
- tradeNO: res.data.tradeNo,
- success(resp) {
- if (resp.resultCode == 9000) {
- my.navigateTo({
- url: '/pages/index/index',
- })
- } else {
- return
- }
- },
- fail: function () {
- // my.showToast({
- // content: '支付失败',
- // icon: 'none'
- // })
- }
- })
- }
- })
- } else {
- my.showToast({
- content: '您的操作过于频繁,请稍后再试~',
- icon: 'none'
- })
- }
- }
- }, 1000),
- onLoad: function (options) {
- this.getBalance()
- var that = this;
- var data = {
- 'area_id': my.getStorageSync({ 'key': 'home' }).data.id
- }
- my.showLoading({
- content: '加载中...',
- mask: true
- })
- app.request('/pages/recharge', data, 'Get').then(res => {
- if (res.status == 200) {
- console.log(res)
- my.hideLoading({
- complete: (res) => { },
- })
- if (res.data.data != '') {
- that.setData({
- moneyList: res.data.data,
- money: res.data.data[0].recharge_money,
- id: res.data.data[0].id
- })
- }
- }
- })
- },
- onReady: function () {
- },
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|