$('.refresh').click(function(){location.reload();});
function system_update()
{
	loading = parent.layer.load(1, {shade: [0.1, '#fff']});
	$.get(checkVerson_url, function(result){
		parent.layer.close(loading);
		if(result.code == 200) {
			parent.layer.confirm('有新的更新包('+result.data.last_version+')<br><font color=red>更新前请自行备份当前程序</font>',{title:'检查更新',btn:['开始更新','稍后更新'], closeBtn: 0},function(){
				parent.layer.closeAll();
				loading = parent.layer.load(3, {shade: [0.1, '#fff'],scrollbar: false});
				$.get(systemUpdate_url, function(res){
					parent.layer.close(loading);
					if(res.code == 200) {
						parent.layer.alert(res.msg,{icon:1, closeBtn: 0},function(index){
							parent.location.reload(); //刷新父页
						});
					} else {
						parent.layer.alert(res.msg,{icon:2, closeBtn: 0});
					}
				})
			})
		} else {
			parent.layer.msg(result.msg);
		}
	});
}
//function
function table_ajax(data,posturl,alerttype)
{
	loading = layer.load(1, {shade: [0.1, '#fff']});
	$.ajax({
        url: posturl,
        data: data,
        type: 'POST',
        dataType: 'JSON',
        success: function(result){
        	layer.close(loading);
            layuialert(result,alerttype);
        }
    });
}
function openlayer(url,title,size,reloadtable)
{
	var size = size || 'm';
	if(document.body.clientWidth < 800) {
		size = 'l';
	}
	switch(size) {
		case 'l':
			width = '95%';
			height = '95%';
		break;
		case 'm':
			width = '80%';
			height = '90%';
		break;
		case 's':
			width = '50%';
			height = '85%';
		break;
		case 'xs':
			width = '600px';
			height = '85%';
		break;
		default:
			width = '80%';
			height = '90%';
    }
	var title = title||false;
	var reloadtable = reloadtable || false;
	layer.open({
		title:title,
		type:2,
		shade:0.8,
		scrollbar: false,
		maxmin: title==false ? false : true, 
		area:[width,height],
		content:url
		,end:function(){
			if(reloadtable == true) {
				layui.table.reload('data_table');
			}
		}
	});
}
function openfulllayer(url,title) {
	var index = layer.open({
		title:title,
		type:2,
		maxmin: true, 
		content:url
	});
	layer.full(index);
}
function openparentlayer(url,title)
{
	parent.layer.open({
		title:title,
		type:2,
		shade:0.8,
		scrollbar: false,
		maxmin: true, 
		area:['95%','90%'],
		content:url,
		end:function(){
			// location.reload();
			layui.table.reload('data_table');
		}
	});
}
function openparentlayer2(url,title)
{
	parent.layer.open({
		title:title,
		type:2,
		shade:0.8,
		scrollbar: false,
		maxmin: true, 
		area:['95%','90%'],
		content:url
	});
}
function openmedia(url)
{
	layer.open({
		title: false,
		shadeClose: true,
		type:2,
		shade:0.8,
		scrollbar: false,
		area:['90%','90%'],
		content:url
	});
}
function viewpic(img) {
    layer.open({
        type: 1,
        area:['auto', 'auto'],
        title: false,
        closeBtn: 1,
        shadeClose: true,
        content: '<img src="'+img+'" style="max-width:800px;max-height:500px;">'
    });
}
function closelayer(){parent.layer.closeAll();}
function dellayer(url)
{
  layer.confirm('确认删除吗？',{title:'删除'},function()
  {
    $.post(url,'',function(result){
      layer.msg(result.msg,{time:1500,icon:result.code},function(){location.reload();})
    })
  })
}
function layuialert(result,type)
{
	var msg;
	if(result.code == 1) {
		msg = '<i class="layui-icon layui-icon-ok" style="font-size:42px;font-weight:bold;color:#5FB878;"></i><br>' + result.msg;
	} else {
		msg = '<i class="layui-icon layui-icon-close" style="font-size:42px;font-weight:bold;color:#FF5722;"></i><br>' + result.msg;
	}
	switch(type) {
		case 0: // 没有任何动作
			layer.msg(msg,{time:2000},function(){
				return false;
			})
		break;
		case 1: // 成功后刷新当前页
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					location.reload();
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			}
		break;
		case 2: // 失败后刷新当前页
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					location.reload();
				})
			}
		break;
		case 3: // 成功后关闭当前layer 并刷新父层
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					parent.layer.closeAll(); //关闭open层
					parent.location.reload(); //刷新父页
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			}
		break;
		case 4: // 成功后跳转指定地址
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					location.href = result.url
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					location.reload();
				})
			}
		break;
		case 5: // 成功和失败后刷新当前页
			layer.msg(msg,{time:2000},function(){
				location.reload();
			})
		break;
		case 6: // 成功后关闭当前layer 并跳转指定页面
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					parent.layer.closeAll(); //关闭open层
					parent.location.href = result.url; //跳转
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			}
		break;
		case 7: // 成功后关闭当前layer 并重载父层数据表格
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					parent.layer.closeAll(); //关闭open层
					parent.layui.table.reload('data_table'); //重载父层数据表格
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			}
		break;
		case 8: // 成功后关闭当前layer 并刷新框架
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					parent.layer.closeAll(); //关闭open层
					top.location.reload(); //刷新框架
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			}
		break;
		case 9: // 成功后顶层打开，失败刷新
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					top.location.href = result.url
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					location.reload();
				})
			}
		break;
		case 10: // 成功后重载当前数据表格，失败刷新当前页
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					layui.table.reload('data_table'); //重载数据表格
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					location.reload();
				})
			}
		break;
		case 11: // 成功后不动，失败后重载当前数据表格
			if(result.code==1) {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					layui.table.reload('data_table'); //重载数据表格
				})
			}
		break;
		case 12: // 成功弹出继续添加选项,失败停留
			if(result.code==1) {
				layer.confirm(result.msg,{
					title: '选择操作'
					,icon:6
					,btn:['新增类似','新增内容','关闭']
					,btn3: function(index,layero) {
						parent.layer.closeAll(); //关闭open层
						parent.layui.table.reload('data_table'); //重载父层数据表格
					}
					,yes(index, layero) {
						layer.close(index);
						$('input[name=alias]').val('');
					}
					,btn2(index, layero) {
						layer.close(index);
						location.reload();
					}
				})
			} else {
				layer.msg(msg,{time:2000},function(){
					return false;
				})
			}
		break;
	}
	
}