consumeAmount.js 2.72 KB
// pages/me/consumeAmount.js
import App from '../../utils/api';
import util from '../../utils/util';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        type:'',//1消费金 2余额
        sellerList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('options',options);
        let type = options.type;
        if(type){
            this.setData({
                type
            })
        }
    },
    // 获取用户消费金商家余额列表
    getInfo() {
        App.Activity.GetConsumeSellerListByOpenid({
            openid: getApp().openid,
        }).then(res => {
            let sellerList = res.data;
            sellerList.forEach(i => {
                i.balance = (i.balance * 1).toFixed(2)
            })
            this.setData({
                sellerList
            })
        })
    },
    // 获取用户在商家的账户余额
    getConsumeSellerList() {
        App.Activity.GetRechargeBalanceByOpenid({
            openid: getApp().openid,
        }).then(res => {
            let sellerList = res.data;
            sellerList.forEach(i => {
                i.balance = (i.recharge_balance * 1).toFixed(2)
            })
            this.setData({
                sellerList
            })
        })
    },
    // 跳转用户商家消费金消费记录
    getSeller(event) {
        if (this.data.type == '1') {
            wx.navigateTo({
                url: util.http_build_query({
                    sellerid: event.currentTarget.dataset.id,
                    type: this.data.type,
                }, '/pages/me/consumeDetails')
            })
        } else {
            wx.navigateTo({
                url: util.http_build_query({
                    sellerid: event.currentTarget.dataset.id,
                }, '/pages/me/myBalance')
            })
        }
    },
    // 换号查看
    switchAccount() {
        wx.redirectTo({
            url: util.http_build_query({
                types: '3'
            }, '/pages/customer/login')
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let type = this.data.type;
        if (type == 1) this.getInfo()
        if (type == 2) this.getConsumeSellerList()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },
})