<%@ 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" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css"/>
    <style>
        html {
            background-color: #fff;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-form" id="searchForm">
        <div class="layui-card">
            <div class="layui-card-body layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-col-sm10">
                        <%--                    <label class="layui-form-label">优惠券码：</label>--%>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" placeholder="请输入员工姓名进行搜索"
                                   name="name">
                        </div>
                    </div>
                    <button type="button" class="layui-btn f-r 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>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-body hasMsg">
                <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            </div>
        </div>
    </div>
</div>
<div class="operate-footer">
    <button class="layui-btn sureAdd">确认</button>
    <button class="layui-btn layui-btn-primary" onclick="cancel();">取消</button>
</div>
<script type="text/html" id="choose">
    <input type="checkbox" lay-skin="primary" name="choose" value="{{d.id}}" data-name="{{d.name}}"/>
</script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'form'], function () {
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        form = layui.form;
        table = tableExt.getLayTable();

        tableExt.render({
            elem: '#test'
            , height: 'full-160'
            , page : false //开启分页
            , url: '${ctx}/customerEntry/ajaxForDispatchEngineer'
            , cols: [[
                {title: '序号', type: 'numbers'}
                , {field: 'name', title: '员工姓名', align: 'center', minWidth: 120}
                , {field: 'role_name', title: '岗位', align: 'center', minWidth: 120}
                , {field: 'id', title: '选择', align: 'center', templet: '#choose', minWidth: 80, fixed: 'right'}
            ]],
            done: function(res){
            }
        });

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

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

        $('.sureAdd').click(function(){

            var $checked = $('input[name=choose]:checked');
            var ids = [];
            $checked.each(function () {

                ids.push($(this).val());
            });

            if(ids.length === 0){
                layer.msg('请选择工程师');
                return;
            }
            var data = {};
            data.entryIds = '${entryIds}';
            data.engineerIds = ids;
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/batchDispatch',
                contentType: 'application/json',
                data: JSON.stringify(data),
                success: function (result) {
                    if (result.code === '200') {
                        layer.msg('操作成功！', {icon: 1, time: 1000}, function () {
                            cancel();
                            parent.$('.layui-laypage-btn').click();
                        });
                    } else {
                        layer.msg('派工失败！' + result.errMsg);
                    }
                }
            })
        });

    });

    function cancel() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
    }

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