import request from '@/utils/request';

// 获取账号列表数据
export function getTableData(forData) {
	let query = '?page=' + forData.page + '&rows=' + forData.rows
	
	if (typeof forData.adminName !== 'undefined') {
		query += '&adminName=' + forData.adminName
	}

	return request({
		url: '/mhotel/adminqueryPage.action' + query,
		method: 'get'
	});
};

// 新增管理员
export function addAccount(param) {
	let data = new FormData();
	data.append('adminName', param.username);
	data.append('phone', param.phone);
	data.append('password', param.password);
	data.append('level', param.checkedRole[0] == '超级管理员' ? 2 : 1);
	data.append('userName', param.fullname);
	data.append('remark', param.comment);
	data.append('adminPower', '1,2,3');
	
	return request({
		url: '/mhotel/admininsertAdmin.action',
		method: 'post',
		data
	});
};

// 修改管理员
export function modifyAccount(param) {
	let data = new FormData();
	data.append('id', param.id);
	data.append('adminName', param.username);
	data.append('phone', param.phone);
	data.append('password', param.password);
	data.append('level', param.checkedRole[0] == '超级管理员' ? 2 : 1);
	data.append('userName', param.fullname);
	data.append('remark', param.comment);
	data.append('adminPower', '1,2,3');
	
	return request({
		url: '/mhotel/adminupdateAdmin.action',
		method: 'post',
		data
	});
};

// 删除管理员
export function deleteAccount(param) {
	let data = new FormData();
	data.append('id', param);
	
	return request({
		url: '/mhotel/admindelAdmin.action',
		method: 'post',
		data
	});
};

// 重置管理员
export function resetAccountPassword(param) {
	let data = new FormData();
	data.append('id', param);
	
	return request({
		url: '/mhotel/adminremovePwd.action',
		method: 'post',
		data
	});
};
