<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>待收货项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="SIT_XTSZ_YGSZ_YGXX_T"
                                       html='<a href="${ctx}/partnerStaff/partnerEmployeeList"><li class="layui-this">账号信息</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset" onclick="reset()">
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit
                        lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-md4 layui-col-sm4">
                    <label class="layui-form-label">名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" id="name" >
                    </div>
                </div>
                <div class="layui-col-md4 layui-col-sm4">
                    <label class="layui-form-label">联系电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" class="layui-input" id="mobile" >
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" id="addBtn" lay-event="addEmploye"><i class="layui-icon layui-icon-add-1"></i>添加</button>
                </div>
            </script>
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        table = layui.table;
        tableExt.render({
            elem: '#test'
            , height: 'full-150'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/partnerStaff/getPartnerEmployeeData'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar:"#toolbarDemo"
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {type: 'numbers',title:'序号'}
                ,{field :'user_id',hide:true }
                , {field: 'moble', title: '操作', width: 250, align: 'center',
                    templet: function (d) {
                        var add='';

                        add += '<a class="layui-table-link" lay-event="edit">编辑</a>';
                        add += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="layui-table-link" lay-event="delete">删除</a>'

                        if(isBlank(add)){
                            add+='--';
                        }
                        return add;
                    },
                }
                ,{field:'name', title: '姓名',align: 'center'}
                ,{field:'login_name', title: '登录帐号',align: 'center'}
                ,{field:'mobile', title: '手机号',align: 'center'}
                ,{field:'job_number', title: '工号',align: 'center'}
                ,{field:'is_browse', title: '按钮权限',align: 'center', templet: function (d) {
                    if(d.is_browse =='2'){
                        return "浏览权限";
                    }else{
                        return "操作权限";
                    }

                    }}
                ,{field:'hiredate', title: '入职时间',align: 'center'}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '账号信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '账号信息',
                where: function (){
                    console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('toolbar(test)',function(obj) {
            if (obj.event === 'addEmploye') {
                layer.open({
                    type: 2,
                    title: '添加员工',
                    content: '${ctx}/partnerStaff/addEmployee',
                    area: ['770px', '420px']
                });
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {//编辑地址
                var id = data.id;
                layer.open({type: 2,
                    title: '编辑工程师信息',
                    content: '${ctx}/partnerStaff/addEmployee?id='+id,
                    area: ['700px', '480px']
                });
            }else if (obj.event === 'delete') {//删除工程师
                var id = data.id;
                var indexla = layer.confirm('您确定要删除工程师吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/partnerStaff/delEmployee",
                        data: {
                            id: id
                        },
                        success: function (result) {
                            if (result.code == '200') {
                                layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            } else if (result.code == '501') {
                                layer.msg('该工程师有未完成工单，无法删除！', {icon: 2});
                            } else {
                                layer.msg('删除失败！', {icon: 2});
                            }
                        },
                        error: {}
                    })
                }, function () {
                    layer.close(indexla);
                });
            }
        });


        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                reload();
            }
        };
    });

    function reload(){
        table.reload('test', {
            where: {
                name: $('#name').val().trim(),
                telephone:$("#mobile").val().trim()
            }
        });
    }


</script>
</body>
</html>
