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

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

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        oItem: {},
        isData: !0,
        showPay: !1,
        price: "",
        vip_price: ""
    },
    onLoad: function(e) {
        if (wx.getStorageSync("uid")) {
            var a = wx.getSystemInfoSync().model.slice(0, 6), o = wx.getSystemInfoSync().model.slice(0, 4);
            e = !1, "iPhone" != a && "iPad" != o || (e = !0), a = t.globalData.oItem, this.setData({
                statusBarHeight: getApp().globalData.statusBarHeight,
                titleBarHeight: getApp().globalData.titleBarHeight,
                oItem: a,
                isIos: e
            });
        } else wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    getKnowledge: function(t) {
        var a = this;
        e.knowledge({
            op: "knowledgelist",
            uid: wx.getStorageSync("uid"),
            cate: t.id
        }).then(function(t) {
            console.log(t);
            var e = !1;
            0 < t.data.list.length && (e = !0), a.setData({
                list: t.data.list,
                price: t.data.price,
                vip_price: t.data.vip_price,
                pay_open: t.data.pay_open,
                isData: e
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    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);
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    closePayPopup: function() {
        this.setData({
            showPay: !1
        });
    },
    goLook: function(e) {
        1 != (e = e.currentTarget.dataset.item).is_can ? this.data.isIos && 2 == this.data.userInfo.IOS ? this.iosTip() : this.setData({
            showPay: !0
        }) : (t.globalData.oItem = e, wx.navigateTo({
            url: "../knowledgePoints-list-detail/knowledgePoints-list-detail"
        }));
    },
    iosTip: function() {
        wx.showModal({
            cancelText: "关闭",
            confirmText: "联系客服",
            content: "由于相关规范，ios功能暂不可用，如有问题请联系客服",
            showCancel: !0,
            title: "提示",
            success: function(t) {
                t.confirm && wx.navigateTo({
                    url: "/pages/contactService/contactService"
                });
            }
        });
    },
    goVipBtn: function() {
        wx.navigateTo({
            url: "../vip/vip"
        });
    },
    goPayBtn: function() {
        this.pay();
    },
    pay: function() {
        var t = this, a = this.data.oItem;
        e.wxPay({
            uid: wx.getStorageSync("uid"),
            id: a.chapterId,
            type: "2"
        }).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({
                        showPay: !1
                    }), t.getKnowledge(t.data.oItem);
                },
                fail: function(t) {
                    wx.showToast({
                        icon: "none",
                        title: "支付失败,请重试~"
                    });
                }
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    onShow: function() {
        this.getUserInfo(), this.getKnowledge(this.data.oItem);
    },
    onShareAppMessage: function() {}
});