Vue.config.devtools = true;
var v = new Vue({
    el: ".container",
    data: {
        info: {},
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf: -1,
        integralType: "签到成功",
        integralCount: "20",
    },
    created() {
        if (!checkLogin()) {
            // goLogin();
            return false;
        }
        if ($.cookie("memToken")) {
            this.memToken = $.cookie("memToken");
            this.isLogin = 1;
        }
        if ($.cookie("memHeadImg")) {
            this.memHeadImg = $.cookie("memHeadImg");
        }
        this.findUserIntegral();

    },
    mounted() {
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
            // console.log(fromlogin,'fromlogin')
            if (typeof (fromlogin) != "undefined" && fromlogin == "1") {
                jifen();
            }
        }, 500)
        setTimeout(() => {
            this.getUserInfo()
        }, 1000)
    },
    methods: {
        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) {
                }
            });
        },
        getUserInfo() {
            var that = this;
            console.log(that.memToken);
            $.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;
                    }
                }
            })
        },
        singDay() {
            if (!checkLogin()) {
                // goLogin();
                return false;
            }
            var that = this;
            that.integralCount = that.info.dayPoints;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/user/singDay",
                data: {
                    memToken: that.memToken,
                    dayPoints: that.info.dayPoints
                },
                success: function (res) {
                    if (res.code == 200 || res.data == 2) {
                        $(".integral-toast").show();
                        playMusic()
                        setTimeout(function () {
                            $(".integral-toast").fadeOut(200);
                        }, 2000);
                        that.getUserInfo();
                    } else {
                        alert("签到失败");
                    }
                }
            })
        },
        change() {
            var that = this;
            $("#fileInput").click();
        },
        buyRecord() {
            var that = this;
            console.log(this.memToken);
            window.location.href = serverHttp + "/user/buyRecord?from=H5&memToken=" + that.memToken;
        },
        pointsMall() {
            var that = this;
            window.location.href = serverHttp + "/user/pointsMall?from=H5&memToken=" + that.memToken;
        },

        certificationSm() {
            var that = this;
            window.location.href = serverHttp + "/user/certificationSm?from=H5&memToken=" + that.memToken;
        },
        certificationYs() {
            var that = this;
            window.location.href = serverHttp + "/user/certificationYs?from=H5&memToken=" + that.memToken;
        },
        userAccountNumber() {
            var that = this;
            window.location.href = serverHttp + "/user/userAccountNumber?from=H5&memToken=" + that.memToken;
        },
        editPass() {
            var that = this;
            window.location.href = serverHttp + "/user/editPass?from=H5&memToken=" + that.memToken;
        },
        callWe() {
            var that = this;
            window.location.href = serverHttp + "/user/callWe?from=H5&memToken=" + that.memToken;
        },
        aboutWe() {
            var that = this;
            window.location.href = serverHttp + "/user/aboutWe?from=H5&memToken=" + that.memToken;
        },
        logOut() {
            localStorage.removeItem('isVip')
            var that = this;
            window.location.href = serverHttp + "/login/logOut?from=H5&memToken=" + that.memToken;
        },

        gotoUserStudyRecord() {
            var that = this;
            window.location.href = serverHttp + "/user/userStudyRecord?from=H5&memToken=" + that.memToken;
        },
        chooseImg() {
            //上传图片https://files.imevos.com/upload/headimgs/4d1d21aebda441c9924daed3fefee8e3.jpg
            var formData = new FormData();
            formData.append('file', document.getElementById('fileInput').files[0]);
            formData.append('memToken', this.memToken);
            formData.append('type', 1);
            $.ajax({
                url: serverHttp + "/user/uploadHearderImg",
                type: 'post',
                data: formData,
                dataType: "json",
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.code == 200) {
                        alert("上传成功");
                    } else if (data.code == 10003) {
                        alert("为查询到用户");
                    } else if (data.code == 10010) {
                        alert("图片上传失败");
                    }
                },
                error: function (returndata) {
                }
            });
        }
    }
})
