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


    table.render({
        elem: '#wxPersonList'
        , url: '/jx/getWxPersonList' //异步接口
        , even: true // 开启隔行背景
        , size: 'sm' // 小尺寸
        , cols: [[{type: 'numbers'},{type: 'checkbox', align: 'center'}
            , {field: 'wxperson_id', align: 'center', title: "微信ID(工号)"}
            , {field: 'wxperson_name', align: 'center', title: "微信员工"}
            , {field: 'wxperson_matchdata', align: 'center', title: "微信员工实际工号"}
            , {field: 'wxperson_pname', align: 'center', title: "绑定HR员工"}
            , {field: 'wxperson_createtime', align: 'center', title: "创建时间"}
            , {field: 'wxperson_updatetime', align: 'center', title: "更新时间"}
            , {align: 'center', title: "操作",templet: function(d) {
                    return '<button class="layui-btn  layui-btn-xs" lay-event="edit">编辑实际工号</button><button class="layui-btn  layui-btn-xs" lay-event="clear">取消绑定</button>';
                 }
               }
            ]
        ]
        ,limits:[100,500,1000]
        , id: 'wxPersonListTb'
        , page: true
    });

    table.on('tool(wxPersonListFilter)',function(obj){
        var layEvent = obj.event;
        var data = obj.data;
        type = data.syscode_isperson;
        object = obj;
        if(layEvent == 'edit'){
            $(obj.tr.children("td")[4]).attr("data-edit","text");
            //$($(obj.tr.children("td")[1]).children("div")[0]).dblclick();
            $(obj.tr.children("td")[4]).trigger("click");

        }else if(layEvent == 'clear'){
            var d ={};
            d.id = data.wxperson_id;
            AjaxTool.XPost("/jx/clearWxPerson",d,function(data){
                var name = $('#name');
                //执行重载
                table.reload('wxPersonListTb', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , limit: 100
                    , where: {
                        name: name.val()
                    }
                });
            },function(err){
                layer.msg("操作失败，您可能已掉线，请刷新页面或关闭后重试！"+(err.msg?err.msg:''),{icon:2});
            });
        }
    });

    table.on('edit(wxPersonListFilter)', function (obj) {
        // $(this.parentNode).addClass("dirtyData");
        var value = obj.value //得到修改后的值
            , data = obj.data //得到所在行所有键值
            , field = obj.field; //得到字段
        //更新数据
        var d ={};
        d.id = data.wxperson_id;
        d.value = data.wxperson_matchdata;
        //console.log(d);
        AjaxTool.XPost("/jx/upWxPerson",d,function(data){
            var name = $('#name');
            //执行重载
            table.reload('wxPersonListTb', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , limit: 100
                , where: {
                    name: name.val()
                }
            });
        },function(err){
            layer.msg("操作失败，您可能已掉线，请刷新页面或关闭后重试！"+(err.msg?err.msg:''),{icon:2});
        });
    });

    var $ = layui.$, active = {
        reload: function () {
            var name = $('#name');
            //执行重载
            table.reload('wxPersonListTb', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , limit: 100
                , where: {
                    name: name.val()
                }
            });



        }
    };

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


});





