/**
 * 考核列表
 */
layui.use(['form', 'table', 'laydate'], function () {
    var form = layui.form;
    var table = layui.table;
    var laydate = layui.laydate;

    table.render({
        elem: '#halfList1'
        , url: '/jx/orgPersonList' //异步接口
        , even: true // 开启隔行背景
        , size: 'sm' // 小尺寸
        , cols: [[{type: 'numbers'},{type: 'checkbox', align: 'center'}
            , {field: 'pname', align: 'center', title: "员工"}
            , {field: 'org_name', align: 'center', title: "考核组织名称"}
            , {field: 'fdisplayname_l2', align: 'center', title: "组织长名称"}
            , {align: 'center', title: "操作",templet: function(d){
                return '<button class="layui-btn  layui-btn-xs" lay-event="delete">删除</button>';
			}} 
            ]
        ]
        , id: 'halfListTb1'
        , page: true
    });

    // 监听表格工具栏
    table.on('tool(halfListFilter1)', function (obj) {
        var data = obj.data //当前行数据
            , event = obj.event //事件
            ,orgpersonId =data.orgperson_id

        if (event == 'delete') {

            layer.confirm('确定要删除吗?', function(){
                AjaxTool.XPost("/jx/deleteOrgPerson",{orgPersonId:orgpersonId},function(data) {
                    if(data.code == '0'){
                        window.location.href  = "/jx/orgPersonSetting";
                    }else{
                        layer.alert("删除失败!"+(data.msg?data.msg:''),{icon:5})
                    }

                }, function(data) {
                    layer.alert("删除失败，您可能已掉线，请刷新页面或关闭后重试！!"+(data.msg?data.msg:''),{icon:5})
                });

            });
        }

    });

    var $ = layui.$, active = {
        reload: function () {
            var khOrg = $('#khOrg');
            var personName = $('#personName');
                //执行重载
                table.reload('halfListTb1', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , limit: 20
                    , where: {
                        khOrg: khOrg.val()
                        ,personName:personName.val()
                    }
                });
        },
        new: function () {
            window.location.href='/jx/toAddOrgPerson'
        },
        update: function () {
            window.location.href='/jx/toChangeOrgPerson'
        }
    };

    $('#searchForm .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
});
