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

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

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('options', options);
        let type = options.type;
        if (type) {
            this.setData({
                type,
                sellerid: options.sellerid
            })
        }
    },
    getSeller() {
        let type = this.data.type;
        if (type == '1') return
        wx.navigateTo({
            url: util.http_build_query({
                sellerid: event.currentTarget.dataset.id,
                type: this.data.type,
            }, '/pages/me/myBalance')
        })
    },
    // 获取消费金明细
    getInfo(sellerid) {
        App.Activity.GetConsumeListByOpenid({
            openid: getApp().openid,
            sellerid
        }).then(res => {
            let consumeList = res.data;
            consumeList.forEach(i => {
                i.price = (i.price * 1).toFixed(2)
                i.balance = (i.balance * 1).toFixed(2)
                i.cdateInfo = i.cdate ? util.unixtoTime(i.cdate, 'YYYY-MM-DD HH:II') : '';
            })
            consumeList.sort((a, b) => (b.cdate * 1) - (a.cdate * 1));
            this.setData({
                consumeList
            })
        })
    },
    // 获取余额明细
    getBalanceList(sellerid) {
        App.Activity.GetBalanceListByOpenid({
            openid: getApp().openid,
            sellerid
        }).then(res => {
            let consumeList = res.data;
            consumeList.forEach(i => {
                i.price = (i.price * 1).toFixed(2)
                i.balance = (i.balance * 1).toFixed(2)
                i.cdateInfo = i.cdate ? util.unixtoTime(i.cdate, 'YYYY-MM-DD HH:II') : '';
            })
            consumeList.sort((a, b) => (b.cdate * 1) - (a.cdate * 1));
            this.setData({
                consumeList
            })
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

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

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

    },

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

    },

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

    },

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

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})