const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        info: { plugin_name: "分销收入奖励记录" },
        isLoadMore: false,
        list: [],
        loading: false,
        page: 1,
        noMore: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {},

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getdata();
    },
    initdata() {
        this.setData({
            isLoadMore: false,
            page: 1,
            info: {},
            list: [],
            loading: true
        })
    },
    $toast(title) {
        wx.showToast({
            title,
            duration: 1000,
            icon: 'none'
        });
    },
    getdata() {
        this.initdata();
        let urlStr = app.getNetAddresss('plugin.distribution-income.frontend.controllers.center.index');
        app._postNetWork({
            url: urlStr,
            success: ({ data: { result, data, msg } }) => {
                this.setData({ loading: false });
                if (result == 1) {
                    wx.setNavigationBarTitle({
                        title: data.info.plugin_name || "分销收入奖励记录"
                    })
                    this.setData({
                        info: data.info,
                        list: data.list.data
                    })
                    this.setMore(this.data.page == data.list.last_page);
                } else this.$toast(msg)
            }
        });
    },
    setMore(bool = true) {
        this.setData({
            noMore: bool,
            isLoadMore: !bool
        })
    },
    getMoreData() {
        this.setData({
            loading: true,
            isLoadMore: false
        });
        let page = this.data.page + 1;
        let urlStr = app.getNetAddresss('plugin.distribution-income.frontend.controllers.center.index');
        app._postNetWork({
            url: urlStr,
            data: { page },
            success: ({ data: { result, data, msg } }) => {
                this.setData({ loading: false });
                if (result == 1) {
                    this.setData({
                        list: this.data.list.concat(data.list.data),
                        page
                    })
                    this.setMore(this.data.page == data.list.last_page);
                } else this.$toast(msg)
            }
        });
    },

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

    },

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

    },

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

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        if (this.data.isLoadMore) {
            this.getMoreData();
        } else {
            this.$toast("没有更多了~~~")
        }
    },

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

    }
})