//**** 公共JS样式定义文件
//**** 易网软件后台框架
//**** www.ew80.com

//全局加载loading
$(window).load(function() {
	$(".loader").delay(0).fadeOut();
	$(".animationload").delay(0).fadeOut("slow");
});

/*全局弹出层定义*/
/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/

//定义AJAX加载时的效果
var index = null;
$(document).ajaxStart(function(){
index = layer.load();
}).ajaxStop(function () {
layer.close(index);
});

	
function ew80_open(title,url,w,h){
	if (title == null || title == '') {
		title=false;
	};
	if (url == null || url == '') {
		url="404.html";
	};
	if (w == null || w == '') {
		w=800;
	};
	if (h == null || h == '') {
		h=($(window).height() - 50);
	};
	layer.open({
		type: 2,
		skin: 'demo-class',
		area: [w+'px', h +'px'],
		fix: false, //不固定
		shade:0.4,
		closeBtn: 2,
		shift: 0,
		shadeClose: false,
		title: title,
		content: url,
		
	});
}

/*关闭弹出框口*/
function ew80_close(){
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}


//////弹出层定义结束

/////////////////////////////////////////////////////////

/*错误提示弹出层定义*/
/* error_t  错误标题 */
/* error_c  错误内容 */
/* error_u  跳转网址 */
/* error_i  提示图标 */

function ew80_error(error_t,error_c ,error_u,error_i){		
layer.alert(error_c,{icon:error_i,title:error_t},function(){ew80_close()});	
	
}




//////错误提示弹出层定义结束

//////////////////////////////////////////////////////////////////



////定义提示弹出层信息

function ew80_tip(obj,icon){
layer.msg(obj,{icon:icon});	
	
}	



/*定义单个删除操作*/
//* obj 对象本身
//* murl 操作地址
// * tip 操作提示
//* myid 操作ID
function ew80_del(obj,myurl,tip,myid){
layer.confirm(tip,{title:'删除提醒',icon:0},function(index){
//发异步删除
var index = null;
$.ajax({
type: "GET",
url: myurl + "?del=del&id="+ myid,
beforeSend: function (request) {
index = layer.load();
},
success: function(msg){
layer.close(index);

//返回的是正确的提示时
if(msg['type']=="1"){layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']});}
parent.$("#ew80_list_warp").load(window.parent.location.href+" #ew80_list_warp");
//返回的是错误信息时					
if(msg['type']=="0"){layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']});}

}
});
               
});
//异步处理完成
}


/*定义异步排序操作*/
//* obj.value 获取表单本身的值
//* obj.name 获取表单NAME NAME值为ID参数
//* myurl 异步操作地址
//* 通过GET方式异步AJAX排序
function ew80_order(obj,myurl){
var index = null;
$.ajax({
type: "GET",
url: myurl+"?act=px&id=" + obj.name +"&v="+obj.value,
beforeSend: function (request) {
index = layer.load();
},
success: function(msg){
layer.close(index);

if(msg['type']=="1"){layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']});}
parent.$("#ew80_list_warp").load(window.parent.location.href+" #ew80_list_warp");
if(msg['type']=="0"){layer.msg(msg['info'],{ icon:msg['icon'],time: msg['times']});}	
	
}
});
}
//*异步AJAX排序函数end


/*状态修改*/
//@obj 
//$myurl 操作网址
//myid  操作的ID
//mytips 操作提示
//myicon 提示图标
function ew80_zt(obj,myurl,myid,mytips,myicon){
var mydata=$(obj).attr('ew80data');
layer.confirm(mytips,{title:'提醒',icon:myicon},function(index){
//发异步修改状态
var index = null;
	$.ajax({
		type: "GET",
		url: myurl + "?act=zt&id="+ myid+"&v="+ mydata,
		beforeSend: function (request) {
		index = layer.load();
		},
		success: function(msg){
		layer.close(index);
		layer.msg(msg['info'],{icon:msg['icon'],time:msg['times']}); 
		parent.$("#ew80_list_warp").load(window.parent.location.href+" #ew80_list_warp");	
		}
});
               
});
//异步处理完成
}


/*锁定操作设置*/
function user_lock(obj,myurl,myid,myname){
layer.confirm("是否将会员 " + myname + " 锁定？",{title:'提醒',icon:0},function(index){
//发异步锁定用户
var index = null;
	$.ajax({
		type: "GET",
		url: myurl + "?lock=lock&id="+ myid,
		beforeSend: function (request) {
		index = layer.load();
		},
		success: function(msg){
		layer.close(index);
        $(obj).parents("tr").find(".lock").html('<a title="点击取消锁定该用户" href="javascript:void();" onclick="user_ulock(this,\'' +myurl+"',"+ "'"+ myid + "','"+ myname +"')\">" +'<eq name="vo.u_zt" value="no"><span class="label label-default">已锁定</span></eq></a>');
		$(obj).remove();
		layer.msg(msg,{icon:1,time:1000});  
		}
});
               
});
//异步处理完成
}


/*解锁操作设置*/
function user_ulock(obj,myurl,myid,myname){
layer.confirm("是否将会员 "+ myname +" 取消锁定？",{title:'提醒',icon:0},function(index){
//发异步取消锁定用户
var index = null;
	$.ajax({
		type: "GET",
		url: myurl + "?lock=ulock&id="+ myid,
		beforeSend: function (request) {
		index = layer.load();
		},
		success: function(msg){
		layer.close(index);
        $(obj).parents("tr").find(".lock").html('<a title="点击锁定该用户" href="javascript:void();" onclick="user_lock(this,\'' +myurl+"',"+ "'"+ myid + "','"+ myname +"')\">" +'<eq name="vo.u_zt" value="yes"><span class="label label-success">正常</span></eq></a>');
		$(obj).remove();
		layer.msg(msg,{icon:1,time:1000});  
		}
});
               
});
//异步处理完成
}



	
/*会员等级禁用*/
function status_lock(obj,myurl,myid,myname){
layer.confirm("是否将等级 " + myname + " 禁用？",{title:'提醒',icon:0},function(index){
//发异步锁定用户
var index = null;
	$.ajax({
		type: "GET",
		url: myurl + "?lock=lock&id="+ myid,
		beforeSend: function (request) {
		index = layer.load();
		},
		success: function(msg){
		layer.close(index);
        $(obj).parents("tr").find(".lock").html('<a title="点击启用" href="javascript:void();" onclick="status_ulock(this,\'' +myurl+"',"+ "'"+ myid + "','"+ myname +"')\">" +'<eq name="vo.shqy" value="no"><span class="label label-default">未启用</span></eq></a>');
		$(obj).remove();
		layer.msg(msg,{icon:1,time:1000});  
		}
});
               
});
//异步处理完成
}


/*会员等级启用*/
function status_ulock(obj,myurl,myid,myname){
layer.confirm("是否将等级 "+myname+" 启用？",{title:'提醒',icon:0},function(index){
//发异步取消锁定用户
var index = null;
	$.ajax({
		type: "GET",
		url: myurl + "?lock=ulock&id="+ myid,
		beforeSend: function (request) {
		index = layer.load();
		},
		success: function(msg){
		layer.close(index);
        $(obj).parents("tr").find(".lock").html('<a title="点击停用" href="javascript:void();" onclick="status_lock(this,\'' +myurl+"',"+ "'"+ myid + "','"+ myname +"')\">" +'<eq name="vo.shqy" value="yes"><span class="label label-success">启用</span></eq></a>');
		$(obj).remove();
		layer.msg(msg,{icon:1,time:1000});  
		}
});
               
});
//异步处理完成
}

/*定义删除客服人员操作*/
function ew80_del_kf(obj,myurl,myid){
layer.confirm('确认要删除该客服吗？删除后不可恢复！',{title:'提醒',icon:0},function(index){
//发异步删除
var index = null;
	$.ajax({
		type: "GET",
		url: myurl + "?del=del&id="+ myid,
		beforeSend: function (request) {
		index = layer.load();
		},
		success: function(msg){
		layer.close(index);
		$(obj).parents(".col-sm-6").remove();
		layer.msg(msg,{icon:1,time:1000});  
		}
});
               
});
//异步处理完成
}

	




