var t = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../../utils/LoadMore.js")), e = getApp(), a = new t.default(), o = require("../../../utils/util.js");

Page({
    data: {
        url: e.globalData.setting.url,
        resourceUrl: e.globalData.setting.resourceUrl,
        iurl: e.globalData.setting.imghost,
        categories: [ {
            name: "未使用",
            id: 0
        }, {
            name: "已使用",
            id: 1
        }, {
            name: "已过期",
            id: 2
        } ],
        typeId: 0,
        coupons: null,
        currentPage: 1,
        storeName: "自营商店"
    },
    onLoad: function(t) {
        var e = void 0 === t.type ? this.data.typeId : t.type;
        a.init(this, "", "coupons"), this.setStoreName(), this.requestCoupons(e);
    },
    changeTab: function(t) {
        this.reloadCoupons(t.currentTarget.id);
    },
    requestCoupons: function(t) {
        var e = this, n = "/api/user/getCouponList?type=" + t + "&p=" + e.data.currentPage;
        this.setData({
            typeId: t
        }), a.request(n, function(t) {
            e.data.currentPage++, t.data.result.forEach(function(t, e, a) {
                t.deadTimeFommat = o.format(t.use_end_time, "yyyy-MM-dd");
            }), wx.stopPullDownRefresh();
        });
    },
    onReachBottom: function() {
        a.canloadMore() && this.requestCoupons(this.data.typeId);
    },
    onPullDownRefresh: function(t) {
        this.reloadCoupons(this.data.typeId);
    },
    reloadCoupons: function(t) {
        a.resetConfig(), this.setData({
            coupons: null
        }), this.data.currentPage = 1, this.requestCoupons(t);
    },
    setStoreName: function() {
        var t = this;
        e.getConfig(function(e) {
            for (var a = e.config, o = 0; o < a.length; o++) if ("store_name" == a[o].name) {
                t.setData({
                    storeName: a[o].value
                });
                break;
            }
        });
    }
});