/**
* Created by Demon-pro on 2015/7/27.
*/
var recharge = function () {
function clientRechargeValidate() {
//校验是选择或者填写充值金额
var money = getOrPayMoney();
if (money == 0) {
alert("充值金额不能为空");
return false;
}
var orUserTypeShow = getOrUserType();
if (orUserTypeShow == 1 && money < 30000) {
alert("申请开店,至少充值30000元")
return false;
}
return true
}
//获取充值金额
function getOrPayMoney() {
var orPayMoney = 0;
$("li[name=orPayMoney]").each(function () {
if ($(this).hasClass("sss")) {
orPayMoney = parseFloat($(this).html(), 2);
}
})
if (orPayMoney != 0) return orPayMoney;
var otherMoney = $("#otherMoney").val()
if (otherMoney.trim() != "") {
orPayMoney = parseFloat(otherMoney, 2);
}
return orPayMoney;
}
//获取商户类型,开店,普通充值
function getOrUserType() {
var orUserType = 1;
$("li[name=orUserType]").each(function () {
if ($(this).hasClass("sss")) {
orUserType = $(this).val();
}
})
return orUserType;
}
return {
init: function () {
//客户类型绑定事件 1 开店 2 会员
$("li[name=orUserType]").click(function () {
$("#otherMoney").val("");
var orUserType = $(this).val();
if (orUserType == dict.orUserType2) {
$("li[name=orPayMoney]").show();
return;
}
//循环支付金额按钮
$("li[name=orPayMoney]").each(function () {
//只显示30000的标签
var money = $(this).html();
if (money == 30000) {
$(this).show();
} else {
$(this).hide();
}
})
$("li[name=orPayMoney][html='30000']").show()
})
$("li[name=orPayMoney]").click(function () {
$("#otherMoney").val("");
})
},
clientRecharge: function (orPayType) {
if (!clientRechargeValidate()) {
return;
}
var money = getOrPayMoney();
var type = orPayType == 1 ? "微信" : "支付宝";
var orUserTypeShow = getOrUserType() == 1 ? ",申请开店" : "";
if (!confirm("您确定" + type + "充值" + money + "元" + orUserTypeShow))return;
var object={
orStatus:2,
orPayType:orPayType,
orUserType:getOrUserType(),
orPayMoney:getOrPayMoney()
}
$.ajax({
url: basePath + "recharge/clientRecharge",
data: JSON.stringify(object),
contentType: "application/json; charset=utf-8",
type: "post",
success: function (data) {
if (data.ok) {
formSub(basePath + "recharge/clientRechargeSuccess?id="+data.returnMsg);
} else if (data.error) {
alert(data.returnMsg);
return false;
}
}
});
}
}
}();
var basePath = (function () {
var url = window.location + "";
var h = url.split("//");
var x = h[1].split("/");
return h[0] + "//" + window.location.host + "/" + x[1] + "/";
})();
function formSub() {
var $form = $("form");
if ($form.size() == 0) {
$("body").wrap('
');$form = $("form");
}
switch (arguments.length) {
case 0:
$form.attr("method", "post").submit();
break;
case 1:
$form.attr("method", "post").attr("action", arguments[0]).submit();
break;
case 2:
arguments[0].attr("method", "post").attr("action", arguments[1]).submit();
break;
}
}
var dict = {
//商户
orUserType1: 1,
//vip
orUserType2: 2,
//支付状态 1 待支付 2 已支付,3支付成功
orStatus1: 1,
orStatus2: 2,
orStatus3: 3
}