<!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="" class="btn-a-back"><i class="iconfont">&#xe61f;</i></a>
        <h2>直销日报</h2>
    </div>
</header>
<div class="weui-cells__title">
    <!--<div class="weui-cell__hd">-->
    <h2 th:text="${startTime}" style="width:50%;float:left" >
        <h2 style="width:50%;float:left" >日报</h2>
        <!--<span th:text="日报"></span>-->
        <!--<label class="weui-label" th:text="${startTime}" style="width:5.75rem;float:left;">日报</label>-->
        <!--<label class="weui-label" >日报</label>-->
        <!--<input class="weui-input" id="startTime" th:text="${startTime}"/>日报-->
    </h2>


        <!--<input class="weui-input" id="startTime" th:text="${startTime}"/>日报-->
    <!--</div>-->
</div>
<div class="weui-cells__title">基本情况</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">电话接触量</label></div>
        <div class="weui-cell__bd">
            <input id="callCount" class="weui-input" type="number" placeholder="请输入数字" th:value="${callCount}" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">电话接通量</label></div>
        <div class="weui-cell__bd">
            <input id="connectCount" class="weui-input" type="number" placeholder="请输入数字" th:value="${connectCount}" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">意向沉淀量</label></div>
        <div class="weui-cell__bd">
            <input id="intentBuyCount" class="weui-input" type="number" placeholder="请输入数字" th:value="${intentBuyCount}"  />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">到访量</label></div>
        <div class="weui-cell__bd">
            <input id="visitedCount" class="weui-input" type="number" placeholder="请输入数字" th:value="${visitedCount}" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">二访量</label></div>
        <div class="weui-cell__bd">
            <input id="twiceVisitedCount" class="weui-input" type="number" placeholder="请输入数字" th:value="${twiceVisitedCount}" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">认筹量</label></div>
        <div class="weui-cell__bd">
            <input id="identificationChipsCount" class="weui-input" type="number" placeholder="请输入数字" th:value="${identificationChipsCount}" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">认购量</label></div>
        <div class="weui-cell__bd">
            <input id="subscriptionCount" class="weui-input" type="number" placeholder="请输入数字" th:value="${subscriptionCount}" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">业绩</label></div>
        <div class="weui-cell__bd">
            <input id="source" class="weui-input" type="number" placeholder="请输入数字"  th:value="${source}" />
        </div>
    </div>
</div>
<div class="weui-cells__title">到访项目</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea id="visitedProject" class="weui-textarea" placeholder="请输入项目名称" th:text="${visitedProject}" rows="3"></textarea>
            <div class="weui-textarea-counter"><span id="visitedProjectText">0</span>/100</div>
        </div>
    </div>
</div>
<div class="weui-cells__title">二访项目</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea id="twiceVisitedProject" class="weui-textarea" placeholder="请输入项目名称" th:text="${twiceVisitedProject}" rows="3"></textarea>
            <div class="weui-textarea-counter"><span id="twiceVisitedProjectText">0</span>/100</div>
        </div>
    </div>
</div>
<div class="weui-cells__title">认筹项目</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea id="identificationChipsProject" class="weui-textarea" placeholder="请输入项目名称" th:text="${identificationChipsProject}" rows="3"></textarea>
            <div class="weui-textarea-counter"><span id="identificationChipsProjectText">0</span>/100</div>
        </div>
    </div>
</div>
<div class="weui-cells__title">认购项目</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea id="subscriptionProject" class="weui-textarea" placeholder="请输入项目名称" th:text="${subscriptionProject}" rows="3"></textarea>
            <div class="weui-textarea-counter"><span id="subscriptionProjectText">0</span>/100</div>
        </div>
    </div>
</div>
<div class="p40">
    <a class="weui-btn weui-btn_blue" href="javascript:;" id="showToast">保存</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>
<script type="text/javascript" src="/static/js/wechat/zepto.min.js"></script>
<!--<script type="text/javascript" src="/static/js/jquery.min.js"></script>-->
<!--<script type="text/javascript" src="/static/js/statistics.js"></script>-->
<script type="text/javascript">

    $(function () {

        $('#showToast').on('click', function () {
            saveSalesReport();
        });
        var subscriptionProject = $("#subscriptionProject").val();
        if(subscriptionProject !='' && subscriptionProject !='undefined'){
            $("#subscriptionProjectText").html(subscriptionProject.length)
        }
        var identificationChipsProject = $("#identificationChipsProject").val();
        if(identificationChipsProject !='' && identificationChipsProject !='undefined'){
            $("#identificationChipsProjectText").html(identificationChipsProject.length)
        }

        var twiceVisitedProject = $("#twiceVisitedProject").val();
        if(twiceVisitedProject !='' && twiceVisitedProject !='undefined'){
            $("#twiceVisitedProjectText").html(twiceVisitedProject.length)
        }
        var visitedProject = $("#visitedProject").val();
        if(visitedProject !='' && visitedProject !='undefined'){
            $("#visitedProjectText").html(visitedProject.length)
        }


    })

    function isPositiveInteger(s){//是否为正整数
        var re = /^[0-9]+$/ ;
        return re.test(s)
    }

    function saveSalesReport() {
        var callCount = $("#callCount").val();
        var connectCount = $("#connectCount").val();
        var intentBuyCount = $("#intentBuyCount").val();
        var source = $("#source").val();
        var visitedCount = $("#visitedCount").val();
        var visitedProject = $("#visitedProject").val();
        var twiceVisitedCount = $("#twiceVisitedCount").val();
        var identificationChipsCount = $("#identificationChipsCount").val();
        var subscriptionCount = $("#subscriptionCount").val();
        var subscriptionProject = $("#subscriptionProject").val();
        var identificationChipsProject = $("#identificationChipsProject").val();
        var twiceVisitedProject = $("#twiceVisitedProject").val();

        if (callCount == "" || callCount == undefined || connectCount == "" || connectCount == undefined || intentBuyCount == "" || intentBuyCount == undefined ||
            source == "" || source == undefined || visitedCount == "" || visitedCount == undefined || visitedProject == "" || visitedProject == undefined ||
            twiceVisitedCount == "" || twiceVisitedCount == undefined || identificationChipsCount == "" || identificationChipsCount == undefined || subscriptionCount == "" || subscriptionCount == undefined ||
            subscriptionProject == "" || subscriptionProject == undefined || identificationChipsProject == "" || identificationChipsProject == undefined || twiceVisitedProject == "" || twiceVisitedProject == undefined ||
            visitedProject == "" || visitedProject == undefined) {
            alert("有信息格式不正确或未填写");
            return false;
        }

        if(!isPositiveInteger(callCount) || !isPositiveInteger(connectCount) || !isPositiveInteger(intentBuyCount) || !isPositiveInteger(source) || !isPositiveInteger(visitedCount) || !isPositiveInteger(twiceVisitedCount)
            || !isPositiveInteger(identificationChipsCount) || !isPositiveInteger(subscriptionCount)){
            alert("请填写非负整数");
            return false;
        }
        if(callCount.length>9 || connectCount.length>9 ||intentBuyCount.length>9 ||visitedCount.length>9 ||twiceVisitedCount.length>9 ||identificationChipsCount.length>9 ||subscriptionCount.length>9){
            alert("数字长度不能超过9位");
            return false;
        }
        if(twiceVisitedProject.length>140 || identificationChipsProject.length>140 ||subscriptionProject.length>140 ||visitedProject.length>140){
            alert("项目长度不能超过140");
            return false;
        }
        $.ajax({
            url: "/customer/addSalesReport",
            data: {
                callCount: callCount,
                connectCount: connectCount,
                intentBuyCount: intentBuyCount,
                source: source,
                visitedCount: visitedCount,
                visitedProject: visitedProject,
                twiceVisitedCount: twiceVisitedCount,
                identificationChipsCount: identificationChipsCount,
                subscriptionCount: subscriptionCount,
                subscriptionProject: subscriptionProject,
                identificationChipsProject: identificationChipsProject,
                twiceVisitedProject: twiceVisitedProject
            },
            type: "post",
            success: function (data) {
                if (data.result == "1") {
                    showMessage("success", "保存成功", 2000, "/customer/addSalesReport");
                } else {
                    showMessage("error", data.msg, 1000);
                }
            }
        });

    }
    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 + "?time=" + Math.random();
            }
        }, timeout);
    }

    //监听文字个数的事件
    $("#visitedProject").bind('input propertychange', function() {
        var limitSub = $(this).val().substr(0, 100);
        $(this).val(limitSub); //截取字符长度
        if(limitSub.length >100){
            return false;
        }
        $("#visitedProjectText").html(limitSub.length);
    });
    $("#twiceVisitedProject").bind('input propertychange', function() {
        var limitSub = $(this).val().substr(0, 100);
        $(this).val(limitSub); //截取字符长度
        $("#twiceVisitedProjectText").html(limitSub.length);
    });
    $("#identificationChipsProject").bind('input propertychange', function() {
        var limitSub = $(this).val().substr(0, 100);
        $(this).val(limitSub); //截取字符长度
        $("#identificationChipsProjectText").html(limitSub.length);
    });
    $("#subscriptionProject").bind('input propertychange', function() {
        var limitSub = $(this).val().substr(0, 100);
        $(this).val(limitSub); //截取字符长度
        $("#subscriptionProjectText").html(limitSub.length);
    });

</script>
</body>

</html>
