<%@ page language="java" pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/common/layouts/common.jsp" %>
<html>
<head>
    <title>添加客户状态</title>
    <style>
        .cancelImg {
            cursor: pointer;
        }
    </style>
</head>
<body>
<form id="addStatusForm" method="get" action="${ctx}/customer/changeStatus">
    <input type="hidden" name="projectId" id="cpId" value="${cp.id}">
    请选择状态：
    <select id='customStatus' name="status" class="nochosen">
        <c:forEach items="${status}" var="st">
            <c:if test="${st.status > 1}">
                <option value='${st.status}'>${st.msg}</option>
            </c:if>
        </c:forEach>
    </select>

    <div>
        <label class="control-label" style="display: inline-block;margin: 0 27px 0 0;">发生时间:</label>
        <%--<input type="text" id="occurTime" class="datetime-picker required"--%>
        <%--name="occurTime" date-language="zh-CN"--%>
        <%--data-date-minView="hour" onchange="return putTimeStr(this.value)"--%>
        <%--value="<fmt:formatDate value='${occurTime}' pattern='yyyy-MM-dd' />"/>--%>
        <input id="occurTime" type="text" class="datetime-picker span2 input-large" name="occurTime"
               date-language="zh-CN" onchange="return putTimeStr(this.value)" style="margin: 0;"
               value="${occurTime}" date-format="yyyy-mm-dd hh:ii" date-minView="hour">
    </div>

    <p>
        添加备注：
        <textarea style='margin: 0px 0px 10px; width: 436px; height: 191px;' id="remark" name="remark"></textarea>
    </p>

</form>
<script>
    function putTimeStr(obj) {
        var nerDateStr = obj.slice(0, 16);
        $("#occurTime2").val(nerDateStr);
        return nerDateStr;
//        document.getElementById("occurTime").value=nerDateStr;
    }

    $(".uploadFile span").on("click", function () {
        cancelImg(this);
    });

    function cancelImg(_this) {
        $(_this).parent().children("input").val("");
        $(_this).parent().children(".upload-box").html("");
    }


    $(".uploadFile input").on("change", function (e) {
        var index = $(this).attr("id");
        var file = e.target.files[0],   // 获取本地文件File对象集合
            typelist = ["image/jpeg", "image/png", "image/gif", "image/jpg"],  // 合法文件type列表
            filetype, // 当前文件的类型
            isPic;  // 文件类型是否合法标识
        if (file.size > 2097152) {
            alert("图片不能大于2M");
            cancelImg(this);
            return false;
        }
        filetype = file.type;
        //判断filetype是否属于图片
        isPic = typelist.some(function (item) {
            return item == filetype;
        });
        if (isPic) {
            addImage(file, index);   //同时添加到页面
        } else {
            // 提示文件非图片
            // AnimateUtils.info('不支持的文件类型');
        }
    });


    // 将图片加载至浏览器中,并且显示出来
    function addImage(file, index) {
        function createObjectURL(blob) {
            if (window.URL) {
                return window.URL.createObjectURL(blob);
            } else if (window.webkitURL) {
                return window.webkitURL.createObjectURL(blob);
            }
            return null;
        }

        function revokeObjectURL(url) {
            if (window.URL) {
                return window.URL.revokeObjectURL(blob);
            } else if (window.webkitURL) {
                return window.webkitURL.revokeObjectURL(blob);
            }
        }

        $(".upload-box").eq(index).wrapInner('<img style="width:100px;height:100px; padding:.2rem;" src="' + createObjectURL(file) + '" alt="' + file.name + '" />').insertBefore('.add-button');
    }
</script>
</body>
</html>
