import http from '../http';

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

//获取配置集合
export async function getBasicList(typeId) {
	var dataList = [];
	await http.post('/api/Common/GetBasicList', { FType: typeId }).then((data) => {
		dataList = data.Data.sort(function(a, b) { return a.FOrder > b.FOrder; });
	});
	return dataList;
}

//获取信息
export async function getDataModel(dataInfo, controller) {
	let result = 0;
	await http.post('/api/' + controller + '/GetDataModel', dataInfo).then((data) => {
		result = data.Data;
	});
	return result;
}

//修改信息
export async function updateDataInfo(dataInfo, controller) {
	let result = 0;
	await http.post('/api/' + controller + '/UpdateDataModel', dataInfo).then((data) => {
		result = data.Data;
	});
	return result;
}

//新增信息
export async function insertDataInfo(dataInfo, controller) {
	let result = 0;
	await http.post('/api/' + controller + '/InsertDataModel', dataInfo).then((data) => {
		result = data.Data;
	});
	return result;
}

//删除信息
export async function deleteDataById(dataId, controller) {
	let result = 0;
	await http.post('/api/' + controller + '/DeleteDataById', { FID: dataId.FID || dataId }).then((data) => {
		result = data.Data;
	});
	return result;
}

//获取分页
export async function getPageList(param, controller) {
	param = param || { FPageIndex: 1, FPageSize: 10 };
	let result = {};
	await http.post('/api/' + controller + '/GetPageList', param).then((data) => {
		result = data;
	});
	return result;
}

export async function GetFormulaPageList(param, controller) {
	param = param || { FPageIndex: 1, FPageSize: 10 };
	let result = {};
	await http.post('/api/' + controller + '/GetFormulaPageList', param).then((data) => {
		result = data;
	});
	return result;
}

//保存
export async function commonSave(param, controller) {
	let result = {};
	await http.post('/api/' + controller + '/Save', param).then((data) => {
		result = data;
	});
	return result;
}

//获取模板信息
export async function getTempFile(type) {
	let result = "";
	await http.post('/api/Common/GetTempFile', { FType: type || 1 }).then((data) => {
		result = data.Data;
	});
	return result;
}

//验证用户权限
export async function checkIsHasPower(inData) {
	let result = {};
	await http.post('/api/Common/CheckIsHasPower', inData).then((data) => {
		result = data.Data;
	});
	return result;
}

//获取数据选择值
export async function getDataCode(inData) {
	let result = {};
	await http.post('/api/Common/GetDataCodeList', inData).then((data) => {
		result = data.Data;
	});
	return result;
}

//获取配置集合
export async function getConfigList() {
	let result = {};
	await http.post('/api/Common/GetConfigList', {}).then((data) => {
		result = data.Data;
	});
	return result;
}

//获取系统配置值
export async function getConfigValue(dataId) {
	let result = {};
	await http.post('/api/Common/GetConfigValue', { FID: dataId }).then((data) => {
		result = data.Data;
	});
	return result;
}

//修改数据值状态
export async function stateDataCode(dataId) {
	let result = {};
	await http.post('/api/Common/StateDataCode', { FID: dataId }).then((data) => {
		result = data.Data;
	});
	return result;
}

//删除数据值
export async function deleteDataCode(dataId) {
	let result = {};
	await http.post('/api/Common/DeleteDataCode', { FID: dataId }).then((data) => {
		result = data.Data;
	});
	return result;
}

//设置系统配置值
export async function changeDataCode(inData) {
	let result = {};
	await http.post('/api/Common/ChangeDataCode', inData).then((data) => {
		result = data.Data;
	});
	return result;
}


