<div id="cv-category-table-header">
    <div class="panel-title">
        <a href="javascript:openDialog('添加栏目','<?= url('new'); ?>','520px','480px')" class="easyui-linkbutton">+ 添加栏目</a>
        <a href="javascript:openDialog('添加外部链接','<?= url('new',['is_link'=>true]); ?>','520px','480px')" class="easyui-linkbutton">+ 添加外部链接</a>
        <a href="javascript:saveCoverCategoryOrderForm();" class="easyui-linkbutton"><i class="sui-icon icon-tb-delete cv-f-14"></i> 排序</a>
    </div>
</div>
<form id="cv-category-order-form" method="post" style="width: 100%;height: 100%;">
    <table id="cv-category-table" style="height: 100%;"></table>
</form>
<script type="text/javascript">
    $(function () {
        var cvCategoryTable = $('#cv-category-table');
        cvCategoryTable.datagrid({
            url:'<?= url('index'); ?>',
            columns:[[
                {field:'ck',checkbox:true,width:10},
                {field:'id',title:'ID',width:5,align:'center'},
                {field:'order',title:'权重',width:10,align:'center'},
                {field:'title',title:'栏目名称',width:50,halign:'center'},
                {field:'c_type',title:'栏目类型',width:10,align:'center'},
                {field:'mark',title:'特殊标记',width:20,align:'center'},
                {field:'items',title:'内容数量',width:10,align:'center'},
                {field:'is_show',title:'是否显示',width:10,align:'center'},
                {field:'visit',title:'访问',width:10,align:'center'},
                {field:'actions',title:'可用操作',width:40,halign:'center'}
            ]],
            pagination: false,
            border:false,
            fitColumns: true,
            striped: true,
            header: '#cv-category-table-header'
        });
    });

    function saveCoverCategoryOrderForm(){
        $("#cv-category-order-form").form('submit',{
            url: '<?= url('order'); ?>',
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var response = JSON.parse(result);
                message(response.message);
                if (response.success){
                    reloadCategoryListData();
                }
            }
        });
    }

    function reloadCategoryListData() {
        $('#cv-category-table').datagrid('reload');
        updateArchiveTab();
    }

    function deleteCategoryData(url){
        var confirm = layer.confirm('确认删除吗？删除后将无法恢复', {
            btn: ['删除','取消'],
            btnAlign: 'c',
            anim:4
        }, function(){
            $.ajax({
                url: url,
                type:'POST',
                success: function (response) {
                    message(response.message);
                    if (response.success){
                        reloadCategoryListData();
                    }
                }
            });
            layer.close(confirm);
        }, function(){
            layer.close(confirm);
        });
    }
</script>
