<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title></title>

    <link rel="stylesheet" href="/static/css/wechat/weui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/static/css/wechat/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="/static/css/wechat/style.css">
    <link rel="stylesheet" href="/static/css/wechat/tag.css">
    <link rel="stylesheet" href="/static/report/css/public.css">
</head>
<body>
<header>
    <div class="header">
        <a class="btn-a-back" href=""><i class="iconfont"></i></a>
        <h2>客户报备</h2>
    </div>
</header>
<div id="app" class="w750" style="font-size: 0.7rem">
    <div class="r_title">
        报备信息
    </div>
    <div class="r_content">
        <div class="r_ipt">
            <span>*</span><span class="r_spm">姓名</span>
            <input class="name" id="name" type="text" placeholder="请输入姓名">
        </div>
        <div class="r_ipt">
            <span>*</span><span class="r_spm">手机号</span>
            <input class="phone" id="phone" type="text" placeholder="请输入手机号码">
        </div>
        <div class="r_ipt">
            <input class="phone" id="projectId" type="hidden">
            <span style="color: red">*</span><span class="r_spm">约看楼盘</span>
            <a href="javascript:;" onclick="projectShow()" id="projectName" class="weui-flex__item"
               style="color: black">
                请选择 </a>
            <!--<span>*</span><span class="r_spm">约看楼盘</span>-->
            <!--<input class="btn3" type="button" id="projectName" onclick="projectShow()">-->
            <!--<img src="/static/report/img/right.png" alt="">-->
        </div>
        <div class="r_ipt back">
            <span>*</span><span class="r_spm">回访记录</span>
            <div>
                <textarea placeholder="请输入回访信息" id="content" class="backView" style=""></textarea>
            </div>
        </div>
    </div>

    <div class="r_title">
        智能识别
    </div>
    <div class="r_content">
        <div class="tex_a">
            <textarea class="info" placeholder="请输入回访信息" style=""></textarea>
            <button class="distinguish">识别</button>
        </div>
    </div>
    <div class="r_bt">
        <button onclick="customerReport()">报备</button>
    </div>
    <div class="select_box select_box3"></div>
</div>


<div class="weui-mask" id="projectMask" style="display: none"></div>

<div class="weui-actionsheet" id="projectMasksheet2"
     style="height: 3.35rem;z-index: 10000;position: absolute;bottom: 23.4rem;display: none;font-size: 20px">
    <div class="weui-actionsheet__menu" id="projectSheet2">
        <div class="clearfix" style="padding: 0.9rem;position: relative;">

            <input id="project" type="search" class="inp-search fl" placeholder=""
                   style="width: 13.5rem;height: 1.55rem;"/>

            <div class="text-search" id="projectSearch" th:onclick="'projectNameShow()'"
                 style="width: 4.25rem;float:right;text-align: center;position: absolute;right: 0rem;height: 3.3rem;top: 0;line-height: 3.3rem;">
                搜索
            </div>
        </div>
    </div>

</div>
<div class="weui-actionsheet" id="projectMasksheet" style="padding-top:3.35rem">
    <div class="weui-actionsheet__menu" id="projectSheet">
        <div class="weui-actionsheet__cell" th:each="project : ${projectListData}"
             th:onclick="'bindProject('+${project.id}+')'" th:text="${project.projectName}"></div>
    </div>
</div>


<script src="/static/report/js/jquery-1.10.2.js"></script>

<!--<script type="text/javascript" src="/static/js/jquery.min.js"></script>-->
<script type="text/javascript" src="/static/js/wechat/zepto.min.js"></script>
<script type="text/javascript" src="/static/js/statistics.js"></script>
<script type="text/javascript" src="/static/js/history.js"></script>

<script>

    $('.distinguish').on('click', function () {
        var text = $(".info").val();
        var ss = text.split('\n');
        for (let i of ss) {
            var bigYh = i.indexOf("：");
            var item = "";
            if(bigYh != -1){
                item = i.split('：');
            }else{
                item = i.split(':');
            }
            if (item.length > 1) {
                // 前缀
                const prefix = item[0].trim();
                // 值
//                const value = item[1];
                const value = item[1].trim();
                console.info(value);
                switch (prefix) {
                    case '客户姓名':
                        $('#name').val(value);
                        break;
                    case '客户电话':
                        $('#phone').val(value);
                        break;
                    case '客户电话号码':
                        $('#phone').val(value);
                        break;
                    case '客户手机':
                        $('#phone').val(value);
                        break;
                    case '客户手机号码':
                        $('#phone').val(value);
                        break;
                    case '客户联系方式':
                        $('#phone').val(value);
                        break;
                    case '客户联系号码':
                        $('#phone').val(value);
                        break;
                    case '客户号码':
                        $('#phone').val(value);
                        break;
                    case '电话':
                        $('#phone').val(value);
                        break;
                    case '电话号码':
                        $('#phone').val(value);
                        break;
                    case '手机':
                        $('#phone').val(value);
                        break;
                    case '手机号码':
                        $('#phone').val(value);
                        break;
                    case '联系方式':
                        $('#phone').val(value);
                        break;
                    case '联系号码':
                        $('#phone').val(value);
                        break;
                    case '报备项目':
                        $('#projectName').text(value);
                        $("#content").val('约看' + value);
                        break;
                    default:
                        break;
                }
            }
        }
    });
    $(document).ready(function () {
        var u = navigator.userAgent;
        if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
            $("#project").focus(function () {
                var winHeight = $(window).height();  //获取当前页面高度
                $(window).resize(function () {
                    var thisHeight = $(this).height();
                    if (winHeight > thisHeight) {
                        //键盘弹出
                        var aaaa = $("#projectMasksheet").height() * 2 / 40;
                        //noProjectToast
                        $("#projectMasksheet2").css({'bottom': aaaa + 'rem'})
                    } else {
                        //键盘收起
                        //$('.footer').css({'position':'fixed','bottom':'0'});
                        var aaaa = $("#projectMasksheet").height() * 2 / 40;
                        //noProjectToast
                        $("#projectMasksheet2").css({'bottom': aaaa + 'rem'})
                    }
                })
            });
            $("#project").blur(function () {
                var winHeight = $(window).height();  //获取当前页面高度
                $(window).resize(function () {
                    var thisHeight = $(this).height();
                    if (winHeight > thisHeight) {
                        //键盘弹出
                        var aaaa = $("#projectMasksheet").height() * 2 / 40;
                        //noProjectToast
                        $("#projectMasksheet2").css({'bottom': aaaa + 'rem'})
                    } else {
                        //键盘收起
                        //$('.footer').css({'position':'fixed','bottom':'0'});
                        var aaaa = $("#projectMasksheet").height() * 2 / 40;
                        //noProjectToast
                        $("#projectMasksheet2").css({'bottom': aaaa + 'rem'})
                    }
                })
            });
        }

    });

    $(function () {
        var $projectMasksheet = $('#projectMasksheet');
        var $projectMasksheet2 = $('#projectMasksheet2');
        var $projectMask = $('#projectMask');

        function hideProjectSheet() {
            $projectMasksheet.removeClass('weui-actionsheet_toggle');
            $projectMasksheet2.removeClass('weui-actionsheet_toggle');
            //解除列表滚动

            $("#projectMasksheet2").css('display', 'none');
            $("html,body").css({overflow: "auto", height: "100%"});
            $projectMask.fadeOut(200);
//            $(document).on('scroll', onScroll);
        }

        $projectMask.on('click', hideProjectSheet);
    });

    function projectShow() {
        $("#projectSheet").text("");
        var projectName = $("#projectSearch").val();
        $.ajax({
            url: "/customer/getBindProject",
            type: "post",
            data: {'customerId': 0},
            success: function (data) {
                if (data && data.length > 0) {
                    $.each(data, function (index, info) {
//                        $("#projectSheet").append("<div class='weui-actionsheet__cell' onclick=\"bindProject('" + info.id + "')\">" + info.projectName + "</div>");
                        $("#projectSheet").append("<div class='weui-actionsheet__cell' onclick=\"bindProject('" + info.id + '\',\'' + info.projectName + "')\">" + info.projectName + "</div>");
                    });

                    $('#projectMasksheet').addClass('weui-actionsheet_toggle');
                    $('#projectMasksheet2').addClass('weui-actionsheet_toggle');
                    //禁止列表滚动
                    $("html,body").css({overflow: "hidden", height: '100%'});
                    $('#projectMask').fadeIn(100);
                    $(document).off();
                } else {
                    //noProjectToast
                    $('#noProjectToast').fadeIn(100);
                    setTimeout(function () {
                        $('#noProjectToast').fadeOut(100);
                    }, 2000);
                }
                setTimeout(function () {
                    var aaaa = $("#projectMasksheet").height() * 2 / 40;
                    //noProjectToast
                    $("#projectMasksheet2").css({'bottom': aaaa + 'rem', 'display': 'block'})
                }, 10);
            }
        });
    }

    function projectNameShow() {
        var projectName = $("#project").val();
        $("#projectSheet").text("");
        $.ajax({
            url: "/customer/getBindProject",
            type: "post",
            data: {'customerId': 0, projectName: projectName},
            success: function (data) {
                $("#project").val('');
                if (data && data.length > 0) {
                    $.each(data, function (index, info) {
//                        $("#projectSheet").append("<div class='weui-actionsheet__cell' onclick=\"bindProject('" + info.id + "')\">" + info.projectName + "</div>");
                        $("#projectSheet").append("<div class='weui-actionsheet__cell' onclick=\"bindProject('" + info.id + '\',\'' + info.projectName + "')\">" + info.projectName + "</div>");
//                        $("#projectSheet").append("<div class='weui-actionsheet__cell' onclick=\"bindProject('" + info.id + " + "," "+ info.projectName + "')\">" + info.projectName + "</div>");
                    });
                    $('#projectMasksheet').addClass('weui-actionsheet_toggle');

                    //禁止列表滚动
                    $("html,body").css({overflow: "hidden", height: '100%'});
                    $('#projectMask').fadeIn(100);
                    $(document).off();
                    var aaaa = $("#projectMasksheet").height() * 2 / 40;
                    //noProjectToast
                    $("#projectMasksheet2").css({'bottom': aaaa + 'rem', 'display': 'block'})
                } else {
                    $('#noProjectToast').fadeIn(100);
                    var aaaa = $("#projectMasksheet").height() * 2 / 40;
                    //noProjectToast
                    $("#projectMasksheet2").css({'bottom': aaaa + 'rem', 'display': 'block'})
                    setTimeout(function () {
                        $('#noProjectToast').fadeOut(100);
                    }, 2000);
                }
//                setTimeout(function () {
//                    var aaaa = $("#projectMasksheet").height() * 2 / 40;
//                    //noProjectToast
//                    $("#projectMasksheet2").css({'bottom': aaaa + 'rem', 'display': 'block'})
//                }, 10);
            }
        });
    }

    function bindProject(projectId, projectName) {
        debugger;
        $("#projectId").val(projectId);
        $("#projectName").text(projectName);
        $("#content").val('约看' + projectName);
        var $projectMask = $('#projectMask');
        $('#projectMasksheet').removeClass('weui-actionsheet_toggle');
        $('#projectMasksheet2').removeClass('weui-actionsheet_toggle');
        //解除列表滚动
        $("#projectMasksheet2").css('display', 'none');
        $("html,body").css({overflow: "auto", height: '100%'});
        $projectMask.fadeOut(200);
    }

    function customerReport() {
        var customerPhone = $("#phone").val();
        var projectId = $("#projectId").val();
        var projectName = $("#projectName").text();
        var name = $("#name").val();
        var content = $("#content").val();
        if (typeof(name) == "undefined" || name == '' || name == null) {
            alert("请填写客户姓名");
            return;
        }
        if (typeof(customerPhone) == "undefined" || customerPhone == '' || customerPhone == null) {
            alert("请填写客户电话");
            return;
        }
        if (typeof(projectName) == "undefined" || projectName == '' || projectName == null) {
            alert("请选择约看楼盘");
            return;
        }
        if (typeof(content) == "undefined" || content == '' || content == null) {
            alert("请填写回访内容");
            return;
        }
        if (typeof(projectId) == "undefined" || projectId == '' || projectId == null) {
            projectId = 0;
        }
        $.ajax({
            url: "/project/customerReport",
            type: "post",
            data: {
                'customerPhone': customerPhone,
                'projectId': projectId,
                'projectName': projectName,
                'name': name,
                'content': content
            },
            success: function (data) {
                console.log(data);
                if (data == 1) {
                    alert("报备成功！");
                    window.location.reload()
                } else if (data == 2) {
                    alert("该客户已约看到该项目，请核实！");
                } else if (data == 3) {
                    alert("项目不存在，请重新选择！");
                    $("#projectName").text("请选择");
                } else {
                    alert("报备失败！");
                }
            }
        });
    }

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