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

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        payText: "立即开通",
        id: "",
        isloading: !0,
        userInfo: {},
        vipList: [],
        isTui: 0,
        scale: ""
    },
    onLoad: function(a) {
        this.setData({
            statusBarHeight: t.globalData.statusBarHeight,
            titleBarHeight: t.globalData.titleBarHeight
        }), this.getUserInfo();
    },
    getUserInfo: function() {
        var t = this;
        a.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(a) {
            console.log(a);
            var i = "立即开通";
            2 != a.data.info.ismember && (i = "续费会员"), t.setData({
                userInfo: a.data.info,
                payText: i
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    getVipList: function() {
        var t = this, i = this;
        a.member({}).then(function(a) {
            console.log(a), t.setData({
                vipList: a.data.info.info,
                isTui: a.data.info.istui,
                scale: a.data.info.scale,
                id: a.data.info.info[0].id
            }), setTimeout(function() {
                i.setData({
                    isloading: !1
                });
            }, 500);
        }).catch(function(t) {
            console.log(t);
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    goChoose: function(t) {
        this.setData({
            id: t.currentTarget.dataset.item.id
        });
    },
    goPay: function() {
        this.requestPayment();
    },
    requestPayment: function() {
        a.wxPay({
            uid: wx.getStorageSync("uid"),
            memberid: this.data.id,
            type: "3"
        }).then(function(t) {
            console.log(t), wx.requestPayment({
                timeStamp: String(t.data.timeStamp),
                nonceStr: t.data.nonceStr,
                package: t.data.package,
                signType: t.data.signType,
                paySign: t.data.paySign,
                success: function(t) {
                    console.log(t), wx.showToast({
                        icon: "success",
                        title: "支付成功",
                        duration: 1500
                    }), setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 1500);
                },
                fail: function(t) {
                    wx.showToast({
                        icon: "none",
                        title: "支付失败,请重试~"
                    });
                }
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getVipList();
    },
    onShareAppMessage: function() {}
});