Vue.config.devtools = true;
var v = new Vue({
    el:".container",
    data:{
        name:"",
        phone:"",
        adress:"",
        id:0,
        integralType: "",
        integralCount: "",
    },
    created:function (){
        var that = this;
        if(!checkLogin()){
            // goLogin();
            return false;
        }
        that.id = $("#id").val();
        if($.cookie("memToken")){
            that.memToken = $.cookie("memToken");
            that.isLogin=1;
        }
        if($.cookie("memHeadImg")){
            that.memHeadImg = $.cookie("memHeadImg");
        }
    },
    mounted:function (){
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        },500)
    },
    methods:{
        saveReceiptInformation(){
            if(!checkLogin()){
                // goLogin();
                return false;
            }
            var that = this;
            if (that.name == undefined ||that.name == null || that.name.trim() == '') {
                alert("请填写姓名")
                return;
            }
            if (that.adress == undefined ||that.adress == null || that.adress.trim() == '') {
                alert("请填写收货地址")
                return;
            }
            const regex = /^1[3456789]\d{9}$/;//使用此正则即可
            if (!regex.test(that.phone)) {
                alert("请填写正确的手机号")
                return;
            }

            $.ajax({
                type : 'POST',
                url : serverHttp+"/user/saveReceiptInformation",
                data : {
                    memToken:that.memToken,
                    id:that.id,
                    name:that.name,
                    phone:that.phone,
                    adress:that.adress
                },
                success:function (res) {
                    if (res.code == 200) {
                        $(".toast").show();
                        setTimeout(function () {
                            $(".toast").hide();
                            window.location.href=serverHttp+"/user/userExchange?from=H5";
                        },2000);
                    } else {
                        alert("商品兑换失败");
                    }
                }
            })
        }
    }
})
