import request from '@/utils/request'

// 获取表格分页数据
export function getTableData(forData) {
	let data = ''
	data += '?page=' + forData.page + '&rows=' + forData.rows

	if (typeof forData.status !== 'undefined') {
		data += '&state=' + forData.status
	}
	if (typeof forData.title !== 'undefined') {
		data += '&title=' + forData.title
	}
	if (forData.search_datatime !== undefined && forData.search_datatime !== null) {
		data += '&startTime=' + forData.search_datatime[0]
		data += '&endTime=' + forData.search_datatime[1]
	}

	return request({
		url: '/mhotel/advertiselistPage.action' + data,
		method: 'get',
		data
	})
}

// 添加广告
export function addAD(forData) {
	let data = {};
	if (typeof forData.adTitle !== 'undefined') {
		data.title = forData.adTitle
	}
	if (typeof forData.imageUrl !== 'undefined') {
		data.imageUrl = forData.imageUrl
	}
	if (typeof forData.logoStyle !== 'undefined') {
		if (forData.logoStyle == '') {
			data.logoUrl = 'null'
		} else {
			data.logoUrl = forData.logoStyle
		}
	}
	if (typeof forData.logoStyleValue !== 'undefined') {
		data.styleValue = forData.logoStyleValue
	}
	if (typeof forData.checkedTypes !== 'undefined') {
		if (forData.checkedTypes == 1) {
			data.jumpWay = '网页'
			data.jumpDirection = forData.adLink
			data.jumpPoint = forData.adLink
			data.subTitle = forData.adPage
		} else if (forData.checkedTypes == 2) {
			data.jumpWay = '小程序'
			data.jumpDirection = forData.jumpDirection
			data.jumpPoint = forData.adPageId
			data.subTitle = forData.adPage
		} else {
			data.jumpWay = '不跳转'
			data.jumpDirection = '无'
			data.jumpPoint = ''
			data.subTitle = ''
		}
	}
	if (typeof forData.adStatus !== 'undefined') {
		if (forData.adStatus == true) {
			data.state = 1
		} else {
			data.state = 0
		}
	}
	if (typeof forData.adOrder !== 'undefined') {
		data.sortLevel = forData.adOrder
	}

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

// 修改广告
export function modifyAD(forData) {
	let data = {};
	if (typeof forData.id !== 'undefined') {
		data.id = forData.id
	}
	if (typeof forData.adTitle !== 'undefined') {
		data.title = forData.adTitle
	}
	if (typeof forData.imageUrl !== 'undefined') {
		data.imageUrl = forData.imageUrl
	}
	if (typeof forData.logoStyle !== 'undefined') {
		if (forData.logoStyle == '') {
			data.logoUrl = 'null'
		} else {
			data.logoUrl = forData.logoStyle
		}
	}
	if (typeof forData.logoStyleValue !== 'undefined') {
		data.styleValue = forData.logoStyleValue
	}
	if (typeof forData.checkedTypes !== 'undefined') {
		if (forData.checkedTypes == 1) {
			data.jumpWay = '网页'
			data.jumpDirection = forData.adLink
			data.jumpPoint = forData.adLink
			data.subTitle = forData.adPage
		} else if (forData.checkedTypes == 2) {
			data.jumpWay = '小程序'
			data.jumpDirection = forData.jumpDirection
			data.jumpPoint = forData.adPageId
			data.subTitle = forData.adPage
		} else {
			data.jumpWay = '不跳转'
			data.jumpDirection = '无'
			data.jumpPoint = ''
			data.subTitle = ''
		}
	}
	if (typeof forData.adStatus !== 'undefined') {
		if (forData.adStatus == true) {
			data.state = 1
		} else {
			data.state = 0
		}
	}
	if (typeof forData.adOrder !== 'undefined') {
		data.sortLevel = forData.adOrder
	}

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

// 删除广告
export function delAD(id) {
	let param = '';
	if (typeof id !== 'undefined') {
		param = '?id=' + id
	}

	return request({
		url: '/mhotel/advertisedel.action' + param,
		method: 'get',
	})
}

// 获取民宿列表数据
export function getMinsuTableData(forData) {
	let query = '?page=' + forData.page + '&rows=' + forData.rows

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

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

// 优惠券列表
export function getYouhuiquanTableData(forData) {
	let data = ''
	data += '?page=' + forData.page + '&rows=' + forData.rows

	if (typeof forData.title !== 'undefined') {
		data += '&name=' + forData.title
	}

	return request({
		url: '/mhotel/CoupomadvertisingCouponPage.action' + data,
		method: 'get',
		data
	})
}

// 攻略（推文）列表
export function getGonglueTableData(forData) {
	let data = ''
	data += '?page=' + forData.page + '&rows=' + forData.rows

	if (typeof forData.title !== 'undefined') {
		data += '&key=' + forData.title
	}
	if (forData.search_datatime !== undefined && forData.search_datatime !== null) {
		data += '&startTime=' + forData.search_datatime[0]
		data += '&endTime=' + forData.search_datatime[1]
	}

	return request({
		url: '/mhotel/articlewalkthroughPage.action' + data,
		method: 'get',
		data
	})
}

// 商品列表
export function getShangpinTableData(forData) {
	let data = ''
	data += '?page=' + forData.page + '&rows=' + forData.rows

	if (typeof forData.key !== 'undefined') {
		data += '&key=' + forData.key
	}

	return request({
		url: '/mhotel/articleproductPage.action' + data,
		method: 'get',
		data
	})
}

// 修改广告状态
export function ead(forData) {
	let data = ''
	data += '?id=' + forData.id + '&state=' + forData.state

	return request({
		url: '/mhotel/advertiseoperateState.action' + data,
		method: 'get',
		data
	})
}