<!DOCTYPE html>
<html lang="zh">
<head>
    <@meta/>
	<title>系统用户-编辑</title>
    <#include "admin/common/include_hplus.ftl">
    <#include "admin/common/include_form.ftl">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <h3>头像上传</h3>
                    </div>
                    <div class="ibox-content text-center">
                        <form class="form-horizontal m-t" id="bocjavaForm" action="" method="post">
                        <%-- <h1>${entity.name }</h1>--%>
                        <div class="m-b-sm">
                        	<img id="headImgUrl_preview" alt="image" class="img-circle" width="200" height="200" <#if entity.headImgUrl??>src="${entity.headImgUrl }"<#else>src="<@contextPath/>/common/hplus/img/profile_big.jpg"</#if> >
                        </div>
                        <p class="font-bold">${entity.name }</p>
                        <div class="text-center">
                            <input type="file" name="headImgUrl" accept="image/jpg,image/jpeg,image/png,image/gif" id="uploadFile" style="display: none;" onchange="PreviewImage(this,'imghead','preview');">
                            <a class="btn btn-xs btn-white" href="javascript:$('#uploadFile').click();"><i class="fa fa-upload"></i> 上传</a>
                            <a class="btn btn-xs btn-primary" href="javascript:updateHeadImgUrl();"><i class="fa fa-check"></i> 提交</a>
                        </div>
                        <input type="hidden" name="headImgUrl" id="headImgUrl" value="">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
<script type="text/javascript">
	function PreviewImage(inputFile) {
		App.Ajax.upload({
			form    : $("#bocjavaForm"),
			success : function(resp) {
				$('#headImgUrl').val(resp.data.url);
				$('#headImgUrl_preview').attr('src', resp.data.url);
			}
		});
	}
	
	//表单验证
	function updateHeadImgUrl(){
		var headImgUrl = $('#headImgUrl').val();
		if(!headImgUrl){
			return MsgBox.warn('请先上传头像');
		}
		App.Ajax.request({
			url		: Config.ROOT + '/sys/user/saveHeadImgUrl',
			params	: {
				'headImgUrl': headImgUrl
			}
		});
	}
</script>
</body>
</html>
