UserAvatar_wev8.js 1.95 KB
define(['mUtil', "Component"],function(mUtil, Component) {
	var UserAvatar = function(options) {
        
		Component.super(this, options);
		
		this.type = "UserAvatar";
		this.tpl = this.type + "_html";
		this.css = this.type + "_css";
        this.dataload = true;

		var vm = this.viewModel = {
			userid : "",
			style : "wev-avatar-vertical",
			avatar : "/messager/images/icon_m_wev8.jpg"
		};

		this.beforeMount = function () {
			vm.style.indexOf("vertical") != -1 && (vm.style = "wev-avatar-vertical") || (vm.style = "wev-avatar-horizontal");
		};

		this.mounted = function(){
			var that = this;
			var type = this.type;
			var $abbr = this.$el,
				$comp = $abbr.children(".wev-comp-" + type);
			
			var actionUrl = mUtil.getActionUrl(this.type, {action : "info", "userid" : vm.userid}, this.pageid);
			mUtil.getJSON(actionUrl, function(result) {
				var data = result.data;
				var headPicMes = data.avatar;
				var headFormat = headPicMes.headFormat;
				//1:显示姓名首字  2:显示固定图片  3:显示姓名后两字
				if("1" === headFormat || "3" === headFormat){
					//以css形式显示
					var bgColor = headPicMes.background;
					var fontColor = headPicMes.fontColor;
					var shortname = headPicMes.shortname;
					var paddingleft = vm.style.indexOf("horizontal") != -1 ? "padding-left:0; " : "";
					var htm = "<div class='resourceimage' style='background:"+ bgColor +"; color:"+ fontColor +";"+ paddingleft +" '>" + shortname + "</div>";
					$("img", $comp).hide();
					$(".wev-avatar-container", $comp).prepend(htm);
				}  else {
					//以图片的形式显示
					$("img", $comp).attr("src", headPicMes.messagerUrls || vm.avatar);
				}
				$(".wev-avatar-username", $comp).html(data.userName);
				$(".wev-avatar-dept", $comp).html(data.deptName);
				$(".wev-avatar-jobtitle", $comp).html(data.jobTitle);
                mUtil.trigger('dataload', that.pageid, that.id);
		    });
		};
    };

    return Component.init(UserAvatar);
});