/**
 * 部门管理
 */
$(function(){

    AppDept = {
        Events : {'click .btn': function (e, value, row, index) {
			var event = $(e.target).data('event');
			if(event == 'view'){
                AppDept.view(value);
			}else if(event == 'edit'){
                AppDept.edit(value);
			}
		}},
		add : function(parentId){
            MsgBox.window({
                title	: '部门管理',
                url		: Config.ROOT+'/sys/dept/edit?parentId=' + (parentId || ''),
                callback: function(){
                    window.location.reload();
                }
            });
		},
		edit: function(id){
            MsgBox.window({
                title	: '部门管理',
                url		: Config.ROOT+'/sys/dept/edit?id=' + id,
                callback: function(){
                    window.location.reload();
                }
            });
		},
        del: function(id){
            App.MsgBox.confirmDelete(function(){
                App.Ajax.request({
                    url		: Config.ROOT+'/sys/dept/batchDelete',
                    params	: {
                        'oids': id
                    },
                    success: function(resp){
                        window.location.reload();
                    }
                });
            });
        },
        view: function(id){
            MsgBox.window({
                title	: '部门管理',
                url		: Config.ROOT+'/sys/dept/edit?editType=view&id=' + id
            });
        }
	};
	
	
	//初始化表格
    var $table = new App.Table({
        url: Config.ROOT + '/sys/dept/list',
        search: true,
        searchParamName: 'name',
        searchPlaceholder: '名称',
        columns	:[
            {checkbox: true},
            {field:'name', title:'组织机构名称'},
            {field:'state', title:'状态', tpl: 'tpl_state'},
            {field:'contactName', title:'联系人'},
            {field:'contactMobile', title:'联系人电话'},
            {field:'id', title:'操作', width: 150, toolbar: 'tableRowToolbar', events: AppDept.Events}
        ]
    });

});