<!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,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/newstyle.css">
</head>
<style>
    .num3 {
        background: green;
        color: #fff;
        padding: 1px 6px;
        border-radius: 10px;
    }
</style>

<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__title">基本信息</div>
<input type="hidden" id="customerId" th:value="${customerId}"/>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label" style="display: inline">姓名:</label>
            <span th:text=${customerName}></span>
        </div>
        <div class="weui-cell__bd tx-r">
            <span th:if="${isPrivate} eq '1'" class="num3">私</span>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label" style="display: inline">手机号:</label>
            <span>
                <a th:href="|tel:${customerPhone}|" class="my-client__tel" th:text="${customerPhone}"></a>
            </span>
        </div>
        <div class="weui-cell__bd tx-r">
            <span id="crmView" style="color: #D9463F;">CRM会员视图</span>
        </div>
    </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">
            <p th:text=${managerName}></p>
            <!--<input class="weui-input" type="text" th:value=${managerName} readonly="readonly" unselectable>-->
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">报名来源</label></div>
        <div class="weui-cell__bd">
            <p th:text=${latestSource}></p>
            <!--<input class="weui-input" type="text" th:value=${latestSource} readonly="readonly" unselectable>-->
        </div>
    </div>
    <div class="weui-cell a-i-t">
        <div class="weui-cell__hd"><label class="weui-label">活动名称</label></div>
        <div class="weui-cell__bd">
            <p th:text=${actSource}></p>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">报名时间</label></div>
        <div class="weui-cell__bd">
            <p th:text=${singupTime}></p>
            <!--<input class="weui-input" type="text" th:value=${singupTime} readonly="readonly" unselectable>-->
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">派工时间</label></div>
        <div class="weui-cell__bd">
            <p th:text=${bindTime}></p>
            <!--<input class="weui-input" type="text" th:value=${bindTime} readonly="readonly"  unselectable>-->
        </div>
    </div>
</div>
<div class="p40">
    <!--<a class="weui-btn weui-btn_blue" href="javascript:;" id="showToast">加入私客</a>-->
    <a class="weui-btn weui-btn_blue" th:if="${isPrivate} eq '1'"
         th:onclick="'goToUrl(\'' + @{/customer/customerdetail(customerId=${privateId})} + '\')'">私客详情</a>
    <a th:href="'javascript:goToUrl(\'' + @{/project/waitaddvisit(customerId=${customerId},buyIntention=${buyIntention})} + '\')'"
       class="weui-btn weui-btn_blue">加入私客</a>
    <a href="javascript:;" class="weui-btn weui-btn_default xcancel">放弃</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>

<div class="js_dialog" id="iosDialog1" style="visibility: hidden;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd">确定放弃吗？</div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default xhidedialog">取消</a>
            <a href="javascript:;" th:onclick="'javascript:abandonCustomer(\'' +${customerId}+ '\');'"
               class="weui-dialog__btn weui-dialog__btn_primary">确定</a>
        </div>
    </div>
</div>


<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 type="text/javascript">
    $(function () {
//        // 提交成功提示
//        var $toast = $('#toast');
//        $('#showToast').on('click', function(){
//            if ($toast.css('display') != 'none') return;
//
//            $toast.fadeIn(100);
//            setTimeout(function () {
//                $toast.fadeOut(100);
//            }, 2000);
//        });
        $('.xcancel').on('click', function () {
            $("#iosDialog1").css("visibility", "visible");
        });
        $('.xhidedialog').on('click', function () {
            $("#iosDialog1").css("visibility", "hidden");
        });
    });

    function abandonCustomer(customerId) {
//    House365Util.createModal("放弃客户", "警告，您正在放弃跟踪此客户，是否继续？", function () {
        $.ajax({
            url: '/customer/abandonCustomer',
            data: {"customerId": customerId},
            type: "GET",
            success: function (data) {
                if (data == 'success') {
//                    window.location.reload();
                    window.location.href = "/customer/myWaitCallCustomer";
                } else {
                    alert("操作失败，" + data.msg);
                }
            }
        });
//    });
    }

    $("#crmView").on("click", function () {
        $.ajax({
            url: '/project/getCRMURL',
            data: {"customerId": $("#customerId").val()},
            type: "GET",
            success: function (data) {
                if (data.result === '1') {
                    if (data.data.entity === "" || data.data.entity === null) {
                        showMessage("error", "该用户暂未推送至CRM！", 1000);
                        return false;
                    }
                    window.location.href = data.data.entity;
                } else {
                    showMessage("error", "操作失败！", 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);
    }
</script>
</body>

</html>