<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/jsp/includes.jsp" %>

<div class="step-content user-base-info">
    <div class="float-tip-wrap ">
        <div class="input-group">
            <label class="input-label">
                昵　　称：
            </label>
            <input type="text" maxlength="50" placeholder="昵称" class="input-text" id="nickName" value="${userInfo.nickName}">
        </div>
    </div>
    <a href="javascript:void(0)" id="head_upload_2" class="btn-public">上传头像</a>

    <p class="public-tip"><i class="icon-tip"></i>提示：格式支持 jpg、gif、png，分辨率最佳 180*180，文件大小不超过1MB。</p>

    <div class="input-group">
        <div class="img-wblock wblock-action">
        </div>
        <span class="img-arrow">
            →
        </span>

        <div class="img-wblock">
            <div class="img-show max">
            	<img alt="" src="${userInfo.useravatar90}" id="preview_large" >
                <i class="show-cbg"></i>
            </div>

            <p class="img-size">90*90像素</p>
        </div>
        <div class="img-wblock">
            <div class="img-show middle">
            	<img alt="" src="${userInfo.useravatar60}" id="preview_middle" >
                <i class="show-cbg"></i>
            </div>
            <p class="img-size">60*60像素</p>
        </div>
        <div class="img-wblock">
            <div class="img-show min">
            	<img alt="" src="${userInfo.useravatar30}" id="preview_tiny" >
                <i class="show-cbg"></i>
            </div>
            <p class="img-size">30*30像素</p>
        </div>
    </div>
    <form id="head_update_form">
        <input type="hidden" name="axisX" value="" id="x">
        <input type="hidden" name="axisY" value="" id="y">
        <input type="hidden" name="width" value="" id="w">
        <input type="hidden" name="height" value="" id="h">
        <input type="hidden" name="fileRelativePath" value="" id="srcRFile">
        <input type="hidden" name="fileTempPath" value="" id="srcTFile">
        <input type="hidden" name="fileTempUrl" value="" id="srcUFile">
    </form>
    <div class="btn-area">
        <a id="saveHead" href="javascript:void(0)" class="btn-icon">
            <i class="icon-btn">
                <i class="i-save"></i>
            </i>
            <span>保存</span>
        </a>
    </div>
</div>

<coeus:js src="/js/app/user/head.upload.js"/>
<script type="text/javascript">
	var host = "${host}";
    $(function () {
        $("#saveHead").click(function () {
            submitForm();
        });
    });

    function submitForm() {
        if ($('.wblock-action').html() == "") {
            $("#passwordSet").trigger("click");
            return;
        }
        var nickName = $("#nickName").val();
        var data = $("#head_update_form").serializeArray();
        var obj = new Object();
        obj.name = "nickName";
        obj.value = nickName;
        data.push(obj);
        $.ajax({
            type: 'post',
            url: CONTEXTPATH + "/user/update/avatar.mooc",
            data: data,
            dataType: "json",
            success: function (resultData) {
                if (resultData.result == "1" || resultData.result == 1) { //成功
                    var avatarPath = resultData.avatarPath;
                	var userInfo = resultData.userInfo;
                    $(".model-img .user-max").attr("src", userInfo.useravatar90);
                    $(".pm-mod .user-header").attr("src", userInfo.useravatar30);
                    $.dialog.success("保存成功！");
                } else if (resultData.result == "2" || resultData.result == 2) {
                    $.dialog.success("保存成功！");
                } else {
                    $.dialog.error(resultData.errorMsg);
                }
            },
            error: function () {
            }
        })
    }
</script>