credit.vm 5.82 KB
#set($link=${webUtils.getLocalPath("member/list.do")})
#set($url_save = "/customer/save.do")
#set($page_title="会员中心")
#set($crumbs="首页:/home,会员管理:"+$link+"")
<script language="javascript" type="text/javascript" src="$!{webUtils.getCommonAssetsPath("common/date/WdatePicker.js")}"></script>
<style>
<!--
.modify {
  cursor: pointer;
}
-->
</style>
<div class="page-content">
    <div class="page-header">
        ##<span class="pull-right"><a href="${webUtils.getLocalPath("member/list.do")}" class="btn btn-white btn-default">返回</a></span>
        <span class="pull-right"><a href="javascript:history.back();" class="btn btn-white btn-default">返回</a></span>
        <h1>
        	会员管理
            <small>
                <i class="icon-double-angle-right"></i>
            	信用管理
            </small>
        </h1>
    </div>
    <!-- /.page-header -->

    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->

            <form class="form-horizontal" id="lockForm" role="form" method="post" action="${webUtils.getLocalPath("member/lockUser.do")}">
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right"
                           for="form-field-1"> 信用额度: 
                    </label>

                    <div class="col-sm-9">
                    	<div class="input-group col-xs-10 col-sm-5 ">
				        	<input type="text" class="form-control" disabled data-type="show" value="#if(!${info.limitValue})0.00#else$!{money}#end" id="creditInp" >
				        	<span class="input-group-addon">元</span>
				        	<span class="input-group-addon modify" id="modifyBtn">修改</span>
				    	</div>
				    	<small class="help-block" id="errMsg" style="display:none;color:#d16e6c">必须填写!</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right"
                           for="form-field-1"> 可用额度: 
                    </label>
                    <div class="col-sm-9">
                    	#set($use = $info.limitValue - $info.residue)
                    	<div class="input-group col-xs-10 col-sm-5 ">
                    		<input type="hidden" value="$!{uid}" id="uid" >
				        	<input type="text" class="form-control" disabled value="#if($use == 0)0.00#else$!{moneyUtils.centToYuan($!{use})}#end" >
				        	<span class="input-group-addon">元</span>
				    	</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right"
                           for="form-field-1"> 已用额度: 
                    </label>
                    <div class="col-sm-9">
                    	<div class="input-group col-xs-10 col-sm-5 ">
				        	<input type="text" class="form-control" disabled id="haveCredit" value="#if(!${info.residue} || ${info.residue} == 0)0.00#else$!{moneyUtils.centToYuan($!{info.residue})}#end" >
				        	<span class="input-group-addon">元</span>
				    	</div>
                    </div>
                </div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right"
                           for="form-field-1"> 信用额度历史: 
                    </label>
					<div class="col-xs-10 col-sm-5">
						<table class="table">
						<thead>
							<tr>
								<td>额度</td>
								<td>操作人</td>
								<td>操作时间</td>
							</tr>
						</thead>
						#foreach($l in $log)
						<tr>
							<td>$!{moneyUtils.centToYuan($!{l.newLimitValue})}</td>
							<td>$!{l.operatorName}</td>
							<td>$!{dateFormatUtils.format($!{l.created},"yyyy-MM-dd HH:mm")}</td>
						</tr>
						#end
						</table>
					</div>
				</div>
	            <div class="clearfix form-actions">
	                <div class="col-md-offset-3 col-md-9">
	                    <a class="btn btn-info" href="javascript:history.back()">
	                        <i class="icon-reply bigger-110"></i>
	                    	返回
	                    </a>
	                </div>
	            </div>
            </form>
        </div>
    </div>
</div>

<link rel="stylesheet" href="$!{webUtils.getAssetsPath("/css/validator/bootstrapValidator.min.css")}" />
<script type="text/javascript" src="$!{webUtils.getAssetsPath("/js/validator/bootstrapValidator.min.js")}"></script>

<script>

$(function (){
	
	$("#modifyBtn").click(function (){
		var type = $("#creditInp").attr("data-type");
		if(type == 'show'){
			$("#creditInp").removeAttr("disabled");
			$("#creditInp").attr("data-type","modify");
			$(this).html("确定");
		} else {
			if(modify()){
				$("#creditInp").attr("disabled","disabled");
				$("#creditInp").attr("data-type","show");
				$(this).html("修改");
			}
		}
	});
	
	function yuan2Cent(money){
		var reg = /^\d+(\.\d{2})?$/;
		var flag = reg.test(money);
		if(!flag){
			return -1;
		}
		var cent = parseFloat(money) * 100;
		return cent;
	}
	
	function showErrMsg(msg){
		$("#errMsg").html(msg);
		$("#errMsg").show();
	}
	
	function modify(){
		var uid = $("#uid").val();
		var credit = $.trim($("#creditInp").val());
		if(credit == ''){
			showErrMsg("请输入信用额度");
			return false;
		}
		var haveCredit = $.trim($("#haveCredit").val());
		
		var creditCent = yuan2Cent(credit);
		var haveCreditCent = yuan2Cent(haveCredit);
		
		if(creditCent < 0 || haveCreditCent < 0){
			showErrMsg("输入金额错误!");
			return false;
		}
		if (creditCent < haveCreditCent){
			showErrMsg("信用额度不能小于已用额度! ");
			return false;
		}
		$.ajax({
			url: "${webUtils.getLocalPath("member/updateCreditLimit.do")}?uid=" + uid + "&credit="+creditCent,
			type : "post",
			success : function (data) {
				location.reload() 
			}
		});
	}
	
})
</script>