//提现申请

window.onload = function() {
	ifLogin(function(flag) {
		$('body').show();
	});
	$('.input_balance').val(0);

	var my_obj = getStorJson('my_commission_20170315');
	if(!my_obj) {
		alert('缺少参数');
		$('body').hide();
		return;
	}
    $('.input_balance').focus();
	var nick_name = my_obj['nick_name'];
	var balance = my_obj['balance'];
	var apply_rule = my_obj['apply_rule'];
	if(nick_name == '') {
		alert('缺少参数');
		$('body').hide();
		return;
	}
	if(balance == '') {
		alert('缺少参数');
		$('body').hide();
		return;
	}
	if(apply_rule) {
		var apply_arr = apply_rule.split('<br/>');
		var HTML = '';
		apply_arr.forEach(function(v) {
			var tempHTML = '<div class="txt">' + v + '</div>';
			HTML += tempHTML;
		})
		$('.top_text').html(HTML);
	} else {
		alert('缺少参数');
		$('body').hide();
		return;
	}

	$('body').show();
	$('.nick_name').text('转入微信钱包（' + nick_name + '）');
	if(balance == '') balance = 0;

	$('.balance').attr('data-balance', balance);
	$('.balance').text('可提现金额：￥' + parseFloat(balance).toFixed(2));

}

$(document).ready(function() {
	//立即提现
	$('.btn_go').on('click', function() {
		delay(go, 300);
		function go() {
			var money = $('.input_balance').val();
			var max_money = $('.balance').attr('data-balance');
			if(parseInt(money) <= 0) {
				alert('请输入提现金额');
				return;
			}
			if(parseInt(money) > parseInt(max_money)) {
				alert('可提现金额不足');
				return;
			}
			//提醒后端 金额必须 是50的倍数
			var data = {
				apply_commission: money
			}
			ZZLog(base_api + 'user/fx-user/cash-commission', JSON.stringify(data));
            $('#loadingToast').show();
			$.ajax({
				type: "post",
				url: base_api + 'user/fx-user/cash-commission',
				data: data,
				dataType: "json",
				success: function(res_data) {
					ZZLog(res_data);
					$('#loadingToast').hide();
					if(false == res_data['flag']) {
						if(codeNotLogin == res_data['code']) {
							//						alert(infoNotLogin);
							location.href = res_data['url'] + '/web/fx/';
						} else if(codeNotRegister == res_data['code']) {
							location.href = 'register.html';
						} else {
							alert(res_data['msg']);
						}
					} else {
						location.href = 'apply_success.html';
					}
				},
				error: function() {
					$('#loadingToast').hide();
					alert('后台接口错误');
				}
			});
		}
	})

	$('.look_apply_detail').on('click', function() {

		location.href = 'withdrawal_list.html';

	})
})