var t = getApp(), e = require("../../utils/login.js");

Page({
    data: {
        showLoding: !0,
        type: "",
        list: [],
        loading: !1,
        page: {
            next_page: 1
        }
    },
    onLoad: function(a) {
        var n = this;
        this.setData({
            type: a.type
        }), wx.setNavigationBarTitle({
            title: "invest" == a.type ? "充值记录" : "消费明细"
        }), e.pageStart(t).then(function(t) {
            n.getContent();
        });
    },
    onShow: function() {
        this.refresh && this.refreshPage();
    },
    refreshPage: function() {
        this.setData({
            list: [],
            page: {
                next_page: 1
            }
        }), this.getContent();
    },
    onPullDownRefresh: function() {
        if (!t.globalData.canGetData) return !1;
        this.refreshPage(), wx.stopPullDownRefresh();
    },
    onReachBottom: function() {
        if (!t.globalData.canGetData) return !1;
        this.getContent();
    },
    onShareAppMessage: function() {},
    getContent: function() {
        if (!this.data.page.next_page || this.data.loading) return !1;
        wx.showLoading({
            title: ""
        });
        var a = this, n = "invest" == this.data.type ? t.globalData.config.recharge.log : t.globalData.config.consume.init;
        e.request(n, {
            page: this.data.page.next_page
        }, !0).then(function(t) {
            if (wx.hideLoading(), 200 != t.code) return wx.showModal({
                title: "提示",
                content: t.message
            }), !1;
            a.setData({
                showLoding: !1,
                list: a.data.list.concat(t.data.list),
                user: t.data.user,
                page: t.data.page
            }, function() {});
        }).catch(function(t) {
            wx.hideLoading();
        });
    },
    toPage: function() {
        this.refresh = 1, wx.navigateTo({
            url: "/pages/voucher/voucher"
        });
    }
});