import request from '@/utils/request'

// 获取表格分页数据
export function getTableData(forData) {
	let data = new FormData()
	if (typeof forData.page !== 'undefined') {
		data.append('page', forData.page)
	}
	if (typeof forData.rows !== 'undefined') {
		data.append('rows', forData.rows)
	}
	if (typeof forData.key !== 'undefined') {
		data.append('key', forData.key)
	}
	if (typeof forData.rtown !== 'undefined') {
		data.append('rtown', forData.rtown)
	}
	if (typeof forData.rtype !== 'undefined') {
		data.append('rtype', forData.rtype)
	}

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

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

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

// 修改周边
// 添加周边
export function appinsertArounds(forData) {
	let data = {}
	if (typeof forData.rtype !== 'undefined' && forData.rtype !== '') {
		data.rtype = forData.rtype
	}
	if (typeof forData.rtown !== 'undefined' && forData.rtown !== '') {
		data.rtown = forData.rtown
	}
	if (typeof forData.rname !== 'undefined' && forData.rname !== '') {
		data.rname = forData.rname
	}
	if (typeof forData.rphone !== 'undefined' && forData.rphone !== '') {
		data.rphone = forData.rphone
	}
	if (typeof forData.radress !== 'undefined' && forData.radress !== '') {
		data.radress = forData.radress
	}
	if (typeof forData.detail !== 'undefined' && forData.detail !== '') {
		data.detail = forData.detail
	}
	if (typeof forData.first_img !== 'undefined' && forData.first_img !== '') {
		data.first_img = forData.first_img
	}
	if (typeof forData.post_video !== 'undefined' && forData.post_video !== '') {
		data.show_video = forData.post_video
	}
	if (typeof forData.detail_img !== 'undefined' && forData.detail_img !== '' && forData.detail_img.length > 0) {
		var tmpStr = ''
		for (var i = 0; i < forData.detail_img.length; i++) {
			tmpStr += forData.detail_img[i] + ','
		}
		data.detail_img = tmpStr.substring(0, tmpStr.length - 1)
	}
	if (typeof forData.jingwei !== 'undefined' && forData.jingwei !== '') {
		data.jingwei = forData.jingwei
	}
	
	return request({
		url: '/mhotel/appinsertArounds.action',
		method: 'post',
		data
	})
}

// // 上传文件
// export function uploadFiles(file) {
// 	let data = new FormData()
// 	if (typeof file !== 'undefined') {
// 		data.append('files', file)
// 	}
	
// 	return request({
// 		url: '/file/cos/upload',
// 		method: 'post',
// 		data
// 	})
// }

// 修改周边
export function appupdateArounds(forData) {
	let data = {}
	if (typeof forData.id !== 'undefined' && forData.id !== '') {
		data.id = forData.id
	}
	if (typeof forData.rtype !== 'undefined' && forData.rtype !== '') {
		data.rtype = forData.rtype
	}
	if (typeof forData.rtown !== 'undefined' && forData.rtown !== '') {
		data.rtown = forData.rtown
	}
	if (typeof forData.rname !== 'undefined' && forData.rname !== '') {
		data.rname = forData.rname
	}
	if (typeof forData.rphone !== 'undefined' && forData.rphone !== '') {
		data.rphone = forData.rphone
	}
	if (typeof forData.radress !== 'undefined' && forData.radress !== '') {
		data.radress = forData.radress
	}
	if (typeof forData.detail !== 'undefined' && forData.detail !== '') {
		data.detail = forData.detail
	}
	if (typeof forData.first_img !== 'undefined' && forData.first_img !== '') {
		data.first_img = forData.first_img
	}
	if (typeof forData.post_video !== 'undefined' && forData.post_video !== '') {
		data.show_video = forData.post_video
	}
	if (typeof forData.detail_img !== 'undefined' && forData.detail_img !== '' && forData.detail_img.length > 0) {
		var tmpStr = ''
		for (var i = 0; i < forData.detail_img.length; i++) {
			tmpStr += forData.detail_img[i] + ','
		}
		data.detail_img = tmpStr.substring(0, tmpStr.length - 1)
	}
	if (typeof forData.jingwei !== 'undefined' && forData.jingwei !== '') {
		data.jingwei = forData.jingwei
	}
	
	return request({
		url: '/mhotel/appupdateArounds.action',
		method: 'post',
		data
	})
}

// 获取周边对应的产品
export function getProductTableData(forData) {
	let data = new FormData()
	if (typeof forData.page !== 'undefined') {
		data.append('page', forData.page)
	}
	if (typeof forData.rows !== 'undefined') {
		data.append('rows', forData.rows)
	}
	if (typeof forData.aid !== 'undefined') {
		data.append('aid', forData.aid)
	}

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

// 删除周边
export function appdelAround(forData) {
	let data = new FormData()
	if (typeof forData !== 'undefined' && forData != '') {
		data.append('id', forData)
	}

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

// 添加产品
export function appinsertAroundPd(forData) {
	let data = {}
	if (typeof forData.aid !== 'undefined' && forData.aid !== '') {
		data.aid = forData.aid
	}
	if (typeof forData.product_name !== 'undefined' && forData.product_name !== '') {
		data.product_name = forData.product_name
	}
	if (typeof forData.product_desc !== 'undefined' && forData.product_desc !== '') {
		data.product_desc = forData.product_desc
	}
	if (typeof forData.price !== 'undefined' && forData.price !== '') {
		data.price = forData.price
	}
	
	return request({
		url: '/mhotel/appinsertAroundPd.action',
		method: 'post',
		data
	})
}

// 编辑产品
export function appupdateAround_pd(forData) {
	let data = {}
	if (typeof forData.id !== 'undefined' && forData.id !== '') {
		data.id = forData.id
	}
	if (typeof forData.product_name !== 'undefined' && forData.product_name !== '') {
		data.product_name = forData.product_name
	}
	if (typeof forData.product_desc !== 'undefined' && forData.product_desc !== '') {
		data.product_desc = forData.product_desc
	}
	if (typeof forData.price !== 'undefined' && forData.price !== '') {
		data.price = forData.price
	}
	
	return request({
		url: '/mhotel/appupdateAround_pd.action',
		method: 'post',
		data
	})
}

// 删除产品
export function appdelAround_pd(forData) {
	let data = new FormData()
	if (typeof forData !== 'undefined' && forData != '') {
		data.append('id', forData)
	}

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