mui.ready(function() {
	$.ajax({
		"type": "post",
		"url": "/iamberry/wechat/WithDrawalsLogs/getWithdrawPage",
		"dataType": "json",
		"data": {
			"openid": "oaH_GwHCnG8fZPwI8c4D_SqLmV0Y" //"openid":"230"
		},
		"success": function(res) {
			//alert(res.data.amount);
			$("#allowMoney").html(accDiv(res.data.amount, 100));
			$("#lessMoney").text(accDiv(res.data.lessMoney, 100));
			$("#withdrawalsCount").text(res.data.withdrawalsCount);
			
			//上次的提款信息
			var Withdraw  = res.data.Withdraw;
			if(Withdraw){
				$("#userName").val(Withdraw.withDrawalsName);		//姓名
				$("#tel").val(Withdraw.tel);		//电话
				$("#bankCount").val(Withdraw.accountNo);		//银行卡号
				$("#bankLocal").val(Withdraw.bankLocal);	// 支行
			}
			
			document.querySelector('.loading-bg').style.display = 'none';
		}
	});
});

//发送请求
function ajaxSendApply(url, data) {
	$.ajax({
		url: url,
		data: data,
		dataType: "json",
		asyn: false,
		success: function(data) {
			var obj = eval("(" + data + ")");
			mui.alert(data.message);
		},
		error: function(data) {
			mui.alert(data.message);
		}
	});

}

var flag = true;
//提交申请
function submitOrder() {
	if(!flag) {
		getAlert("正在处理中，请稍等！");
	}
	var limitMoney = parseInt($("#allowMoney").html());

	var data = {
		"openid": "", //"openid":"230"
		"withDrawalsName": $.trim($("#userName").val()),
		"withDrawalsNum": $("#amount").val() == "" ? 0 : $("#amount").val(),
		"tel": $.trim($("#tel").val()),
		"accountNo": $.trim($("#bankCount").val()),
		"bankLocal": $("#bankLocal").val()
	}

	if(!checkAddress(data.withDrawalsName)) {
		//alert("用户名不能为空");
		getAlert("用户名为空或者格式不正确");
		return;
	} else if(!(/^1[3|4|5|7|8]\d{9}$/.test(data.tel))) {
		mui.alert("手机号码有误，请重填");
		return false;
	} else if(!(/^[1-9]+[0-9]*$/.test(data.withDrawalsNum))) {
		//alert("请输入合法的数字!");   !checkMoney "^[1-9]*[0-9]*$"
		getAlert("请输入正确的金额!");
		return;
	} else if(data.withDrawalsNum < 1) {
		getAlert("金额不能小于0");
		return;
	} else if(data.withDrawalsNum > limitMoney) {
		getAlert("金额超过账户现有金额！");
		return;
	} else if(!(/^\d{15}\d{1,4}$/.test(data.accountNo))) {
		mui.alert("请输入正确的银行卡号!");
		return;

	} else if(!checkAddress(data.bankLocal)) {
		getAlert("支行地址填写不正确！");
		return;
	}
	flag = false;
	data.withDrawalsNum = parseInt(data.withDrawalsNum);
	$.ajax({
		"type": "post",
		"url": "/iamberry/wechat/WithDrawalsLogs/submitWithdraw",
		"dataType": "json",
		"data": data,
		"success": function(res) {
			flag = true;
			if(res.status) {
				window.location.href = "/iamberry/wechat/drp/withdrawalssubmitSuccess";
			} else {
				getAlert("申请失败：" + res.message == "null" ? "" : res.message);
			}

		}
	});

}

//跳转到提现记录表
function goHistoryWithdrawals() {
	window.location.href = "/iamberry/wechat/drp/withdrawalsList";
}

//提现信息
function getAlert(message) {
	mui.alert(message, '爱贝源-消息提醒', function() {
		//console.log("您关闭了警告框");
	});
}