personalCenter.js 8.6 KB
var screenType = ''
$(document).ready(function() {
    //获取屏幕宽度
    var screenWidth = $(window).width()
    console.log(screenWidth);
    //设置支付类型  1:网页支付  2:H5支付
    if (screenWidth < 768) {
        screenType = 2
    } else {
        screenType = 1
    }
    console.log(screenType);
    //获取个人信息(传一个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) {
            //     let title = `<div onClick='binding'>绑定</div>`
            //     $("#WXunbind").html(title)
            // } else {
            //     let title = `<div onClick='binding'>解绑</div>`
            //     $("#WXunbind").html(title)
            // }
            if (res.data.wname == null) {
                $("#WXunbind").html("绑定")
            } else {
                $("#WXunbind").html("解绑")
            }
            if (res.data.phoneNumber == null) {
                $("#Punbind").html("绑定")
            } else {
                $("#Punbind").html("解绑")
            }
            //缺一个img
            //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)
            let title = ` <img src="${res.data.img}" style='width:100%'>`
            $("#head-img").html(title)

        })
        //修改个人信息
    $(".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"; // 接口    
            // 调用公共ajax
            ajax(url2, "DELETE", header, function(res) {
                console.log(res);

            }, function(res) {
                console.log(res);
                alert("解绑成功!")
                location.reload();
            })
        })
        //删除手机号(传token)
    $("#Punbind").click(function() {
            var url3 = "/login/deletePhone"; // 接口    
            // 调用公共ajax
            ajax(url3, "DELETE", header, function(res) {
                console.log(res);

            }, function(res) {
                console.log(res);
                alert("解绑成功!")
                location.reload();
            })
        })
        //
    var header1 = {
        "Content-Type": "application/x-www-form-urlencoded",
    }
    ajax("/login/memberList", "GET", header1, function(res) {
        console.log(res);
    }, function(res) {
        console.log(res);
        var color = ['#66CA94', '#ff8000', '#6F1C0B'];
        var quarter = ['单月', '半年', '年度']
        var chooseTime = [1, 6, 12]
        for (var i in res.data) {
            console.log(res.data[i].memberType);

            let title = `
            <div onclick="clickVIPone(${res.data[i].id},'${res.data[i].memberType}',${chooseTime[i]},${res.data[i].memberMoney})" class="personal-vip-basic" id='personal_vip_${res.data[i].id}'>
                <div class="personal-vip-info" style='background-color:${color[i]}'>
                    <p>${res.data[i].memberType}</p>
                    <a>${res.data[i].memberName}</a>
                </div>
                <div style="background: #fff;">
                    <div style="text-align: center;padding: 5%;">
                        <a style="color: ${color[i]};">
                            <span style="font-size: 2em;">${res.data[i].memberMoney}</span> /${quarter[i]}
                        </a>
                    </div>
                    <div class="personal-ol">${res.data[i].introduce}</div>
                </div>
            </div>`
            $("#meau_nav").append(title)
        }
        $('.personal-vip-basic').click(function() {
            // var index = $(this).index();
            $(this).addClass('active-click').siblings().removeClass('active-click');
        })
    })
});

// $('#meau_nav>div').click(function() {
//     // var index = $(this).index();
//     $(this).addClass('active-click').siblings().removeClass('active-click');
// })

var actualFee = ''
var memberMonth = ''
var memberName = ''
var paymentType = ''

function clickVIPone(id, type, time, money) {

    console.log(id);
    console.log(type);
    console.log(time);
    console.log(money);

    actualFee = money
    memberMonth = time
    memberName = type
}

// function clickVIPtwo() {
//     actualFee = 399
//     memberMonth = 6
//     memberName = '标准会员'
// }

// function clickVIPthree() {
//     actualFee = 699
//     memberMonth = 12
//     memberName = '超级会员'
// }
//获得支付方式选值
function checkRadio() {
    paymentType = $("input[name='zhifu']:checked").val()
}
//立即支付
function payment() {
    console.log(paymentType);
    console.log(actualFee);
    console.log(memberMonth);
    console.log(memberName);
    console.log(screenType);

    var header = {
        "Content-Type": "application/json",
        "token": localStorage.getItem('token'),
    }
    var header1 = {
        "Content-Type": "application/x-www-form-urlencoded",
        "token": localStorage.getItem('token'),
    }
    var params = JSON.stringify({
        actualFee: actualFee,
        memberMonth: memberMonth,
        memberName: memberName,
        paymentType: paymentType
    })

    // 支付下单获取订单号
    ajax("/orderLog/orderAdd", "POST", header, params, function(res) {
        console.log(res);
        console.log(res);
        console.log(res.data);

        $(".hide_box").fadeToggle();
        $(".shang_box").fadeToggle();

        var params1 = {
            id: res.data,
            type: screenType
        }

        //微信支付
        ajax("/pay/createNative", "GET", header1, params1, function(res) {
            console.log(res);
            let title = `<img src="${res.data.codeUrl}" alt="扫码支付" title="扫一扫" >`
            $(".shang_payimg").html(title)
        }, function(res) {})
    }, function(res) {})
}
//获取用户VIP信息判断是否是VIP
function ifVIP() {
    var url5 = "/login/userInfo"; // 接口    
    var header = {
            "Content-Type": "application/json",
            "token": localStorage.getItem('token'),
        }
        // 调用公共ajax
    ajax(url5, "GET", header, function(res) {
        console.log(res);

    }, function(res) {
        console.log(res);
        if (res.data.status1 == 1) {
            window.location.href = 'personalCenter.html'
        } else {
            window.location.href = 'aboutUs.html'
        }
    })
}