import http from '../http';

//获取导航菜单
export async function getMenuList(param) {
	var menuList = [];
	await http.post('/api/User/GetMenuList', param).then((data) => {
		menuList = data.Data.filter(s => s.FParentID == -1).sort(function(a, b) {
			return a.FOrder > b.FOrder;
		});
		menuList.forEach((item) => {
			item.FChild = (data.Data.filter(s => s.FParentID == item.FID) || []).sort(function(a, b) {
				return a.FOrder > b.FOrder;
			});
		});
	});
	return menuList;
}

//获取角色集合（分页）
export async function getRolePageList(param) {
	param = param || { FPageIndex: 1, FPageSize: 10 };
	let result = {};
	await http.post('/api/User/GetRolePageList', param).then((data) => {
		result = data;
	});
	return result;
}

//获取角色集合
export async function getRoleList() {
	var dataList = [];
	await http.post('/api/User/GetRoleList').then((data) => {
		dataList = data.Data;
	});
	return dataList;
}

//修改角色
export async function updateRoleModel(dataInfo, controller) {
	let result = 0;
	await http.post('/api/User/UpdateRoleModel', dataInfo).then((data) => {
		result = data.Data;
	});
	return result;
}

//新增角色
export async function insertRoleModel(dataInfo, controller) {
	let result = 0;
	await http.post('/api/User/InsertRoleModel', dataInfo).then((data) => {
		result = data.Data;
	});
	return result;
}

//删除角色信息
export async function deleteRoleModel(dataId) {
	let result = 0;
	await http.post('/api/User/DeleteRoleModel', { FID: dataId }).then((data) => {
		result = data.Data;
	});
	return result;
}

//获取权限信息（非菜单）
export async function getBasicRoleList(dataInfo) {
	let result = [];
	await http.post('/api/User/GetBasicRoleList', dataInfo).then((data) => {
		result = data.Data;
	});
	return result;
}

//保存权限信息
export async function saveRolePower(dataInfo) {
	let result = 0;
	await http.post('/api/User/SaveRolePower', dataInfo).then((data) => {
		result = data.Data;
	});
	return result;
}

//登出用户信息
export async function loginOut(dataInfo) {
	let result = "";
	await http.post('/api/User/LoginOut', dataInfo || {}).then((data) => {
		result = data.Data;
	});
	return result;
}

//获取首页数量
export async function getHomeTopCount(dataInfo) {
	let result = "";
	await http.post('/api/User/GetHomeTopCount', dataInfo || {}).then((data) => {
		result = data.Data;
	});
	return result;
}

//获取用户权限
export async function GetPower(dataInfo) {

	let result="";
	if(typeof(dataInfo.FID)=="undefined")
	{
		return result;
	}
	await http.post('/api/User/GetPower?userid='+dataInfo.FID,{}).then((data)=>{
		result=data.Data;

	});
	return result;
}

export async function CreatePower(list) {
	//alert(JSON.stringify(list));
	let result="";
	await http.post('/api/User/CreatePower',{list:list}).then((data)=>{
		result=data.Data;
	})
	return result;
	
}

export async function GetPowerList() {
	let result="";
	await http.post('/api/User/GetPowerList').then((data)=>{
		result=data.Data;
	})
	return result;
}


