/** 分配工作 **/
function assignWork(applyId, nodeTypeCode) {
	sxUtil.dialog.window({
		url : '/flowInfoManagement/assignWork?salesApplyId=' + applyId + '&nodeTypeCode=' + nodeTypeCode,
		layer : {
			title : '分配工作',
			area : [ '660px', '460px' ],
			success : function(dom, index) {

			},
			btn : [ '确定', '关闭' ],
			yes : function(index, dom) {
				$("#" + nodeTypeCode + "Form").data('index', index).submit();
			}
		}
	});
}

/**流程操作权限控制：将操作按钮遮蔽（效果）**/
function operateShade(operationAttribute,operationAttributeValue,operationTip,operationUrl){
	$("[" + operationAttribute + "='" + operationAttributeValue + "']").each(
			function(i, ele) {
				if ($(ele).hasClass('page-header')) {
					$(ele).append("<em class='operation_shadeParent'></em>").find("button").addClass("operation_color");
					var shadeWidth = 0;
					for(var i=0;i<$(ele).find("button").length;i++){
						shadeWidth += ($(ele).find("button").eq(i).width()+37)
					}
					$(".operation_shadeParent").width(shadeWidth);
				} else {
					$(ele).addClass("operation_color").append("<em class='operation_shade'></em>");
					// $(ele).removeAttr('onclick').unbind();//移除 button 的事件
				}
			});
	$(".operation_shade,.operation_shadeParent").parent().hover(function(){
		var operationTipValue;
		var operation_tipHtml;
		$(this).attr(operationTip)==undefined||$(this).attr(operationTip)==""?operationTipValue="无权限操作":operationTipValue=$(this).attr(operationTip);
		$(this).attr(operationUrl)==undefined||$(this).attr(operationUrl)==""?operation_tipHtml="<span>"+operationTipValue+"</span>":operation_tipHtml="<span>"+operationTipValue+"<br><a href='"+$(this).attr(operationUrl)+"' class='operation_url'>点击前往&gt;&gt;</a></span>";
		$(this).append("<p class='operation_tip'>"+operation_tipHtml+"</p>");
		($(this).find(".operation_tip span").width()+30)<215?$(this).find(".operation_tip").width($(this).find(".operation_tip span").width()+50):$(this).find(".operation_tip").width(200);
		if( $(this).find("em").hasClass("operation_shadeParent") ){
			$(".operation_tip").css({"top":"43px","left":"33px"});
		}
		$(".operation_shade,.operation_tip").click(function(event){
			event.stopPropagation();  //若不移除 button 事件,则 注释上句,放开本注释.
		});
	},function(){
		$(this).find('.operation_tip').remove();
	});
}

/**流程提醒**/
function prohints(){
	var i=0;
	$("#tabs").find("li a").each(function(i){
		var geturl=$(this).attr('href');
		$.ajax({
			url:geturl,
			type: 'GET',
			success: function(data){
				if($(data).eq(0).attr('operate')==undefined){
	        	   var litop=$("#tabs").find("ul li").eq(i).offset().top;
	        	   var liheight=$("#tabs").find("ul li").eq(i).height;
	        	   var littleicon='<span class="fa fa-hand-o-right handright processReminder"></span>';
	        	   $("#tabs").find("ul li").eq(i).find(".handright").remove().end().append(littleicon);
	        	   $(".handright").animate({left:"0"});
	           }else {
	        	  if($("#tabs").find("ul li").eq(i).find("span")){
	        		  $("#tabs").find("ul li").eq(i).find("span").remove();
	        	  }
	           }
			}
		})
	});
}


/** 列表加载附件 **/
function afterLoad(namespace) {
	var attachment_showbox = '<div class="attachment_showbox"><ul></ul></div>';
	var attachment_timer;
	$("body").off("mouseenter").on("mouseenter",".attachment",function(){
		clearTimeout(attachment_timer)
        var $that = $(this) ;
		attachment_timer = setTimeout(function(){
			if( $that.find(".attachment_showbox").length<=0 ){
				var rowId = $that.attr("rowDataId");//所选数据id
				var data = eval('(' + loadFiles(namespace, rowId) + ')');
				var datali = ''
				$that.append(attachment_showbox);
				for(var i=0;i<data.length;i++){
					datali += '<li class="attachment_name">'+data[i].name+'<a class="attachment_preview" onclick="previewDocument(event,\''+data[i].docFileId+'\');">预览</a><a class="attachment_download" href="'+data[i].url2+'">下载</a>'
				};
				$that.find(".attachment_showbox").find("ul").append(datali);
				$that.find(".attachment_showbox").find("ul li:last").css("border-bottom","0px");
			}else{
				$that.find(".attachment_showbox").show();
			}
			$that.find(".attachment_showbox").animate({opacity:1,left:$that.position().left-255,top:$that.position().top-5},"slow");
		},100);
		$that.parent().css("overflow","visible");
		$(".attachment_name").css("text-align","left");
		
	});
	$("body").off("mouseleave").on("mouseleave",".attachment",function(){
		var $that = $(this) ;
		$that.find(".attachment_showbox").hide().css({"top":"50%","left":"60%","opacity":"0"});
	    clearTimeout(attachment_timer);
	    $that.parent().css("overflow","hidden");
	})
}

/** 根据列表业务数据ID查找附件 **/
function loadFiles(namespace, rowId) {
	var data="[";
	$.ajax({
		url : "/" + namespace + "/do_selectFile?id=" + rowId,
		async : false,
		success : function(e) {
			if (e && e.success == true) {
				for(var j = 0; j < e.data.docStorageList.length; j++){
					data+="{name:'"+e.data.docStorageList[j].originalName+"',docFileId:'"+e.data.docStorageList[j].id+"',url2:'/documentStorage/do_download?id="+e.data.docStorageList[j].id+"'},"
				}
			}
		}
	})
	data+="]";
	return data;
}

/** 预览附件 **/
function previewDocument(event,documentStorageId){
	$.ajax({
		type : "GET",
		url : "/documentStorage/judgePicture",
		data : {
			"id" : documentStorageId
		},
		success : function(data) {
			if(data){
				window.open("/documentStorage/previewImage?id="+documentStorageId); 
			}else{
				window.open("/documentStorage/preview?id="+documentStorageId); 
			}
		}
	});
 }

/** tabs页面操作后重加载，请求后台，判断流程权限操作 **/
function loadingAgainDetail() {
	for (var i = 0; i < $("#tabs>div").length; i++) {
		if ($("#tabs>div").eq(i).css("display") != "none") {
			$("#tabs").tabs("load", i)
		}
	}
	prohints();
}

/** list列表页面操作后重加载，请求后台，判断流程权限操作 **/
function loadingAgainList() {
	for (var i = 0; i < $("#sidebarMenu>li").length; i++) {
		if ($("#sidebarMenu>li").eq(i).hasClass("active")) {
			if ($("#sidebarMenu>li").eq(i).hasClass("open")) {
				$("#loadContent").load(
						$("#sidebarMenu>li").eq(i).find(".active .menu-link").attr("url"));
			} else {
				$("#loadContent").load(
						$("#sidebarMenu>li").eq(i).find(".menu-link").attr("url"));
			}
			break;
		}
	}
}

/**输入框输入的（金额）数字（含小数）按照千分符格式显示**/
//控制输入框只能输入数字和小数点
function amountLimit(id) {
	var flag=false;
	var limitV = $("#" + id).val();
	if((limitV.indexOf("-")==0||limitV.indexOf("NaN")==0)){
		flag=true
	}
	$("#" + id).val(limitV.replace(/[^0-9.]/g, ""));
	if(flag){
		$("#" + id).val("-"+$("#" + id).val())
	}
	amountFormat(id);
}

//对输入数字的整数部分插入千位分隔符
function amountFormat(id) {
	var formatV = $("#" + id).val();
	var array = new Array();
	array = formatV.split(".");
	var re = /(-?\d+)(\d{3})/;
	while (re.test(array[0])) {
		array[0] = array[0].replace(re, "$1,$2")
	}

	var returnV = array[0];
	for (var i = 1; i < array.length; i++) {
		returnV += "." + array[i];
	}
	$("#" + id).val(returnV);
}

// 过滤掉数据的千位分隔符
function amountUnformat(id) {
	var v = $("#" + id).val();
	if (undefined != v && '' != v) {// 防止输入空字符串格式化返回NaN
		var x = v.split(',');
		if(x[0]=="-"){
			var newx=[];
			for(var i=1;i<x.length;i++){
				newx.push(x[i])
			}
			x=newx;
			if(x.length>0){
				var returnV = parseFloat(x.join(""));
				returnV = "-"+returnV;
				$("#" + id).val(returnV);
			}else{
				$("#" + id).val("-");
			}
		}else {
			var returnV = parseFloat(x.join(""));
			$("#" + id).val(returnV);
		}
		
	}
}

// jqGrid列表千位分隔符显示数字
function separateAmountFormat(formatV) {
	var array = new Array();
	array = formatV.split(".");
	var re = /(-?\d+)(\d{3})/;
	while (re.test(array[0])) {
		array[0] = array[0].replace(re, "$1,$2")
	}
	var returnV = array[0];
	for (var i = 1; i < array.length; i++) {
		returnV += "." + array[i];
	}
	return returnV;
};