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

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

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        windowHeight: 0,
        knowledgeList: [],
        knowledgeIndex: 0,
        pay_open: "",
        title: "",
        total_num: "0",
        item: {},
        isloading: !0,
        isBool: !0,
        show: !1,
        activationShow: !1,
        setCDKey: "",
        fItem: {},
        userInfo: {},
        isIos: !1,
        params: {}
    },
    getCode: function() {
        this.setData({
            show: !1,
            activationShow: !0
        });
    },
    onClose: function() {
        this.setData({
            activationShow: !1
        });
    },
    onChange: function(t) {
        this.setData({
            setCDKey: t.detail
        });
    },
    onConfirm: function() {
        this.data.setCDKey ? e.setCDKey({
            uid: wx.getStorageSync("uid"),
            code: this.data.setCDKey
        }).then(function(t) {
            console.log(t), wx.showToast({
                icon: "none",
                title: t.message
            });
        }).catch(function(t) {
            console.log(t), wx.showToast({
                icon: "none",
                title: "该激活码不可用"
            });
        }) : wx.showToast({
            icon: "none",
            title: "请输入激活码"
        });
    },
    onLoad: function(e) {
        if (wx.getStorageSync("uid")) {
            1 == e.type && this.setData({
                params: e
            }), console.log(this.data.params);
            var a = wx.getSystemInfoSync().model.slice(0, 6), o = wx.getSystemInfoSync().model.slice(0, 4);
            e = !1, "iPhone" != a && "iPad" != o || (e = !0), a = wx.getSystemInfoSync().windowHeight, 
            this.setData({
                statusBarHeight: getApp().globalData.statusBarHeight,
                titleBarHeight: getApp().globalData.titleBarHeight,
                windowHeight: a,
                title: t.globalData.title,
                isIos: e
            });
        } else wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    onReady: function() {},
    ltChoose: function(t) {
        this.setData({
            knowledgeIndex: t.currentTarget.dataset.i
        });
    },
    rtChoose: function(e) {
        var a = e.currentTarget.dataset.chapterid, o = e.currentTarget.dataset.fitem;
        console.log(e), (e = e.currentTarget.dataset.oitem).chapterId = a, this.setData({
            total_num: e.total_num,
            item: e,
            fItem: o
        }), console.log(o), 1 != o.is_can ? this.data.isIos && 2 == this.data.userInfo.IOS ? this.iosTip() : this.setData({
            show: !0
        }) : (t.globalData.id = e.id, wx.navigateTo({
            url: "../practice/practice"
        }));
    },
    iosTip: function() {
        wx.showModal({
            cancelText: "关闭",
            confirmText: "联系客服",
            content: "由于相关规范，ios功能暂不可用，如有问题请联系客服",
            showCancel: !0,
            title: "提示",
            success: function(t) {
                t.confirm && wx.navigateTo({
                    url: "/pages/contactService/contactService"
                });
            }
        });
    },
    onShow: function() {
        this.getUserInfo(), this.getSequence();
    },
    getSequence: function() {
        var a = this;
        t.globalData.op = "special", e.sequence({
            uid: wx.getStorageSync("uid"),
            op: "getallspecial"
        }).then(function(t) {
            console.log(t);
            var e = !1;
            0 < t.data.list.length && (e = !0), a.setData({
                knowledgeList: t.data.list,
                isloading: !1,
                pay_open: t.data.pay_open,
                freenum: t.data.freenum,
                isBool: e
            }), a.firstNavTabs();
        }).catch(function(t) {
            console.log(t);
        });
    },
    firstNavTabs: function() {
        var t = this.data.params;
        if (t && 1 == t.type) {
            for (var e = this.data.knowledgeList, a = 0, o = 0; o < e.length; o++) if (t.id == e[o].id) {
                a = o;
                break;
            }
            this.setData({
                knowledgeIndex: a
            });
        }
    },
    onHide: function() {},
    tryAnswer: function(e) {
        console.log(e), e = e.currentTarget.dataset.num, t.globalData.id = this.data.item.id, 
        wx.navigateTo({
            url: "../practice/practice?num=" + e
        });
    },
    getUserInfo: function() {
        var t = this;
        e.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);
        });
    },
    closePayPopup: function() {
        this.setData({
            show: !1
        });
    },
    goVipBtn: function() {
        wx.navigateTo({
            url: "../vip/vip"
        }), this.setData({
            show: !1
        });
    },
    goPay: function() {
        var t = this;
        e.wxPay({
            uid: wx.getStorageSync("uid"),
            id: this.data.item.chapterId,
            type: "1"
        }).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) {
                    wx.showToast({
                        icon: "success",
                        title: "支付成功"
                    }), t.setData({
                        show: !1
                    }), t.getSequence();
                },
                fail: function(t) {
                    wx.showToast({
                        icon: "none",
                        title: "支付失败,请重试~"
                    });
                }
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});