personalCenter2.js 4.4 KB
$(document).ready(function() {

    //获取个人信息(传一个token)
    var url = "/login/userInfo"; // 接口    
    var header = {
            "Content-Type": "application/x-www-form-urlencoded",
            "token": localStorage.getItem('token'),
        }
        // 调用公共ajax
    ajax(url, "GET", header, function(res) {
            console.log(res);
        }, function(res) {
            console.log(res);
            if (res.data.wname == null) {
                $("#WXunbind").html("绑定")
            } else {
                $("#WXunbind").html("解绑")
            }
            if (res.data.phoneNumber == null) {
                $("#Punbind").html("绑定")
            } else {
                $("#Punbind").html("解绑")
            }
            //input用val,a用html
            let a = res.data.surname + res.data.userName
            console.log(a);
            $("#fullName").html(a)
            $('#phone').val(res.data.phone)
            $('#surname').val(res.data.surname)
            $('#userName').val(res.data.userName)
            $('#specialty').val(res.data.specialty)
            $('#school').val(res.data.school)
            $('#emailAddress').val(res.data.emailAddress)
            $('#WXname').html(res.data.wname)
            $('#Pnumber').html(res.data.phoneNumber)
            $("#startTime").html(res.data.startTime)
            $("#dateTime").html(res.data.dateTime)
            let title = ` <img src="${res.data.img}" style='width:100%'>`
            $("#head-img").html(title)
            if (res.data.memberName == '1') {
                $("#vip-info").html("基础会员")
            } else if (res.data.memberName == '2') {
                $("#vip-info").html("标准会员")
            } else if (res.data.memberName == '3') {
                $("#vip-info").html("超级会员")
            } else {
                $("#vip-info").html("无会员信息")
            }
        })
        //修改个人信息
    $(".btnSave button").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 url1 = "/login/updateSysUser"; // 接口    
        var header1 = {
            "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
        ajax(url1, "PUT", header1, params, function(res) {
            console.log(res);
            alert('保存成功!')
            location.reload();
        }, function(res) {
            console.log(res);
        })
    })



    //删除微信(传token)

    $("#WXunbind").click(function() {
        var url2 = "/login/deleteWeXin"; // 接口    
        var header = {
                "Content-Type": "application/x-www-form-urlencoded",
                "token": localStorage.getItem('token'),
            }
            // 调用公共ajax
        ajax(url2, "DELETE", header, function(res) {
            console.log(res);

        }, function(res) {
            console.log(res);
            alert("解绑成功!")
            location.reload();
        })
    })

    //删除手机号(传token)
    $("#Punbind").click(function() {
        var url = "/login/deletePhone"; // 接口    
        var header = {
                "Content-Type": "application/x-www-form-urlencoded",
                "token": localStorage.getItem('token'),
            }
            // 调用公共ajax
        ajax(url, "DELETE", header, function(res) {
            console.log(res);

        }, function(res) {
            console.log(res);
            alert("解绑成功!")
            location.reload();
        })
    })


});