<!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=customer-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;
        }

        .tableContent {
            width: 100%;
            display: flex;
            justify-content: space-between;
            flex-direction: row;
        }

        .demo-class .layui-layer-btn0 {
            background-color: #009688 !important;
            color: #fff;
        }

        .demo-class .layui-layer-btn1 {
            background-color: red;
            color: #fff;
        }
    </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;">
                        <div style="float: left">
                            <button class="layui-btn" id="customer_order"><i
                                    class="layui-icon layui-icon-add-circle"></i>预约量房
                            </button>
                            <button class="layui-btn" id="btn_list"><i
                                    class="layui-icon layui-icon-download-circle"></i>导出
                            </button>
                        </div>
                        <form class="layui-form" lay-filter="query-form-element">
                            <div class="seach_items">
                                <button class="layui-btn" lay-submit lay-filter="query-form-element"><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>

                    <div class="tableContent">
                        <div style="width: 375px">
                            <table class="layui-hide" id="customer_log" lay-filter="customer-operate-log"></table>
                        </div>
                        <div style="width: calc(100% - 390px)">
                            <table class="layui-hide" id="customer_datagrid" lay-filter="customer-operate"></table>
                        </div>
                    </div>

                    <script type="text/html" id="customer-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="customer_search"
                            >查看</a>
                            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="add_review"
                               data-permission="customer.view_new_customer"
                            >跟踪报告</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: '#customer_log'
            , url: '/customer/stage_count/'
            , cols: [[
                {field: 'stage', title: '阶段', width: 100}
                , {field: 'total_count', title: "总人数", width: 90, sort: true}
                , {field: 'today_count', title: '今日', width: 90, sort: true}
                , {field: 'overdue_count', title: '逾期', width: 90, sort: true}
            ]]
        });

        table.render({
            elem: '#customer_datagrid'
            , url: '/customer/new_customer/'
            , title: '潜客跟踪'
            , cols: [[
                {field: 'name', title: '姓名', width: 110}
                , {field: 'gender_text', title: "性别", width: 70}
                , {field: 'tel', title: '电话', width: 130}
                , {field: 'village', title: '小区', width: 150}
                , {field: 'address', title: '地址', width: 200}
                , {field: 'source_text', title: '来源', width: 100}
                , {field: 'project_text', title: '项目', width: 100}
                , {field: 'stage_progress_text', title: '阶段进度', width: 100}
                , {field: 'potential_level_text', title: '客户级别', width: 100}
                , {field: 'notes', title: '备注', width: 200}
                , {field: 'status_text', title: '状态', width: 80}
                , {field: 'track_user_text', title: '跟踪人', width: 100}
                , {field: 'end_time_f', title: '最后跟踪时间', width: 120}
                , {field: 'last_review', title: '最后跟踪情况', width: 200}
                , {field: 'next_time_f', title: '下次跟踪时间', width: 120}
                , {field: 'follow_count', title: '跟踪次数', width: 100}
                , {field: 'enter_count', title: '进店次数', width: 100}
                , {field: 'last_enter_time', title: '最后进店时间', width: 150}
                , {field: 'create_time_f', title: '建档时间', width: 150}
                , {field: 'create_user_text', title: '建档人', width: 100}
                , {width: 130, align: 'center', fixed: 'right', toolbar: '#customer-operate-bar'}
            ]]
            , page: true
            , height: 'full-108'
        });

        function createFollowReport(customer_id, stage_progress_sort) {
            layer.open({
                type: 2,
                title: '添加跟踪报告',
                area: ['45%', '70%'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (res) {
                        if (res.code === 0) {
                            layer.msg('添加成功！', {icon: 1})
                        }
                        layer.close(index);
                        table.reload('customer_datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'add_report.html?customer_id=' + customer_id + '&stage_progress_sort=' + stage_progress_sort
            });
        };
        //监听工具条
        table.on('tool(customer-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'customer_search') {
                table.editdata = data;
                layer.open({
                    skin: 'demo-class',
                    type: 2,
                    title: '查看客户详情',
                    area: ['45%', '90%'],
                    btn: ['跟踪报告', '更新进度', '取消'],
                    yes: function (index, dom) {
                        //添加跟踪报告
                        createFollowReport(data.id, data.stage_progress_sort)
                    },
                    btn2: function (index, layero) {
                        //更新进度
                        layer.close(index);//关闭当前按钮
                    },
                    btn3: function (index, layero) {
                        //取消
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'detail.html'
                });
            } else if (obj.event === 'add_review') {
                //添加跟踪报告
                createFollowReport(data.id, data.stage_progress_sort)
            }
        });

        table.on('row(customer-operate-log)', function (obj) {
            var data = obj.data;
            table.reload('customer_datagrid', {
                where: {stage_progress: data.stage_id}
                , page: {curr: 1}
            });

            //标注选中样式
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        });

        var _params = {};
        form.on('submit(query-form-element)', function (data) {
            _params = data.field;
            table.reload('customer_datagrid', {
                where: data.field
                , page: {curr: 1}
            });
            layer.closeAll();
            return false
        });
        //导出列表
        $('#btn_list').on('click', function () {
            $.get({
                url: '/customer/new_customer/?export=true',
                dataType: 'json',
                data: _params,
                success: function (res) {
                    if (res.code === 1) {
                        layer.msg(res.msg);
                        return;
                    }
                    table.exportFile('customer_datagrid', res,)
                }
            })
        });

        $('#customer_order').on('click', function () {
            layer.open({
                type: 2,
                title: '预约量房',
                area: ['45%', '65%'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (res) {
                        if (res.code === 0) {
                            layer.msg('添加成功！', {icon: 1})
                        }
                        layer.close(index);
                        table.reload('customer_datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'order.html'
            });
        });
    });

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