{extend name="base"}

{block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="card-box">
			<div class="row">
				<div class="col-sm-12">
					<form class="form-inline" role="form" action="" method="get">
	                    <div class="form-group">
							<input name="code" type="text" class="form-control" placeholder="邀请码" value="{$Think.get.code|default=''}">
	                    </div>
						<div class="form-group">
							<select name="status" class="form-control">
								<option value="">全部</option>
								<option value="2" {if $Think.get.status === '2'}selected{/if}>已过期</option>
								<option value="1" {if $Think.get.status === '1'}selected{/if}>已使用</option>
								<option value="0" {if $Think.get.status === '0'}selected{/if}>未使用</option>
							</select>
						</div>
						<div class="form-group">
							添加时间：<input class="form-control input-daterange-datepicker"  style="width:200px;" type="text" name="create_at" value="{:urldecode($Think.get.create_at)}" placeholder="点击选择查询日期">
						</div>
						<div class="form-group">
							过期时间：<input class="form-control input-daterange-datepicker"  style="width:200px;" type="text" name="expire_at" value="{:urldecode($Think.get.expire_at)}" placeholder="点击选择查询日期">
						</div>
						<button type="submit" class="btn btn-purple waves-effect waves-light"><i class="fa fa-search"></i> 搜索</button>
	                </form>
				</div>
				<div class="col-sm-12">
					<a href="{:url('add')}" class="pull-right btn btn-purple waves-effect waves-light">生成要邀请码</a>
				</div>
			</div>
			<!-- end row -->
			<div class="row">
				<table class="table table-striped m-0">
					<thead>
						<tr>
							<th>邀请码</th>
							<th>状态</th>
							<th>邀请时间</th>
							<th>添加时间	</th>
							<th>有效期</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						{foreach $codes as $v}
						<tr>
							<td>{$v.code}</td>
							<td>
								{switch name="v.status"}
								{case value="0"}<font color="gray">未使用</font>{/case}
								{case value="1"}<font color="green">已使用</font>{/case}
								{case value="2"}<font color="red">已过期</font>{/case}
								{/switch}
							</td>
							<td>
								{if $v.status==1}
								{$v.invite_at|date="Y-m-d H:i:s",###}
								{else/}
								-
								{/if}
							</td>
							<td>
								{$v.create_at|date="Y-m-d H:i:s",###}
							</td>
							<td>
								{if $v.status==1}
								已使用
								{else/}
								{$v.expire_day}
								{if $v.expire_at!=0}
								{if $v.create_at>=$v.expire_at}
								[ 已过期 ]
								{else/}
								[ {$v.expire_days}天 ]
								{/if}
								{/if}
								{/if}
							</td>
							<td>
								{if $v.status!=1}
								<a href="javascript:void(0);" onclick="delCode({$v.user_id},{$v.id})">删除</a>
								{/if}
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
			</div>
			<!-- end row -->
		</div>
		{$page}
	</div>
</div>
{/block}

{block name="appendJS"}

<script>
    function delCode(user_id,id)
    {
        layer.confirm('确认删除该邀请码？', {icon: 3, title:'提示'}, function(index){
            $.get("{:url('del')}",{
                user_id:user_id,
                id:id
            },function(res){
                if(res.code==1){
                    window.location.reload();
                }else{
                    alert(res.msg);
                }
            },'json');
            layer.close(index);
        });
    }
</script>

{/block}
