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
	}

	if (typeof forData.hotelTownship !== 'undefined') {
		query += '&hotelTownship=' + forData.hotelTownship
	}

	if (typeof forData.level !== 'undefined') {
		query += '&level=' + forData.level
	}

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

// 获取乡镇配置列表
export function getTowns() {
	let query = '?code=10'

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

// 新增民宿
export function addHostel(param) {
	let data = new FormData();
	data.append('adminName', param.adminName);
	data.append('password', 'Jams_123456');
	data.append('hotelName', param.hotelName);
	data.append('hotelTownship', param.hotelTownship);
	data.append('corpnName', param.corpnName);
	data.append('corpnPhone', param.corpnPhone);
	data.append('level', param.level);
	data.append('bankCard', param.bankCard);
	data.append('cardName', param.cardName);
	data.append('bankName', param.bankName);
	data.append('fileListJson', param.fileUrl);
	data.append('type', param.jibieId);
	data.append('linkProUrl', param.linkproUrl);

	return request({
		url: '/mhotel/managerAdmininsertAdmin.action',
		method: 'post',
		data
	});
};

// 修改民宿
export function modifyHostel(param) {
	let data = new FormData();
	data.append('id', param.id);
	data.append('adminName', param.adminName);
	data.append('password', 'Jams_123456');
	data.append('hotelName', param.hotelName);
	data.append('hotelTownship', param.hotelTownship);
	data.append('corpnName', param.corpnName);
	data.append('corpnPhone', param.corpnPhone);
	data.append('level', param.level);
	data.append('bankCard', param.bankCard);
	data.append('cardName', param.cardName);
	data.append('bankName', param.bankName);
	data.append('fileListJson', param.fileUrl);
	data.append('type', param.type);
	data.append('linkProUrl', param.linkProUrl);

	return request({
		url: '/mhotel/managerAdminupdateAdmin.action',
		method: 'post',
		data
	});
};

// 删除民宿
export function delHostelAccount(param) {
	let data = new FormData();
	data.append('id', param);

	return request({
		url: '/mhotel/managerAdmindelAdmin.action',
		method: 'post',
		data
	});
};

// 重置民宿管理账号密码
export function resetHostelAccountPassword(param) {
	let data = new FormData();
	data.append('id', param);

	return request({
		url: '/mhotel/managerAdminremovePwd.action',
		method: 'post',
		data
	});
};

// 冻结民宿账号
export function frozenHostelAccount(param) {
	let data = new FormData();
	data.append('id', param);

	return request({
		url: '/mhotel/managerAdminfreezeAdmin.action',
		method: 'post',
		data
	});
};

// 解冻民宿账号
export function thawHostelAccount(param) {
	let data = new FormData();
	data.append('id', param);

	return request({
		url: '/mhotel/managerAdminthawAdmin.action',
		method: 'post',
		data
	});
};

// 民宿字典列表
// code：1.民宿类型；2.民宿服务；3.房型名称；4.房型服务
export function listHomestayDictionary(param) {
	let data = new FormData();
	data.append('code', param);

	return request({
		url: '/mhotel/hotelqueryList.action',
		method: 'post',
		data
	});
};

// 增加民宿字典
export function addHomestayDictionary(param) {
	let data = new FormData();
	data.append('name', param.name);
	data.append('code', param.code);
	if (typeof param.fileUrl !== 'undefined') {
		data.append('fileUrl', param.fileUrl);
	}

	return request({
		url: '/mhotel/hotelinsterHotelDict.action',
		method: 'post',
		data
	});
};

// 修改民宿字典
export function modifyHomestayDictionary(param) {
	let data = new FormData();
	data.append('id', param.id);
	data.append('name', param.name);
	data.append('code', param.code);
	if (typeof param.fileUrl !== 'undefined') {
		data.append('fileUrl', param.fileUrl);
	}

	return request({
		url: '/mhotel/hotelupdateHotelDict.action',
		method: 'post',
		data
	});
};

// 删除民宿字典
export function delHomestayDictionary(param) {
	let data = new FormData();
	data.append('id', param);

	return request({
		url: '/mhotel/hoteldelHotelDict.action',
		method: 'post',
		data
	});
};

// 获取民宿其他配置
export function otherConfig(param) {
	return request({
		url: '/mhotel/hotelqueryTakeOrderDict.action',
		method: 'get'
	});
};

// 修改民宿其他配置
export function modifyOtherConfig(param) {
	const data = {
	  dicts: [
	    {
	      id: param[0].id,
	      code: param[0].miniteValue,
	    },
	    {
	      id: param[1].id,
	      code: param[1].value,
	    },
	    {
	      id: param[2].id,
	      code: param[2].days,
	    }
	  ]
	};
	
	return request({
		url: '/mhotel/hotelupdateTakeOrderDict.action',
		method: 'post',
		data
	});
};