{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-6">
					<form class="form-inline" role="form" action="" method="get">
	                    <div class="form-group">
							<select name="cate_id" class="form-control">
								<option value="" {if $Think.get.cate_id==''}selected{/if}>全部分类</option>
								{foreach $categorys as $v}
								<option value="{$v.id}" {if $Think.get.cate_id==$v.id}selected{/if}>{$v.name}</option>
								{/foreach}
							</select>
	                    </div>
	                    <div class="form-group">
							<select name="goods_id" class="form-control">
								<option value="" {if $Think.get.goods_id==''}selected{/if}>全部商品</option>
								{foreach $goodsList as $v}
								<option value="{$v.id}" {if $Think.get.goods_id==$v.id}selected{/if}>{$v.name}</option>
								{/foreach}
							</select>
	                    </div>
	                    <!-- <div class="form-group">
							<select name="status" class="form-control">
								<option value="" {if $Think.get.status==''}selected{/if}>全部状态</option>
								<option value="1" {if $Think.get.status=='1'}selected{/if}>未售出</option>
								<option value="2" {if $Think.get.status=='2'}selected{/if}>已售出</option>
							</select>
	                    </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-6">
					<a class="pull-right btn btn-primary waves-effect waves-light" href="javascript:void(0);" style="margin-right: 10px;" onclick="batch_restore()">批量恢复</a>
					<a class="pull-right btn btn-warning waves-effect waves-light" href="javascript:void(0);" style="margin-right: 10px;" onclick="batch_del()">批量删除</a>
					<a class="pull-right btn btn-danger waves-effect waves-light" href="javascript:void(0);" style="margin-right: 10px;" onclick="ashbin_clear(this)">清空回收站</a>
				</div>
			</div>
			<!-- end row -->
			<div class="row">
				<table class="table table-striped m-0">
					<thead>
						<tr>
							<th><input type="checkbox" id="select_all"></th>
							<th>商品分类</th>
							<th>商品名称</th>
							<th>商品价格</th>
							<th>卡号</th>
							<th>卡密</th>
							<th>删除时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						{foreach $cards as $v}
						<tr>
							<td><input type="checkbox" name="card_id" value="{$v.id}"></td>
							<td>{$v.goods.category.name}</td>
							<td>{$v.goods.name}</td>
							<td>{$v.goods.price}</td>
							<td>{$v.number}</td>
							<td>{$v.secret}</td>
							<td>{$v.delete_at|date="Y-m-d H:i:s",###}</td>
							<td>
								<a href="javascript:void(0);" onclick="del(this,{$v.id})">删除</a>
								<span> | </span>
								<a href="javascript:void(0);" onclick="restore(this,{$v.id})">恢复</a>
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
			</div>
			<!-- end row -->
		</div>
		{$page}
	</div>
</div>
{/block}

{block name="appendJS"}

<script>
	function del(obj,id)
	{
		swal({
			title: "确定删除吗？",
			text: "你无法恢复该操作",
			type: "warning",
			showCancelButton: true,
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确定删除！",
			closeOnConfirm: false
		},
		function(){
			$.post('/merchant/goods_card/ashbin_delete',{
				id:id
			},function(res){
				if(res.code!=0){
					swal('删除失败', res.msg, "error");
				}else{
					swal('删除成功', '', "success");
					setTimeout(function(){
						location.reload();
					},200);
				}
			});
		});
	}

    function batch_del()
	{
        swal({
                title: "确定删除吗？",
                text: "你无法恢复该操作",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定删除！",
                closeOnConfirm: false
            },
            function(){
                var ids = new Array();

                $('tbody').find('input[name="card_id"]').each(function(){
                    if($(this).is(':checked')){
                        ids.push($(this).val());
                    }
                })

                if(ids.length == 0){
                    swal('选择要删除的数据', '', "error");
                    return false;
                }
                $.post('/merchant/goods_card/ashbin_batch_del',{
                    ids:ids
                },function(res){
                    if(res.code!=0){
                        swal('删除失败', res.msg, "error");
                    }else{
                        swal('删除成功', '', "success");
                        setTimeout(function(){
                            location.reload();
                        },200);
                    }
                });
                console.log(ids);
            });
    }

	function restore(obj,id)
	{
		swal({
			title: "确定恢复吗？",
			text: "",
			type: "warning",
			showCancelButton: true,
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确定恢复！",
			closeOnConfirm: false
		},
		function(){
			$.post('/merchant/goods_card/ashbin_restore',{
				id:id
			},function(res){
				if(res.code!=0){
					swal('恢复失败', res.msg, "error");
				}else{
					swal('恢复成功', '', "success");
					setTimeout(function(){
						location.reload();
					},200);
				}
			});
		});
	}

    function batch_restore()
    {
        var ids = new Array();
        $('tbody').find('input[name="card_id"]').each(function(){
            if($(this).is(':checked')){
                ids.push($(this).val());
            }
        })
        if(ids.length == 0){
            swal('选择要恢复的数据', '', "error");
            return false;
        }
        $.post('/merchant/goods_card/ashbin_batch_restore',{
            ids:ids
        },function(res){
            if(res.code!=0){
                swal('恢复失败', res.msg, "error");
            }else{
                swal('恢复成功', '', "success");
                setTimeout(function(){
                    location.reload();
                },200);
            }
        });
        console.log(ids);
    }

	function ashbin_clear(obj)
	{
		swal({
			title: "确定清空回收站吗？",
			text: "你无法恢复该操作",
			type: "warning",
			showCancelButton: true,
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确定清空！",
			closeOnConfirm: false
		},
		function(){
			$.post('/merchant/goods_card/ashbin_clear',{
			},function(res){
				if(res.code!=0){
					swal('清空失败', res.msg, "error");
				}else{
					swal('清空成功', '', "success");
					setTimeout(function(){
						location.reload();
					},200);
				}
			});
		});
	}

	$(function(){
        $('#select_all').click(function(){
            if($(this).is(':checked')){
                $('tbody').find('input[type="checkbox"]').each(function(){
                    $(this).prop("checked", true)
                })
            }else{
                $('tbody').find('input[type="checkbox"]').each(function(){
                    $(this).prop("checked", false)
                })
            }
        })
	})
</script>

{/block}
