var t = {
    scope: {}
};

t.defineProperty = "function" == typeof Object.defineProperties ? Object.defineProperty : function(t, e, a) {
    if (a.get || a.set) throw new TypeError("ES3 does not support getters and setters.");
    t != Array.prototype && t != Object.prototype && (t[e] = a.value);
}, t.getGlobal = function(t) {
    return "undefined" != typeof window && window === t ? t : "undefined" != typeof global ? global : t;
}, t.global = t.getGlobal(void 0), t.SYMBOL_PREFIX = "jscomp_symbol_", t.initSymbol = function() {
    t.initSymbol = function() {}, t.global.Symbol || (t.global.Symbol = t.Symbol);
}, t.symbolCounter_ = 0, t.Symbol = function(e) {
    return t.SYMBOL_PREFIX + (e || "") + t.symbolCounter_++;
}, t.initSymbolIterator = function() {
    t.initSymbol();
    var e = t.global.Symbol.iterator;
    e || (e = t.global.Symbol.iterator = t.global.Symbol("iterator")), "function" != typeof Array.prototype[e] && t.defineProperty(Array.prototype, e, {
        configurable: !0,
        writable: !0,
        value: function() {
            return t.arrayIterator(this);
        }
    }), t.initSymbolIterator = function() {};
}, t.arrayIterator = function(e) {
    var a = 0;
    return t.iteratorPrototype(function() {
        return a < e.length ? {
            done: !1,
            value: e[a++]
        } : {
            done: !0
        };
    });
}, t.iteratorPrototype = function(e) {
    return t.initSymbolIterator(), (e = {
        next: e
    })[t.global.Symbol.iterator] = function() {
        return this;
    }, e;
}, t.makeIterator = function(e) {
    t.initSymbolIterator();
    var a = e[Symbol.iterator];
    return a ? a.call(e) : t.arrayIterator(e);
}, t.arrayFromIterator = function(t) {
    for (var e, a = []; !(e = t.next()).done; ) a.push(e.value);
    return a;
}, t.arrayFromIterable = function(e) {
    return e instanceof Array ? e : t.arrayFromIterator(t.makeIterator(e));
};

var e = getApp(), a = require("../../provider/dataApi.js");

require("../../provider/pipe.js");

Page({
    data: {
        title: "题型练习",
        statusBarHeight: "",
        titleBarHeight: "",
        list: [],
        isloading: !0,
        params: "",
        isShowTest: !1,
        showPay: !1,
        item: {},
        page: 1,
        totalPage: "",
        isData: !0,
        isSon: 2
    },
    onLoad: function(t) {
        if (wx.getStorageSync("uid")) {
            var a = wx.getSystemInfoSync().model.slice(0, 6), o = wx.getSystemInfoSync().model.slice(0, 4), i = !1;
            "iPhone" != a && "iPad" != o || (i = !0), this.setData({
                statusBarHeight: getApp().globalData.statusBarHeight,
                titleBarHeight: getApp().globalData.titleBarHeight,
                title: e.globalData.title,
                isIos: i
            }), "{}" !== JSON.stringify(t) && this.setData({
                params: t,
                title: "全真模拟试卷列表",
                isShowTest: !0
            }), this.data.isShowTest || (this.setData({
                lib_id: e.globalData.lib_id
            }), this.getSequence());
        } else wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    getSequence: function() {
        var t = this;
        a.sequence({
            uid: wx.getStorageSync("uid"),
            op: "getalltypes",
            lib_id: this.data.lib_id
        }).then(function(e) {
            if (console.log(e), e.data.type_list) {
                var a = e.data.type_list, o = !1;
                0 < a.length && (o = !0), t.setData({
                    list: a,
                    isSon: e.data.son,
                    isloading: !1,
                    isData: o
                });
            }
            wx.stopPullDownRefresh();
        }).catch(function(t) {
            console.log(t);
        });
    },
    getExamList: function(e) {
        var o = this;
        a.getExamList({
            uid: wx.getStorageSync("uid"),
            page: e
        }).then(function(e) {
            if (console.log(e), e.data.list) {
                var a, i = !1;
                0 < (a = [].concat(t.arrayFromIterable(o.data.list), t.arrayFromIterable(e.data.list))).length && (i = !0), 
                o.setData({
                    list: a,
                    totalPage: Math.ceil(e.data.total / e.data.psize),
                    isData: i,
                    isloading: !1
                });
            }
            wx.stopPullDownRefresh();
        }).catch(function(t) {
            console.log(t);
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    iosTip: function() {
        wx.showModal({
            cancelText: "关闭",
            confirmText: "联系客服",
            content: "由于相关规范，ios功能暂不可用，如有问题请联系客服",
            showCancel: !0,
            title: "提示",
            success: function(t) {
                t.confirm && wx.navigateTo({
                    url: "/pages/contactService/contactService"
                });
            }
        });
    },
    goLx: function(t) {
        if (this.data.params) {
            var a = t.currentTarget.dataset.item;
            1 != a.is_repeat && 0 < a.do_number ? wx.showToast({
                title: "不可重复答题",
                icon: "none"
            }) : wx.navigateTo({
                url: "../exam-before-see/exam-before-see?exam_type=1&paperid=" + t.currentTarget.id
            });
        } else 1 == this.data.isSon ? 8 != (t = t.currentTarget.id) ? (e.globalData.op = "qtype", 
        e.globalData.id = t, wx.navigateTo({
            url: "../practice/practice"
        })) : wx.navigateTo({
            url: "/pages/shortAnswerList/shortAnswerList"
        }) : (t = t.currentTarget.id, e.globalData.op = "qtype", e.globalData.id = t, wx.navigateTo({
            url: "../practice/practice"
        }));
    },
    goPayPopup: function(t) {
        1 != (t = t.currentTarget.dataset.item).is_repeat && 0 < t.do_number ? wx.showToast({
            title: "本套试卷暂不可购买",
            icon: "none"
        }) : this.data.isIos && 2 == this.data.userInfo.IOS ? this.iosTip() : this.setData({
            item: t,
            showPay: !0
        });
    },
    getUserInfo: function() {
        var t = this;
        a.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(e) {
            console.log(e), t.setData({
                userInfo: e.data.info
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    onShow: function() {
        this.data.isShowTest && (this.setData({
            page: 1,
            list: []
        }), this.getUserInfo(), this.getExamList(1));
    },
    closePayPopup: function() {
        this.setData({
            showPay: !1
        });
    },
    goPayBtn: function() {
        this.requestPayment();
    },
    requestPayment: function() {
        var t = this;
        a.wxPay({
            uid: wx.getStorageSync("uid"),
            id: this.data.item.id,
            type: "4"
        }).then(function(e) {
            console.log(e), wx.requestPayment({
                timeStamp: String(e.data.timeStamp),
                nonceStr: e.data.nonceStr,
                package: e.data.package,
                signType: e.data.signType,
                paySign: e.data.paySign,
                success: function(e) {
                    console.log(e), wx.showToast({
                        icon: "success",
                        title: "支付成功"
                    }), t.setData({
                        showPay: !1
                    }), t.getExamList(1);
                },
                fail: function(e) {
                    wx.showToast({
                        icon: "none",
                        title: "支付失败,请重试~"
                    }), t.setData({
                        showPay: !1
                    });
                }
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    goVipBtn: function() {
        wx.navigateTo({
            url: "../vip/vip"
        });
    },
    onPullDownRefresh: function() {
        this.data.isShowTest ? (this.setData({
            page: 1,
            list: [],
            isloading: !0
        }), this.getExamList(1)) : this.getSequence();
    },
    onReachBottom: function() {
        var t = parseInt(this.data.totalPage), e = parseInt(this.data.page);
        e < t && (this.setData({
            page: e + 1
        }), this.getExamList(this.data.page));
    },
    onShareAppMessage: function() {}
});