Vue.config.devtools = true;
var v = new Vue({
    el:".container",
    data:{
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf:-1,
        id:-1,
        goodInfo:{},
        info:{},
        integralType: "",
        integralCount: "",
    },
    created:function (){
        if(!checkLogin()){
            // goLogin();
            return false;
        }
        if($.cookie("memToken")){
            this.memToken = $.cookie("memToken");
            this.isLogin=1;
        }
        if($.cookie("memHeadImg")){
            this.memHeadImg = $.cookie("memHeadImg");
        }
        this.id = $("#id").val();
        this.getUserInfo();
        this.findGoodDetails();
        this.findUserIntegral();
    },
    mounted:function (){
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        },500)
    },
    methods: {
        gotoReceiptInformation(){
            if (this.info.memResidualPoints < this.goodInfo.goodsNeedPoints) {
                alert("抱歉,您的积分不足");
                return;
            }
            window.location.href = serverHttp + "/user/receiptInformation?from=H5&id="+this.id;
        },
        getUserInfo (){
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/user/getUserInfo",
                data : {
                    memToken:that.memToken
                },
                success:function (res) {
                    console.log(res);
                    if (res.code == 200) {
                        that.info = res.data;
                    }
                }
            })
        },
        findUserIntegral (){
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/user/findUserIntegral",
                data : {
                    memToken:that.memToken
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.userJf = data.data;
                    }
                },
                error : function(data) {
                }
            });
        },
        findGoodDetails (){
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/user/findGoodDetails",
                data : {
                    memToken:that.memToken,
                    id:that.id
                },
                success:function (res) {
                    if (res.code == 200) {
                        that.goodInfo = res.data;
                        if(that.goodInfo.goodsImg){
                            if(that.goodInfo.goodsImg.indexOf('http') < 0){
                                that.goodInfo.goodsImg = 'http://files.qkyxzx.com/' + that.goodInfo.goodsImg;
                            }
                        }
                    }
                }
            })
        },
        gotoCommodityDetail (id){
            window.location.href = serverHttp + "/user/commodityDetail?from=H5&memToken="+this.memToken+"&id="+id;
        }
    }
})
