<!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=report_check-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <style type="text/css">
        .seach_items {
            float: right;
            margin-left: 10px;
        }
    </style>
    <style type="text/css">
        .LAY-btns .layui-nav {
            padding-left: 0;
            padding-right: 10px;
            top: -4px;
            margin: 0 10px;
            border: 0;
            background-color: #009688;
        }

        .LAY-btns .layui-nav .layui-nav-item {
            line-height: 40px;
        }

        .LAY-btns .layui-nav .layui-nav-child {
            top: 34px;
        }

        .LAY-btns .layui-nav .layui-nav-bar {
            display: none;
        }

        .LAY-btns .layui-nav .layui-nav-child dd.layui-this a {
            color: #333;
            background-color: #fff;
        }

        .LAY-btns .layui-nav .layui-nav-child dd.layui-this a:hover {
            background-color: #f2f2f2;
            color: #000;
        }
    </style>

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="LAY-btns" style="margin-bottom: 10px;">

                        <form class="layui-form" lay-filter="query-form-element1">
                            <div class="seach_items">
                                <button class="layui-btn" lay-submit lay-filter="query-form-element1"><i
                                        class="layui-icon layui-icon-search"></i>查询
                                </button>
                            </div>
                            <div class="seach_items">
                                <input type="text" name="tel" autocomplete="off" class="layui-input"
                                       placeholder="姓名"/>
                            </div>
                            <div class="seach_items">
                                <input type="text" name="name" autocomplete="off" class="layui-input"
                                       placeholder="电话"/>
                            </div>
                        </form>
                        <div style="clear: both;"></div>
                    </div>
                    <table class="layui-hide" id="report_check_datagrid" lay-filter="report_check-operate"></table>

                    <script type="text/html" id="report_check-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-default layui-btn-xs" lay-event="dispatch"
                            >分配</a>
                        </div>
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="sign_repeat"
                            >标记撞单</a>
                        </div>
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-default layui-btn-xs" lay-event="repeat_report"
                            >撞单跟踪记录</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form',], function () {
        var $ = layui.$;
        var table = layui.table
            , form = layui.form
            , admin = layui.admin;

        table.render({
            elem: '#report_check_datagrid'
            , url: '/customer/report_customer/?report_status=0'
            , cols: [[
                {field: 'name', title: '姓名', width: 120}
                , {field: 'gender_text', title: "性别", width: 70}
                , {field: 'tel', title: '电话', width: 120}
                , {field: 'project_text', title: '项目', width: 200}
                , {field: 'create_time', title: '报备时间', width: 150}
                , {field: 'create_user_text', title: '报备人', width: 100}
                , {field: 'hitBill_customer', title: '撞单客户', width: 100}
                , {field: 'hitBill_project_text', title: '撞单项目', width: 100}
                , {field: 'stalk_user', title: '撞单跟踪人', width: 100}
                , {field: 'stalk_process', title: '撞单进度', width: 100}
                , {field: 'last_stalk', title: '最后跟踪', width: 200}
                , {width: 240, align: 'center', fixed: 'right', toolbar: '#report_check-operate-bar'}
            ]]
            , page: true
            , height: 'full-108'
        });

        // admin.req({
        //     url: '/report_check/dict/',
        //     done: function (res) {
        //         var data = res.data.source;
        //         var source_node = $('#id_source');
        //         for (var i in data) {
        //             var pid = data[i].id;
        //             var name = data[i].name;
        //             source_node.append("<option value='" + pid + "'>" + name + "</option>");
        //         }
        //         form.render('select');
        //     }
        // });

        //监听工具条
        table.on('tool(report_check-operate)', function (obj) {
            var data = obj.data;
            //查看跟踪记录
            if (obj.event === 'dispatch') {
                layer.open({
                    type: 2,
                    title: '分配客户',
                    area: ['30%', '40%'],
                    btn: ['分配', '取消'],
                    yes: function (index, dom) {
                        layui.onSubmitChild = function (data) {
                            layer.close(index);
                            table.reload('report_check_datagrid', {});
                        };
                        layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'divide.html?id=' + data.id
                });
            }
            else if (obj.event === 'sign_repeat') {

            }
            else if (obj.event === 'repeat_report') {

            }
        });

        form.on('submit(query-form-element1)', function (data) {
            table.reload('report_check_datagrid', {
                where: data.field
                , page: {curr: 1}
            });
            layer.closeAll();
            return false
        });


        $('#report_check_divide').on('click', function () {
            var checkStatus = table.checkStatus('report_check_datagrid');
            if (checkStatus.data.length === 0) {
                layer.msg('请至少选择一条记录');
                return
            };
            let divide_id = checkStatus.data.map(item => {
                return item.id
            }).join(",");

            layer.open({
                type: 2,
                title: '分配客户',
                area: ['400px', '300px'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        let customer = '华北';
                        layer.close(index);
                        if (!data) {
                            layer.open({
                                type: 1,
                                title: '操作',
                                area: ['300px', '220px'],
                                btn: ['标记为撞单客户', '重新分配'],
                                yes: function (index, dom) {
                                    layui.onSubmitChild = function (data) {
                                        layer.close(index);
                                    };
                                },
                                btn2: function (index, layero) {
                                    layer.close(index);
                                },
                                content: '<p style="text-align: center; padding: 15px 0">和' + customer + '客户撞单，请选择后续操作。<p>'
                            });
                        }
                        table.reload('report_check_datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'divide.html?id=' + divide_id
            });
        });
    });

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