<%@ page contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp" />
    <style> .layui-form-label {
        width: 115px !important;
    }
    .layui-input-block {
        margin-left: 120px;
        min-height: 36px;
    }
    </style>
</head>
<body>
<form class="layui-form" id="form1" action="" style="margin-top: 30px;margin-left: 50px;">
    <div class="layui-inline">
        <label class="layui-form-label">用户ID</label>
        <div class="layui-input-block">
            <input type="text" name="userId" id="userId" placeholder="请输入用户ID" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">业务员名称</label>
        <div class="layui-input-block">
            <input type="text" name="userName"  id="userName" placeholder="请输入业务员名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">登录账号</label>
        <div class="layui-input-block">
            <input type="text" name="loginName"  id="loginName" placeholder="请输入登录账号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-block">
            <input type="text" name="phone"  id="phone" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">所属代理ID</label>
        <div class="layui-input-block">
            <input type="text" name="agentId"  id="agentId" placeholder="请输入所属代理ID" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">所属代理名称</label>
        <div class="layui-input-block">
            <input type="text" name="agentName"  id="agentName" placeholder="请输入所属代理名称" autocomplete="off" class="layui-input">
        </div>
    </div>
</form>
<table class="layui-hide" id="businessInfoTab" lay-filter="businessInfoTab"></table>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <%--<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>--%>
<%--         TODO 暂时不需要查询功能，屏蔽按钮 --%>
        <button class="layui-btn layui-btn-sm" lay-event="search">查询</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<%--    <a class="layui-btn layui-btn-xs" lay-event="part">详情</a>--%>
   <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
</script>

<script>
    layui.use(['table', 'layer'], function(){
        var table = layui.table;
        var layer = layui.layer;

        var tableIns = table.render({
            elem: '#businessInfoTab'
            ,url:'${ctx}/businessInfo/page'
            ,initSort: {
                field: 'createTime'
                ,type: 'desc'
            }
            ,response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                ,countName: 'count' //数据总数的字段名称，默认：count
                ,dataName: 'data' //默数据列表的字段名称，认：data
                ,statusCode : 200
            }
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '业务员数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left', hidden: true}
                ,{field:'numbers', title:'序号', fixed: 'left', width:100,type:'numbers'}
                ,{field:'userId', title:'用户ID', fixed: 'left', width:100, sort: true}
                ,{field:'userName', title:'业务员名称', sort: true}
                ,{field:'loginName', title:'登录账号'}
                ,{field:'phone', title:'联系电话'}
                ,{field:'agentId', title:'所属代理ID'}
                ,{field:'agentName', title:'所属代理名称'}
                ,{field:'status', title:'状态',templet: function (d) {
                    if(d.status == 1){
                        return "<div style='color: green'>正常</div>";
                    }else{
                        return "<div style='color: red'>禁用</div>";
                    }
                 }}
                ,{field: 'createTime', title: '创建日期',width:180,templet : "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
            ]]
            ,request: {
                pageName: 'current' //页码的参数名称，默认：page
                ,limitName: 'size' //每页数据量的参数名，默认：limit
            }
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(businessInfoTab)', function(obj){
            switch(obj.event){
                case 'add':
                    // 添加
                    toAdd();
                    break;
                case 'search':
                    // 查询
                    var params= serialize($('#form1'));
                    table.reload('businessInfoTab', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                    break;
            }
        });
        //监听行工具事件
        table.on('tool(businessInfoTab)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么?', function(index){
                    obj.del(data);
                    layer.close(index);
                    del(obj);
                });
            } else if(obj.event === 'edit'){
                toAdd(obj.data);
            }
        });

        function toAdd(obj) {
            var url = '${ctx}/businessInfo/detail/';
            if(obj != undefined){
                url = "${ctx}/businessInfo/detail/"+obj.userId
            }
            var index = layer.open({
                type: 2
                ,shade: 0.5
                ,maxmin: true
                , content: url
                , area: ['550px', '300px']
            });
        }
        /*function part(obj) {
            var url = "${ctx}/agentInfo/part/"+obj.userId;
            var index = layer.open({
                type: 2
                ,shade: 0.5
                ,maxmin: true
                , content: url
                , area: ['550px', '300px']
            });
            layer.full(index);
        }*/
        function del(obj) {
            $.ajax({
                url: '${ctx}/businessInfo/delete',
                method: 'post',
                data: JSON.stringify(obj.data),
                dataType: 'JSON',
                contentType:"application/json",
                success: function(res) {
                    if(res.code == 200) {
                        layer.msg(res.data, {
                            icon: 1
                        });
                    } else {
                        layer.msg(res.data, {
                            icon: 5
                        });
                    }
                }
            })
        }
    });
</script>
</body>
</html>