{extend name="common/common2" /}
{block name="main"}

<div class="ibox">
    <div class="ibox-content">
        <div class="row">
            <div class="col-xs-3">
                <a href="{:url('add')}"  class="btn btn-sm btn-primary">盘点</a>
            </div>
            <div class="col-xs-9" style="text-align: right;">
                <form class="form-inline" id="form-search" action="{:url('index')}">

                    <div class="input-group">
                        <select name="status" class="form-control">
                            <option value="">选择状态</option>
                            <option value="0">盘库中</option>
                            <option value="1">完成</option>
                        </select>
                    </div>

                    <div class="input-group">
                        <span class="input-group-btn">
                            <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
                        </span>
                        <span class="input-group-btn">
                            <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
                        </span>
                    </div>
                </form>
            </div>

        </div>
    </div>
    <div class="ibox-content">
        <div class="jqGrid_wrapper">
            <table id="table" style="border-collapse: collapse"></table>
            <div id="pager"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    $(function () {

        $(window).bind("resize",function(){
            var width=$(".jqGrid_wrapper").width();
            $("#table").setGridWidth(width);
        });

        $.jgrid.defaults.styleUI="Bootstrap";
        $("#table").jqGrid({
            url:"{:url('index')}",
            datatype: "json",
            colModel:[
                {label:'盘点人',name:'user_name',index:'user_name', width:70,sortable: false},
                {label:'盘点说明',name:'remark',index:'remark', width:70,sortable: false},
                {label:'盘点开始时间',name:'create_time',index:'create_time', width:70,sortable: false},
                {label:'盘点结束时间',name:'finish_time',index:'finish_time', width:70,sortable: false},
                {label:'状态',name:'status',index:'status',width:40,editable: false,sortable: false,formatter:function (a,b,c){
                        if(a == 0){
                            return '<span >盘库中</span>';
                        } else if(a == 1){
                            return '<span >已完成</span>';
                        }
                    }},
                {label:'操作',width:60,sortable: false,formatter: function (a, b, c) {
                        var report_url = "{:url('report',[],'')}/id/"+c.id;
                        var detail_url = "{:url('detail',[],'')}/id/"+c.id;
                        var finish_url = "{:url('finish',[],'')}/id/"+c.id;
                        var del_url = "{:url('del',[],'')}/id/"+c.id;
                        var btn = '<a url="'+report_url+'" href="javascript:;" data-title="报表" onclick="layer_open(this,1)" data-width="800px"  ><span class="label label-primary" title="报表">报表</span></a>&nbsp;';
                         btn += '<a  href="'+detail_url+'" ><span class="label label-primary" title="明细">明细</span></a>&nbsp;';
                        if(c.status == 0){
                            btn += '<a href="'+finish_url+'" class="confirm ajax-get" data-confirm="确定要标记为完成状态吗?" data-table="1"><span class="label label-success" title="完成">完成</span></a>&nbsp;';
                        }
                        btn += '<a href="'+del_url+'" class="confirm ajax-get" data-confirm="确定要标记为删除吗?" data-table="1"><span class="label label-warning" title="删除">删除</span></a>';
                        return btn;
                    }},
            ],
            rowNum:10,
            rowList:[10,20,30,50,100],
            pager: '#pager',
            sortname: 'sort',
            viewrecords: true,
            autowidth:true,
            mtype: 'post',
            height: 'auto',
            emptyrecords: "暂无数据",
            sortorder: "asc",
            caption:"盘库列表",
            loadComplete: function (xhr) {
                if(xhr.code==0){
                    layer.msg(xhr.msg);
                    return false;
                }
            },
        });
    });

</script>
{/block}