123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- // pages/storedValue/index.js
- import {
- get,
- post
- } from '../../utils/http'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- selectRe: 0,
- agree: true,
- // 自定义金额
- money: null,
- // 控制自定义金额显示
- isShow: 1,
- },
- // 获取输入的自定义金额
- getInput(e) {
- this.setData({
- money: e.detail.value
- })
- },
- agree() {
- this.setData({
- agree: !this.data.agree
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getRecharge()
- this.getAmount()
- },
- submitRe() {
- if (!this.data.agree) {
- wx.showToast({
- title: '请先勾选同意jolijoli充值协议',
- icon: 'none'
- })
- return
- }
- let that = this
- let storeId = wx.getStorageSync('store_id')
- post('api/recharge/add', {
- amount: this.data.money||this.data.reChargeList[this.data.selectRe].amount,
- store_id: storeId
- }, (res) => {
- if (res.data) {
- wx.requestPayment({
- timeStamp: res.data.pay_data.timeStamp,
- nonceStr: res.data.pay_data.nonceStr,
- package: res.data.pay_data.package,
- signType: res.data.pay_data.signType,
- paySign: res.data.pay_data.paySign,
- success(res) {
- if (res.errMsg == 'requestPayment:ok') {
- wx.showToast({
- title: '支付成功',
- icon: 'success'
- })
- that.getAmount()
- }
- },
- fail(res) {
- wx.showToast({
- title: '支付失败',
- icon: 'error'
- })
- },
- complete:(res)=>{
- this.setData({
- money:null
- })
- }
- })
- }
- })
- },
- selectRe(e) {
- this.setData({
- selectRe: e.currentTarget.dataset.index
- })
- },
- /**
- * 获取我的储值
- * api/user
- */
- getAmount() {
- get('api/user/amount', {}, (res) => {
- if (res.data) {
- this.setData({
- inserllAmount: res.data.amount
- })
- }
- })
- },
- /**
- * 获取充值列表
- *
- */
- getRecharge() {
- let storeId = wx.getStorageSync('store_id')
- get('api/recharge/list', {
- store_id: storeId
- }, (res) => {
- if (res.data) {
- this.setData({
- reChargeList: res.data.list
- })
- //控制显示自定义金额
- this.setData({
- isShow: this.data.isShow == res.data.allow_custom ? true : false
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|