<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-card{box-shadow: none;}
    </style>
</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_YGSZ_T" html='<a href="${ctx}/siteEmployee/siteEmployeeList"><li class="layui-this">基本信息</li></a>'/>
               <%-- <sfTags:pagePermission authFlag="SIT_XTSZ_YGSZ_QXSZ_T" html='<a href="${ctx}/siteEmployee/siteLimites"><li>权限设置</li></a>'/>--%>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">工程师姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" id="form-name" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">手机号：</label>
                    <div class="layui-input-block">
                        <input type="text" id="form-mobile" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class='layui-card'>
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test-table-reload" lay-filter="table-toolbar"></table>
            <%--<script type="text/html" id="toolbarDemo">
                <sfTags:pagePermission authFlag="SIT_XTSZ_YGSZ_TJYG_B" html='<button class="layui-btn layui-btn-sm" id="addEmployeeBtn"><i class="layui-icon layui-icon-add-1"></i>添加员工</button>'/>
            </script>--%>
        </div>
    </div>
</div>
<div class="layui-form  layui-card hide" id="Reasons">
    <div class="layui-card ">
        <div class="layui-card-body">
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div id="qrcode" style="width:300px; height:320px; margin-top:15px; margin-left: 60px"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/ueditor/1.4.3/third-party/jquery-1.10.2.min.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/modules/qrcode.min.js"></script>
<script type="text/html" id="table-toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">查看详情</a>
    <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
</script>

<script type="text/javascript">
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer'], function(){
        var tableExt = layui.tableExt;
        var layer = layui.layer;
        var $ = layui.jquery;

        tableExt.render({
            elem: '#test-table-reload'
            ,toolbar : '#toolbarDemo'
            ,defaultToolbar : false
            ,url: '${ctx}/siteEmployee/getSiteEmployeeData'
            ,cols: [[
                {type: 'numbers',title:'序号'}
                ,{field :'user_id',hide:true }
                ,{field:'id', title: '操作',toolbar: '#table-toolbar',align: 'center'}
               /* ,{field:'status', title: '状态',
                    templet: function(d){
                        return d.status == '0' ? '正常' : '';
                    },
                    exportable:true,            //开启导出功能
                    expFormat: function(data){  //格式导出的化字段
                        console.log("expFormat:", data);
                        return d.status == '0' ? '正常' : '';
                    }
                }*/
                ,{field:'name', title: '服务工程师', exportable:true,align: 'center'}
                ,{field:'login_name', title: '登录帐号',align: 'center'}
                ,{field:'mobile', title: '手机号',align: 'center'}
                ,{field:'years', title: '工作年限',align: 'center'}
                ,{field:'qrCode', title: '诚信服务二维码',align: 'center',
                    templet: function (d) {
                        var add;
                        if (d.qrcode == "0") {
                            add = '<a class="layui-btn layui-btn-xs" lay-event="viewQrcode"><i class="layui-icon fs-16">&#xe642;</i>查看</a>';
                            return add;
                        } else {
                            return ""
                        }
                    },}
            ]]
            ,done: function(res, curr, count){
                console.log("customer done", res);
            },exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '员工列表',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '员工导出',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    var ret = {};
                    ret.name= $("#form-name").val();
                    return ret;
                }
            }
        });

        var table = tableExt.getLayTable();

        //监听行工具事件
        table.on('tool(table-toolbar)', function(obj){
            var data = obj.data;
            var employeeId = data.id;
            if(obj.event === 'edit'){
                var fitTag = '${fns:checkPagePermission(request, "SIT_XTSZ_YGSZ_XG_B")}';
                if(fitTag !='0'){
                    layer.msg("对不起，您现在没有查看详情权限！",{icon:2});
                    return;
                }
                goMemberform('查看员工信息', '${ctx}/siteEmployee/updateEmployee?id=' + employeeId);
            }else {

                var toAnUrl="${ctx}//main/redirect/employeCard?id="+data.user_id;
                $("#qrcode").empty().qrcode({width : 300, height : 300,text:toAnUrl});
                layer.open({
                    type: 1,
                    content:  $("#Reasons")  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                    ,title: "查看二维码"
                    ,area:["450px","450px"]
                })
            }
        });

        var active = {
            reload: function(){
                table.reload('test-table-reload', {
                    where: {
                        name: $('#form-name').val(),
                        mobile: $("#form-mobile").val()
                    }
                });
            }
        };

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

        $(".layui-table-tool").hide();
    });

    function goMemberform(title, url){
        layer.open({
            title:title,
            type: 2,
            area: ["750px", "520px"],
            fixed: false,
            content: url
            /*end:function(){
                location.reload();
            }*/
        })
    }

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