<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="FWSGL_FWSGL_FWSGL_T" html='<li class=""><a href="${ctx}/siteInformation/siteDataList">服务商管理</a></li>'/>
                <sfTags:pagePermission authFlag="FWSGL_FWSGL_GCSGL_T" html='<li class="layui-this"><a href="${ctx}/employeInformation/employeList">工程师管理</a></li>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn"  lay-submit data-type="reload" 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" >
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-col-md2 layui-col-sm3">
                        <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-md2 layui-col-sm3">
                        <label class="layui-form-label">手机号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile" class="layui-input" id="mobile" >
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">所属服务商：</label>
                        <div class="layui-input-block">
                            <select class="" id="site" name="siteId" lay-verify="site" lay-filter="site"  lay-search>
                                <option value="">请选择服务商</option>
                                <c:forEach items="${siteList}" var="site">
                                    <option value="${site.columns.id}" <c:if test="${site.columns.id eq siteId}">selected</c:if> >${site.columns.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>
    </div>

</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="FWSGL_FWSGL_GCSGL_ADD" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="addEmploye"><i class="layui-icon layui-icon-add-1"></i>添加 </button>'/>
    <sfTags:pagePermission authFlag="FWSGL_FWSGL_GCSGL_QR" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="addQrcode"><i class="layui-icon layui-icon-picture-fine"></i>生成二维码 </button>'/>
    <sfTags:pagePermission authFlag="FWSGL_FWSGL_GCSGL_DC_B" html='<button class="layui-btn layui-btn-sm" id="exportBtn" ><i class="layui-icon layui-icon-export"></i>导出 </button>'/>
</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/layui/data.js"></script>
<%--<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/qrcode.js"></script>--%>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/modules/qrcode.min.js"></script>
<script type="text/javascript">
    var siteId = "${siteId}";
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    var JQuery;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        table = layui.table;
        var excel = layui.excel;
        JQuery = layui.jquery;
        //服务商信息列表
        var updateFlag='${fns:checkPagePermission(request, "FWSGL_FWSGL_GCSGL_XG_B")}';
        var deleteFlag='${fns:checkPagePermission(request, "FWSGL_FWSGL_GCSGL_SC_B")}';
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/employeInformation/siteEmploye?site=' + siteId
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , method:"post"
            ,toolbar:"#toolbarDemo"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', width: 50, title: '序号', align: 'center', type: 'numbers',rowspan:'2', fixed: 'left'}
                ,{field : 'id', width : '4%',checkbox : true,align : 'center',rowspan:'2' , fixed: 'left'}
                ,{field : 'user_id',hide:true }
                , {field: 'moble', title: '操作', width: 250, align: 'center',rowspan:'2', fixed: 'left',
                    templet: function (d) {
                        var add='';
                        if(updateFlag=='0'){
                            add += '<a class="layui-table-opt-link" lay-event="edit"><i class="layui-icon fs-16">&#xe642;</i>编辑</a>';
                        }
                        if(deleteFlag=='0'){
                            add += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="layui-table-opt-link" lay-event="delete"><i class="layui-icon fs-16">&#xe640;</i>删除</a>'
                        }
                        if(isBlank(add)){
                         add+='--';
                        }
                        return add;
                    },
                }
                , {field: 'siteName', title: '所属服务商', width: 250, align: 'center',exportable:true ,rowspan:'2', fixed: 'left'}
                , {field: 'name', title: '服务工程师', width: 150, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'login_name', title: '登录账号', width: 250, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'mobile', width: 200, title: '手机号', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'years', width: 180, title: '工作年限', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'qrcode', width: 250, title: '诚信服务二维码', align: 'center',rowspan:'2',
                    templet: function (d) {
                        var add;
                        if (d.qrcode == "0") {
                            add = '<a class="layui-table-opt-link" lay-event="viewQrcode"><i class="layui-icon fs-16">&#xe642;</i>查看</a>';
                            return add;
                        } else {
                            return "———"
                        }
                    },
                }
            ],
            ]
            ,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}/employeInformation/addEmploye',
                    area: ['80%', '70%']
                });
            } else {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                if (data.length < 1) {
                    layer.msg("请先选择工程师!", {icon: 5, anim: 6});
                    return;
                }
                var ids = "";
                for (var i = 0; i < data.length; i++) {
                    ids+=data[i].id+",";
                }
                var indexla = layer.confirm('您确定要为该工程师生成二维码吗？', {
                    icon:3,
                    btn: ['确定','取消'] //按钮
                }, function(){
                    layer.close(indexla);
                    $.ajax({
                        type : 'post',
                        data : {ids:ids},
                        url : "${ctx}/employeInformation/saveQrcode",
                        success : function(data) {
                            console.log(data);
                            if (data === "200") {
                                layer.msg('保存成功！', {icon: 1, time: 1000}, function () {
                                    table.reload('test'); //数据刷新
                                });
                            }else if (data=="402") {
                                layer.msg("该工程师已生成过二维码，请不要重复生成！", {icon: 2});
                            } else {
                                layer.msg("保存失败！", {icon: 2});
                            }
                        }
                    });

                }, function(){
                    layer.close(indexla)
                });
            }

        });


        //监听事件
        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}/employeInformation/addEmploye?id=' + id,
                    area: ['80%', '70%']
                });
            } else if (obj.event === 'delete') {//删除工程师
                var id = data.id;
                var indexla = layer.confirm('您确定要删除工程师吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/employeInformation/deleteEmploye",
                        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);
                });
            } 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"]
                            })
            }

        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });

        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });


        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 () {
                table.reload('test', {
                    where: {
                        name: $('#name').val(),
                        mobile: $("#mobile").val(),
                        siteId: $("#site").val()
                    }
                });
            }
        };
    });


    function denglsj(id, userId) {
        console.log("siteInfo" + id +" userId : "+ userId)
        parent.denglusdj(id,userId);
    }


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