<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>费率管理</title>
	<meta name="decorator" content="default"/>
    <style>
        .input_border{
            border-radius:4px;
            border:1px solid #c3c3c3;
            height: 25px;
        }
        .input_border:focus{
            border:1px solid #0bbbee;
        }
        .input_s{
            width: 50px;
        }
        .input_m{
            width: 100px;
        }
        .input_l{
            width: 150px;
        }
    </style>
	<script type="text/javascript">
		$(document).ready(function() {
			$(".save").click(function () {
			    console.log(",,,,,")
                $this = $(this);
			    var id = $this.attr("id");
                $("#form-save"+id).submit();
                console.log( $("#form-save"+id))

            })
		});
		function page(n,s){
			$("#searchForm").attr("action","${ctx}/youka/rate/list");
			$("#searchForm").submit();
	    	return false;
	    }

        function saveAll(n,s){
		    var datas = [];
			var trs = $("#contentTable tr");
			console.log(trs);
			var len = trs.size() - 1;
			console.log(len);
			for(var i=0 ;i<len;i++){
                var data = new Object();
                data.userLevel = $("#userLevel"+i).val();
                data.payMethod = $("#payMethod"+i).val();
                data.payChannel  = $("#payChannel"+i).val();
                data.rate  = $("#rate"+i).val();
                data.balance  = $("#balance"+i).val();
                data.singleLimit  = $("#singleLimit"+i).val();
                data.dayLimit  = $("#dayLimit"+i).val();

                data.code  = $("#code"+i).val();
                data.rateType  = $("#rateType"+i).val();
                data.siglePrice  = $("#siglePrice"+i).val();
                datas.push(data);
			}
			console.log(datas);
			console.log(JSON.stringify(datas));
            $.ajax({
                url:"${ctx}/youka/rateBody/saveAll",
                type: "POST",
                dataType : 'json',
                data:
					{
                        lists:JSON.stringify(datas)
					}
                ,
                async:false,
                success: function(data){
					alert("保存成功");
                }
            })

            return false;
        }



	</script>
</head>
<body>
	<%--<div id="importBox" class="hide">--%>
		<%--<form id="importForm" action="${ctx}/youka/user/import" method="post" enctype="multipart/form-data"--%>
			<%--class="form-search" style="padding-left:20px;text-align:center;" onsubmit="loading('正在导入，请稍等...');"><br/>--%>
			<%--<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　--%>
			<%--<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>--%>
			<%--<a href="${ctx}/youka/user/import/template">下载模板</a>--%>
		<%--</form>--%>
	<%--</div>--%>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/youka/rate/list">费率列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="youkaRate" action="${ctx}/youka/rate/list" method="post" class="breadcrumb form-search ">

		<ul class="ul-form">

			<%--<li>--%>
				<%--<form:select path="level" cssStyle="width: 100px">--%>
					<%--<form:option value="">--%>
						<%--全部--%>
					<%--</form:option>--%>
					<%--<form:option value="S">--%>
						<%--管理员--%>
					<%--</form:option>--%>
					<%--<form:option value="A">--%>
						<%--王者会员--%>
					<%--</form:option>--%>
					<%--<form:option value="B">--%>
						<%--钻石会员--%>
					<%--</form:option>--%>
					<%--<form:option value="C">--%>
						<%--黄金会员--%>
					<%--</form:option>--%>
					<%--<form:option value="D">--%>
						<%--白银会员--%>
					<%--</form:option>--%>
					<%--<form:option value="E">--%>
						<%--青铜会员--%>
					<%--</form:option>--%>
				<%--</form:select></li>--%>
			<%--<li class="clearfix"></li>--%>
			<li><label>支付方式：</label><form:select cssStyle="width: 100px;"  path="payMethod" items="${fns:getDictList('pay_rate_method')}" itemLabel="label" itemValue="value" htmlEscape="false" />
			</li>
			<li><label>支付渠道：</label><form:select cssStyle="width: 150px;"   path="payChannel" items="${fns:getDictList('pay_channel')}" itemLabel="label" itemValue="value" htmlEscape="false" />
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" onclick="return page();"/>
				<%--<input id="btnExport" class="btn btn-primary" type="button" value="导出"/>--%>
				<%--<input id="btnImport" class="btn btn-primary" type="button" value="导入"/>--%>
			</li>

			<li class="btns"><input id="saveSubmit" class="btn btn-primary" type="submit" value="一键保存" onclick="return saveAll();"/>
			</li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
		<table id="contentTable" class="table table-striped table-bordered table-condensed">
			<thead><tr><th>序号</th><th class="sort-column login_name">用户类型</th><th class="sort-column name">汇率</th><th>汇率类型</th><th>单笔价格</th><td>结算</td><td>单笔限额</td><td>当天额度</td><shiro:hasPermission name="sys:user:edit"><th>操作</th></shiro:hasPermission></tr></thead>
			<tbody>
			<c:forEach items="${userLevels}" var="userLevel" varStatus="indexs">
				<tr>
					<form action="${ctx}/youka/rate/save" id="form-save${indexs.index}" method="post" class="breadcrumb form-save">
						<c:set var="rateEntity" value="${map[userLevel.level]}"></c:set>
						<td>${indexs.index}</td>
						<td>
							<input id="payMethod${indexs.index}" name="payMethod" value="${youkaRate.payMethod}" style="display: none"/>
							<input id="code${indexs.index}" name="code" value="${rateEntity.code}" style="display: none"/>
							<input id="payChannel${indexs.index}" name="payChannel" value="${youkaRate.payChannel}" style="display: none"/>
							<input id="userLevel${indexs.index}" name="userLevel" value="${userLevel.level}" style="display: none"/>
							<span>${userLevel.name}</span>
						</td>
						<td><input class="input_border input_m" id="rate${indexs.index}" name="rate" value="${rateEntity.rate}"></td>
						<td>
							<select id="rateType${indexs.index}" name="rateType" style="width: 120px;">
								<c:forEach items="${HL3rates}" var="HL3rate">
									<c:if test="${HL3rate.value eq rateEntity.rateType}">
										<option selected="selected" value="${HL3rate.value}">${HL3rate.label}</option>
									</c:if>
									<c:if test="${HL3rate.value ne rateEntity.rateType}">
										<option value="${HL3rate.value}">${HL3rate.label}</option>
									</c:if>
								</c:forEach>
							</select>
								<%--<input class="input_border input_m"  name="rateType" value="${rateEntity.rateType}">--%>
						</td>
						<td>
							<input id="siglePrice${indexs.index}" class="input_border input_m"  name="siglePrice" value="${rateEntity.siglePrice}">
						</td>
						<td><input id="balance${indexs.index}" class="input_border input_m"  name="balance" value="${rateEntity.balance}"></td>
						<td>
							<input id="singleLimit${indexs.index}" class="input_border input_m"  name="singleLimit" value="${rateEntity.singleLimit}">
						</td>
						<td>
							<input id="dayLimit${indexs.index}" class="input_border input_m"  name="dayLimit" value="${rateEntity.dayLimit}">
						</td>
							<%--
                        <td>${user.roleNames}</td> --%>

						<td>
							<shiro:hasPermission name="youka:rate:save">
								<input id="${indexs.index}" type="button" class="save btn" value="保存">
							</shiro:hasPermission>
						</td>

					</form>
				</tr>

			</c:forEach>

			</tbody>
		</table>


</body>
</html>