<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/html5.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/respond.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title></title>
</head>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 礼品卡管理 <span class="c-gray en">&gt;</span> 兑现管理 <span class="c-gray en">&gt;</span> 批量生成支付密码 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="pd-20">
		<form action="" method="post" id="myForm">
			<span>付费代理：</span>
			<select id='openId' name='openId' style="width: 150px;height: 30px;">
			</select>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<span>支付密码数量：</span>&nbsp;
			<input type="text" name="payCodeNum" id="payCodeNum" value="" placeholder="支付密码数量" style="width: 150px" class="input-text">
			<button name="" id="submitBtn" class="btn btn-success" type="button" onclick="submitAdd()">
				<i class="Hui-iconfont">&#xe665;</i>&nbsp;&nbsp;添加
			</button>
		</form>
		
		<div class="mt-20">
	<div class="text-c">
		</div>
		<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="150">支付密码</th>
					<th width="50">使用状态</th>
					<th width="80">推荐人</th>
					<th width="80">使用人</th>
					<th width="80">创建时间</th>
					<th width="80">使用时间</th>
				</tr>
			</thead>
			<tbody>
				<c:choose>
					<c:when test="${!(empty list)}">
						<c:forEach items="${list}" var="payCode">
							<tr class="text-c">
								<td>${payCode.codePassword }</td>
								<td id="codeStatus">
									<c:if test="${payCode.codeStatus == 1}">
										待使用
									</c:if>
									<c:if test="${payCode.codeStatus == 2}">
										已使用
									</c:if>
									<c:if test="${payCode.codeStatus == 3}">
										不可用
									</c:if>
								</td>
								
								<td>${payCode.codeReferrerName }</td>
								<td>${payCode.codeUseOpenName }</td>
								<td><fmt:formatDate value="${payCode.codeCreateDate }" pattern="YYYY-MM-dd HH:MM:ss"/></td>
								<td><fmt:formatDate value="${payCode.codeUpdateDate }" pattern="YYYY-MM-dd HH:MM:ss"/></td>
							</tr>
						</c:forEach>
					</c:when>
					<c:otherwise>
						<tr class="text-c">
							<td colspan="9">暂无数据</td>
						</tr>
					</c:otherwise>
				</c:choose>
			</tbody>
		</table>
	</div>
	</div>
<div align="right">
	<%@include file="/common/other/paper/pager.jsp"%>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
<script type="text/javascript">
$(function(){
	addSelect();
});

function addSelect() {
	var url = "${pageContext.request.contextPath}/admin/card/selectAgentList";
	$.ajax({
		   type: "POST",
		   url: url,
		   dataType: "json",
		   success: function(dt){
			   if (dt.status) {
					// 设置默认选项
					$("<option></option>").val("").text("---请选择付费代理商---").appendTo($("select"));
				   $(dt.data).each(function(){
					    console.log(this.agentOpenId);
					    $("<option></option>").val(this.agentOpenId).text(this.agentNickname).appendTo($("select"));
					  });
			   }
		   }
	}); 
}

function submitAdd() {
	var payCodeNum = $("#payCodeNum").val();
	var openId = $("#openId").val();
	if(payCodeNum == '' && openId == ''){
		layer.msg('请选择付费代理商或输入生成支付密码数量!',{icon: 5,time:2000});
		return false;
	}
	
	layer.confirm('确认要生成抵扣码？',
		function(index){
			$.ajax({
		        url: '${pageContext.request.contextPath }/admin/card/add_pay_password',
		        type: "post",
		        dataType: "json",
		        data: {'payCodeNum' : payCodeNum,'openId' : openId},
		        error:function(data){
		      	  layer.msg("生成抵扣码失败!请重试!",{icon: 5,time:2000});
		        },
		        success:  function(data){
		      	  layer.msg("生成抵扣码成功!",{icon: 1,time:2000});
		      	  window.location.href = '${pageContext.request.contextPath }/admin/card/pay_code_list';
		        }
   			});
		}
	);
}
</script>
</body>
</html>