<!--#include file="admin_conn.asp"-->
<%
chkLogin
dim action : action = be("get","action")

select case action
	case "save" : save
	case "del" : del
	case else : headAdmin "充值卡管理" : main
end select
dispseObj()

sub save
	dim flag,num,c_id,c_number,c_pass,c_money,c_point,c_addtime,i,colarr,valarr,where
	flag=be("all","flag") : num=be("all","num") :  c_id=be("all","c_id")
	c_money=be("all","c_money") :  c_point=be("all","c_point") 
	
	if flag="edit" then
		colarr = Array("c_money","c_point")
		valarr = Array(c_money,c_point)
		where = "c_id="&c_id
		objdb.Update "{pre}user_card",colarr,valarr,where
	else
		num = cint(num)
		colarr = Array("c_number","c_pass","c_money","c_point","c_addtime")
		for i=1 to num
			c_number = getRndStr(10) : c_pass = getRndStr(6) : c_addtime=now()
			valarr = Array(c_number,c_pass,c_money,c_point,c_addtime)
			objdb.Add "{pre}user_card",colarr,valarr
		next
	end if
	writee "保存完毕"
end sub

sub main
	dim used : used = be("all","used")
	dim sale : sale = be("all","sale")
	dim pagenum : pagenum = be("all","page")
	if not isNum(pagenum) then pagenum = 1
	if pagenum < 1 then pagenum = 1
	pagenum = cint(pagenum)
	dim sql : sql = "select c_id,c_number,c_pass,c_money,c_point,c_addtime,c_usetime,c_user,c_used,c_sale from {pre}user_card WHERE 1=1 "
	if not isN(used) then sql = sql & " and c_used="&used
	if not isN(sale) then sql = sql & " and c_sale="&sale
	dim rs : set rs = objdb.db(sql,"rs1")
%>
<script language="javascript">
$(document).ready(function(){
	$("#form2").validate({
		rules:{
			c_num:{
				number:true
			},
			c_money:{
				required:true,
				number:true,
				min:1
			},
			c_point:{
				required:true,
				number:true,
				min:1
			}
		}
	});
	$('#form1').form({
		onSubmit:function(){
			if(!$("#form1").valid()) {return false;}
		},
	    success:function(data){
	        $.messager.alert('系统提示', data, 'info',function(){
	        location.href=location.href;
	        });
	    }
	});
	$('#form2').form({
		onSubmit:function(){
			if(!$("#form2").valid()) {return false;}
		},
	    success:function(data){
	        $.messager.alert('系统提示', data, 'info');
	    }
	});
	$("#btnDel").click(function(){
			if(confirm('确定要删除吗')){
				$("#form1").attr("action","admin_ajax.asp?action=del&flag=batch&tab={pre}user_card");
				$("#form1").submit();
			}
			else{return false}
	});
	$("#btnAdd").click(function(){
		$("#trnum").css("display","block");
		$('#form2').form('clear');
		$("#flag").val("add");
		$('#win1').window('open'); 
	});
	$("#btnCancel").click(function(){
		location.href= location.href;
	});
	$("#used").change(function(){
		var used = $(this).children('option:selected').val();
		location.href= "admin_user_card.asp?used="+used;
	});
	$("#sale").change(function(){
		var used = $(this).children('option:selected').val();
		location.href= "admin_user_card.asp?sale="+used;
	});
	$.fn.datebox.defaults.formatter = function(date) {
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	var d = date.getDate();
	return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);
	};
});
function edit(id)
{
	$('#form2').form('clear');
	$("#trnum").css("display","none");
	$("#flag").val("edit");
	$('#win1').window('open');
	$('#form2').form('load','admin_ajax.asp?action=getinfo&tab={pre}user_card&col=c_id&val='+id);
}
</script>
<table class="tb">
	<tr>
	<td colspan="5" ><strong>过滤条件：</strong>
	<select id="used" name="used">
	<option value="">请选择使用情况</option>
	<option value="0" <%if used="0" then %> selected <%end if%>>未使用</option>
	<option value="1" <%if used="1" then %> selected <%end if%>>已使用</option>
	</select>
	&nbsp;<select id="sale" name="sale">
	<option value="">请选择出售情况</option>
	<option value="0" <%if sale="0" then %> selected <%end if%>>未使用</option>
	<option value="1" <%if sale="1" then %> selected <%end if%>>已使用</option>
	</select>
	</td>
	</tr>
</table>

<form action="" method="post" id="form1" name="form1">
<table class="tb">
	<tr>
    <td width="4%">&nbsp;</td>
    <td	width="10%">充值卡号</td>
    <td width="10%">密码</td>
    <td width="10%">面值</td>
    <td width="10%">点数</td>
    <td width="10%">出售情况</td>
    <td width="10%">使用情况</td>
    <td width="10%">使用者</td>
    <td width="15%">充值时间</td>
    <td width="10%">操作</td>
	</tr>
	<%
		if rs.eof then
	%>
    <tr><td align="center" colspan="11" >没有任何记录!</td></tr>
    <%
		else
		dim i,c_sale,c_used,c_user
		rs.PageSize = app_pagenum
	    rs.AbsolutePage = pagenum
	  	for i = 1 to rs.PageSize
	  		if rs.eof then exit for
	  		c_sale = rs("c_sale") : c_used=rs("c_used") : c_user=rs("c_user")
	  		if c_sale=1 then c_sale="已售出" else c_sale="<font color=red>未出售</font>"
	  		if c_used=1 then c_used="已使用" else c_used="<font color=red>未使用</font>"
	  		if c_user>0 then
	  			dim rsb : set rsb = objdb.DB("SELECT u_name FROM {pre}user WHERE u_id="&c_user,"rs1")
	  			if rsb.eof and rsb.bof then
	  				c_user = "未知"
	  			else
         			c_user = rsb("u_name")
         		end if
         		objdb.C(rsb)
         	else
         		c_user=""
         	end if
	%>
	<tr>
    <td><input type="checkbox" name="c_id" id="c_id" value="<%=rs("c_id")%>"></td>
    <td><%=rs("c_number")%></td>
    <td><%=rs("c_pass")%></td>
    <td><%=rs("c_money")%>元</td>
    <td><%=rs("c_point")%>点</td>
    <td><%=c_sale%></td>
    <td><%=c_used%></td>
    <td><%=c_user%></td>
    <td><%=rs("c_usetime")%></td>
    <td>
	<a href="javascript:void(0)" onclick="edit('<%=rs("c_id")%>');return false;">修改</a> |
	  <a href="admin_ajax.asp?action=del&tab={pre}user_card&c_id=<%=rs("c_id")%>" onClick="return confirm('确定要删除吗?');">删除</a>
	</td>
	</tr>
	<%
	rs.movenext
	next
	end if
	%>
	<td colspan="11">全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onClick="checkAll(this.checked,'c_id')" />
	&nbsp;<input type="button" id="btnDel" value="批量删除" class="input" />
	&nbsp;<input type="button" id="btnAdd" value="添加"  class="input"/>
	</td></tr>
	<tr align="center">
	<td colspan="11">
	<%=pagelist_manage(rs.PageCount,pagenum,rs.RecordCount,app_pagenum,"admin_user_card.asp?page={p}")%>
	</td>
	</tr>
</table>
</form>

<div id="win1" class="easyui-window" title="窗口" style="width:400px;padding:5px;" closed="true" closable="false" minimizable="false" maximizable="false">
<form action="?action=save&tab={pre}user_card" method="post" name="form2" id="form2">
<table class="tb">
	<input id="c_id" name="c_id" type="hidden" value="">
	<input id="flag" name="flag" type="hidden" value="">
	<tr id="trnum">
	<td width="30%">添加数量：</td>
	<td><input id="num" name="num" size=20 value="">个
	</td>
	</tr>
	<tr>
	<td>充值卡面值：</td>
	<td><input id="c_money" name="c_money" size=20 value="">(元)
	</td>
	</tr>
	<tr>
	<td>充值卡点数：</td>
	<td><input id="c_point" name="c_point" size=20 value="">(点)
	</td>
	</tr>
    <tr align="center">
      <td colspan="2"><input class="input" type="submit" value="保存" id="btnSave"> <input class="input" type="button" value="返回" id="btnCancel"> </td>
    </tr>
</table>
</form>
</div>

</body>
</html>
<%
objdb.C(rs)
end sub
%>