personalCenter.js 13.1 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%;height: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 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("/login/updateSysUser", "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;" class='vip_info'>
                        <a style="color: ${color[i]};" class='vip_info_a'>
                            <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.data);//订单号
        console.log(paymentType);
        var params1 = {
                id: res.data,
                type: screenType
            }
            //支付类型paymentType : 1微信  2支付宝
        if (paymentType == 1) {
            var params1 = {
                id: res.data,
                type: screenType
            }
            console.log(res.data);
            console.log(screenType);
            console.log(params1);
            
            //微信支付
            ajax("/pay/createNative", "GET", header1, params1, function(res1) {
                console.log(res1);
                if(screenType == 1){
                    $(".hide_box").fadeToggle();
                    $(".shang_box").fadeToggle();
                    let title = `<img src="${res1.data.codeUrl}" alt="扫码支付" title="扫一扫" >`
                    $(".shang_payimg").html(title)
                        //支付轮询
                var params3 = { id: res1.data.outTradeNo }
                var timeInterval = setInterval(function() {
                    ajax("/orderLog/test", "GET", header1, params3, function(res2) {
                        console.log(res2.data);
                        if (res2.data == '2') {
                            clearInterval(timeInterval)
                            alert("支付成功,审核通过后即可成为会员!")
                            window.location.href = 'personalCenter2.html'
                            // $('.payStatus').html("支付成功,审核通过后即可成为会员!")
                        }
                    }, function(res) {})
                }, 5000)
                }else{
                    window.location.href = res1.data.codeUrl
                        //支付轮询
                    var params3 = { id: res1.data.outTradeNo }
                    var timeInterval = setInterval(function() {
                        ajax("/orderLog/test", "GET", header1, params3, function(res2) {
                            console.log(res2.data);
                            if (res2.data == '2') {
                                clearInterval(timeInterval)
                                alert("支付成功")
                                window.location.href = 'personalCenter2.html'
                                // $('.payStatus').html("支付成功,审核通过后即可成为会员!")
                            }
                        }, function(res) {})
                    }, 5000)
                }
                //订单号
                console.log(res1.data.outTradeNo);
                //支付轮询
                // var params3 = { id: res1.data.outTradeNo }
                // var timeInterval = setInterval(function() {
                //     ajax("/orderLog/test", "GET", header1, params3, function(res2) {
                //         console.log(res2.data);
                //         if (res2.data == '2') {
                //             clearInterval(timeInterval)
                //             window.location.href = 'personalCenter.html'
                //             alert("支付成功,审核通过后即可成为会员!")
                //             $('.payStatus').html("支付成功,审核通过后即可成为会员!")
                //         }
                //     }, function(res) {})
                // }, 2000)
            }, function(res) {})
        } else if (paymentType == 2) {
            // $(".hide_box").fadeToggle();
            // $(".shang_box").fadeToggle();
            //支付宝支付
            var url1 = 'http://start-line.cn/personalCenter.html'
            var params3 = {
                id: res.data,
                type: screenType,
                returnUrl: url1
            }
            ajax("/zfbPay/alipay", "GET", header1, params3, function(res) {
                console.log(res);
                $(".zhifubao_form").html(res)
                 //支付轮询
                var params3 = { id: res1.data.outTradeNo }
                var timeInterval = setInterval(function() {
                    ajax("/orderLog/test", "GET", header1, params3, function(res2) {
                        console.log(res2.data);
                        if (res2.data == '2') {
                            clearInterval(timeInterval)
                            window.location.href = 'personalCenter.html'
                            alert("支付成功")
                            // $('.payStatus').html("支付成功,审核通过后即可成为会员!")
                        }
                    }, function(res) {})
                }, 2000)
                
            }, function(res) {})
        } else {
            alert("请选择支付类型!")
        }



    }, function(res) {
        console.log(res);
    })
}
//获取用户VIP信息判断是否是VIP
// function ifVIP() {
//     var header = {
//             "Content-Type": "application/json",
//             "token": localStorage.getItem('token'),
//         }
//     ajax("/login/userInfo", "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'
//         }
//     },function(res){
//         console.log(res);
//         if(res){
//             alert("请您先登录!")
//         }
//     })
// }
function aboutUs(){
    window.location.href = 'aboutUs.html'
}
function myAcc(){
    window.location.href ='personalCenter.html'
}