<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="format-detection" content="telephone=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">
</head>

<body ontouchstart>
<header>
    <div class="header">
        <a href="javascript:history.go(-1)" class="btn-a-back"><i class="iconfont">&#xe61f;</i></a>
        <h2>查询条件</h2>
    </div>
</header>
<div class="weui-cells weui-cells_form mt0">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="" class="weui-label">开始时间</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="startTime" type="date" th:value="${startTime}"/>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="" class="weui-label">结束时间</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="endTime" type="date" th:value="${endTime}"/>
        </div>
    </div>
    <div class="weui-cell weui-cell_select weui-cell_select-after">
        <div class="weui-cell__hd">
            <label for="" class="weui-label">置业顾问</label>
        </div>
        <div class="weui-cell__bd">
            <select class="weui-select" id="managerFilter">

                <option th:value="-1">全部用户</option>
                <!--<option th:value="0">当前用户</option>-->
                <option th:each="manager,index:${managers}" th:value="${manager.id}"
                        th:text="${manager.realName}"></option>
            </select>
        </div>
    </div>
    <div class="weui-cell weui-cell_select weui-cell_select-after">
        <div class="weui-cell__hd">
            <label for="" class="weui-label">客户状态</label>
        </div>
        <div class="weui-cell__bd">
            <select class="weui-select" id="customerStatus">
                <option value="">全部客户</option>
                <option value="98">未跟踪</option>
                <option value="0">已跟踪</option>
            </select>
        </div>
    </div>
</div>
<div class="btn-modify">
    <a class="weui-btn weui-btn_blue" href="javascript:search()">查询</a>
</div>
<!--提交成功提示-->
<div id="toast" style="display: none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-icon-success-no-circle weui-icon_toast"></i>
        <p class="weui-toast__content">提交成功</p>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/statistics.js"></script>
<script>
    function search() {
        var startDateStr = $("#startTime").val();
        if (startDateStr == "" || startDateStr == undefined) {
            showMessage("error", "请选择开始时间", 1000);
            return false;
        }
        var endDateStr = $("#endTime").val();
        if (endDateStr == "" || endDateStr == undefined) {
            showMessage("error", "请选择结束时间", 1000);
            return false;
        }

        if (startDateStr != '' && startDateStr != null && startDateStr != undefined) {
            if (endDateStr != '' && endDateStr != null && endDateStr != undefined) {
                var startDate = eval('new Date(' + startDateStr.replace(/\d+(?=-[^-]+$)/,
                        function (a) {
                            return parseInt(a, 10) - 1;
                        }).match(/\d+/g) + ')');
                var endDate = eval('new Date(' + endDateStr.replace(/\d+(?=-[^-]+$)/,
                        function (a) {
                            return parseInt(a, 10) - 1;
                        }).match(/\d+/g) + ')');

                if (startDate > endDate) {
                    showMessage("error", "结束时间不能早于开始时间", 1000);
                    return false;
                }

            }
        }


        window.location.href = "/customer/hotline?startTime=" + startDateStr + "&endTime=" + endDateStr
            + "&managerFilter=" + $("#managerFilter").val() + "&customerStatus=" + $("#customerStatus").val()
    }

    function showMessage(type, message, timeout, url) {
        var $toast = $('#toast');
        if (type == "error") {
            $toast.find("i").removeClass().addClass("weui-icon_toast")
        } else if (type == "success") {
            $toast.find("i").removeClass().addClass("weui-icon_toast").addClass("weui-icon-success-no-circle")
        }
        $toast.find("p").text(message);
        if ($toast.css('display') != 'none') return;

        $toast.fadeIn(100);
        setTimeout(function () {
            $toast.fadeOut(100);
            if (url != undefined) {
                window.location.href = url;
            }
        }, timeout);
    }
</script>
</html>
