var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), a = require("../../@babel/runtime/helpers/toConsumableArray"), e = require("../../@babel/runtime/helpers/asyncToGenerator"), n = (getApp(), 
require("../../utils/login.js"));

Page({
    data: {
        showLoding: !0,
        navList: [ {
            name: "全部",
            tab: "all"
        }, {
            name: "待付款",
            tab: "0"
        }, {
            name: "待使用",
            tab: "1"
        }, {
            name: "已完成",
            tab: "4"
        } ],
        tab: "all",
        loading: !1,
        next_page: 1,
        data: [],
        status: {
            0: "待付款",
            1: "待使用",
            2: "待收货",
            3: "待收货",
            4: "已完成"
        }
    },
    onLoad: function(t) {
        this.setData({
            tab: t.tab || "all"
        }), this.getList();
    },
    onPullDownRefresh: function() {
        this.clearData();
    },
    onReachBottom: function() {
        this.getList();
    },
    clearData: function() {
        this.setData({
            next_page: 1,
            loading: !1,
            data: []
        }), this.getList();
    },
    changeTab: function(t) {
        var a = t.currentTarget.dataset.tab;
        if (a == this.data.tab) return !1;
        this.setData({
            tab: a
        }), this.clearData();
    },
    getList: function() {
        var r = this;
        return e(t.default.mark(function e() {
            var s, i;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (r.data.next_page && !r.data.loading) {
                        t.next = 2;
                        break;
                    }
                    return t.abrupt("return", !1);

                  case 2:
                    return r.setData({
                        loading: !0
                    }), t.prev = 3, t.next = 6, n.request(n.baseUrl + "shop/order/lists", {
                        page: r.data.next_page,
                        typeid: r.data.tab
                    }, !0);

                  case 6:
                    s = t.sent, i = s.data, r.setData({
                        loading: !1,
                        showLoding: !1
                    }), 200 == s.code && (i.data.length < i.limit ? r.data.next_page = 0 : r.data.next_page += 1, 
                    r.setData({
                        type: i.type,
                        count: i.count,
                        limit: i.limit,
                        next_page: r.data.next_page,
                        data: [].concat(a(r.data.data), a(i.data))
                    })), t.next = 15;
                    break;

                  case 12:
                    t.prev = 12, t.t0 = t.catch(3), console.log(t.t0);

                  case 15:
                  case "end":
                    return t.stop();
                }
            }, e, null, [ [ 3, 12 ] ]);
        }))();
    },
    deleteItem: function(a) {
        var r = this;
        return e(t.default.mark(function e() {
            var s, i, o, d;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return s = a.currentTarget.dataset, i = s.orderid, o = s.index, wx.showLoading({
                        title: "正在删除"
                    }), t.prev = 2, t.next = 5, n.request(n.baseUrl + "shop/order/delete", {
                        orderid: i
                    }, !0);

                  case 5:
                    d = t.sent, wx.hideLoading(), 200 == d.code && (r.data.data.splice(o, 1), r.setData({
                        data: r.data.data
                    }), wx.showToast({
                        title: d.message
                    })), t.next = 14;
                    break;

                  case 10:
                    t.prev = 10, t.t0 = t.catch(2), console.log(t.t0), wx.hideLoading();

                  case 14:
                  case "end":
                    return t.stop();
                }
            }, e, null, [ [ 2, 10 ] ]);
        }))();
    }
});