$(document).ready(function() {

});

//获取用户VIP信息判断是否是VIP
function setPersonal() {
    // $.ajax({
    //     type: 'GET',
    //     url: 'http://192.168.1.241:9004/login/userInfo',
    //     headers: {
    //         "Content-Type": "application/json",
    //         "token": localStorage.getItem('token'),
    //     },
    //     success: function(res) {
    //         console.log(res);
    //         if (res.data.status1 == 1) {
    //             window.location.href = 'personalCenter.html'
    //         } else {
    //             window.location.href = 'personalCenter2.html'
    //         }
    //     }
    // })
    alert('请完善个人信息!')
}
$(".btnSave").click(function() {
    //姓
    var inputSurname = $("#surname").val();
    console.log(inputSurname);
    //名
    var inputUserName = $("#userName").val();
    console.log(inputUserName);
    //专业(null)
    var inputSpecialty = $("#specialty").val();
    console.log(inputSpecialty);
    //学校
    var inputSchool = $("#school").val();
    console.log(inputSchool);
    //手机号
    var inputPhone = $("#phone").val();
    console.log(inputPhone);
    //邮箱
    var inputEmailAddress = $("#emailAddress").val();
    console.log(inputEmailAddress);
    var reg_phone = /^1[3|4|5|6|7|8][0-9]\d{8}$/;
    if (inputSurname.length === 0) {
        alert("姓氏不能为空!")
    } else if (inputUserName.length === 0) {
        alert("名字不能为空!")
    } else if (inputSchool.length === 0) {
        alert("学校不能为空!")
    } else if (inputPhone.length === 0) {
        alert("手机号码不能为空!")
    } else if (!reg_phone.test(inputPhone)) {
        alert("请填写正确的手机号");
        return false;
    } else if (inputEmailAddress.length === 0) {
        alert("邮箱不能为空!")
    } else if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(inputEmailAddress) == false) {
        alert("邮箱格式不正确,请重新填写!")
    } else {
        var url = "/login/updateSysUser"; // 接口 
        var header = {
            "Content-Type": "application/json"
        }
        var params = JSON.stringify({
            emailAddress: inputEmailAddress,
            id: localStorage.getItem("userId"),
            img: null,
            phone: inputPhone,
            specialty: inputSpecialty,
            school: inputSchool,
            surname: inputSurname,
            userName: inputUserName
        })

        ajax(url, "PUT", header, params, function(res) {
            console.log(res);
            alert('保存成功!')
            window.location.href = 'index.html'
        }, function(res) {
            console.log(res);
        })



        // $.ajax({
        //     type: "PUT",
        //     url: "http://192.168.1.241:9004/login/updateSysUser",
        //     // dataType: "jsonp",
        //     headers: {
        //         "Content-Type": "application/json"
        //     },
        //     data: JSON.stringify({
        //         emailAddress: inputEmailAddress,
        //         id: localStorage.getItem("userId"),
        //         img: null,
        //         phone: inputPhone,
        //         specialty: inputSpecialty,
        //         school: inputSchool,
        //         surname: inputSurname,
        //         userName: inputUserName
        //     }),
        //     success: function(msg) {
        //         alert('保存成功!')
        //         window.location.href = 'index.html'
        //     },
        //     error: function(res) {}
        // });
    }
})