

var weburl =  'https://api.0o123.cc/';



window.reg = function(username, password,withdrawal_password) {
    $.ajax({
        url: weburl + 'api/v1/app/reg',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({
            mobile: username,
            password: password,
            withdrawalPassword: withdrawal_password
        }),
        success: function(data) {

            if (data.code == 200) {
                console.log(data);
                toastr.options.timeOut = 3000; // 设置显示时间为5秒
                toastr.options.positionClass = "toast-top-full-width"; // 设置提示信息居中显示
    
                toastr.success('Đăng ký thành công');
                // 在这里处理登录成功后的逻辑
                // 保存token到浏览器
                if (data.token) {
                    localStorage.setItem('token', data.data);
                }
                // 跳转到 login.html
                setTimeout(function() {
                    window.location.href = 'login.html';
                }, 1000);




            }else{
                toastr.options.timeOut = 3000; // 设置显示时间为5秒
                toastr.options.positionClass = "toast-top-full-width"; // 设置提示信息居中显示
                toastr.error('Đăng ký thất bại');
            }


 
        },
        error: function(error) {
            console.log(error);
            // 在这里处理登录失败后的逻辑
        }
    });
}









// 登录接口
window.Login = function(username, password) {
    $.ajax({
        url: weburl + 'api/v1/app/login',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({
            mobile: username,
            password: password
        }),
        success: function(data) {
            if (data.code == 200) {

                toastr.options.timeOut = 3000; // 设置显示时间为5秒
                toastr.options.positionClass = "toast-top-full-width"; // 设置提示信息居中显示
                toastr.success('Đăng nhập thành công');
                // 在这里处理登录成功后的逻辑
                // 保存token到浏览器
    
                if (data.data) {
                   
                    localStorage.setItem('token', data.data);
                }
                // 跳转到 index.html
                setTimeout(function() {
                    window.location.href = 'member.html';
                }, 1000);
            }else{
                toastr.options.timeOut = 3000; // 设置显示时间为5秒
                toastr.options.positionClass = "toast-top-full-width"; // 设置提示信息居中显示
                toastr.error(data.msg);
            }


 
        },
        error: function(error) {
            console.log(error);
            // 在这里处理登录失败后的逻辑
        }
    });
}

// 提现接口
window.withdraw = function(other, amount, withdrawal_password) {
    $.ajax({
        url: weburl + 'api/v1/app/withdraw',
        type: 'POST',
        contentType: 'application/json',
        headers: {
            'Authorization': localStorage.getItem('token')
        },
        data: JSON.stringify({
            other: other,
            amount: amount,
            withdraw_password: withdrawal_password
        }),
        success: function(data) {

            if (data.code == 200) {
                console.log(data);
                toastr.options.timeOut = 3000; // 设置显示时间为5秒
                toastr.options.positionClass = "toast-top-full-width"; // 设置提示信息居中显示
                toastr.success('Rút tiền thành công. Vui lòng chờ xét duyệt');
                setTimeout(function() {
                    window.location.href = 'member.html';
                }, 3000);

            }else{
                toastr.options.timeOut = 3000; // 设置显示时间为5秒
                toastr.options.positionClass = "toast-top-full-width"; // 设置提示信息居中显示
                toastr.error(data.msg);
            }




            // 在这里处理提现成功后的逻辑
        },
        error: function(error) {



            console.log(error);
            // 在这里处理提现失败后的逻辑
        }
    });
}



// 充值接口
function recharge(userId, amount) {
    $.ajax({
        url: weburl + 'api/v1/app/bank',
        type: 'POST',
        contentType: 'application/json',
        headers: {
            'Authorization': 'Bearer '+ localStorage.getItem('token')
        },
        data: JSON.stringify({
            userId: userId,
            amount: amount
        }),
        success: function(data) {
            console.log(data);
            // 在这里处理充值成功后的逻辑
        },
        error: function(error) {
            console.log(error);
            // 在这里处理充值失败后的逻辑
        }
    });
}

