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('keyWord', forData.key)
	}

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

// 获取发布人
export function getPublisher(adminId) {
	let data = new FormData()
	data.append('page', 1)
	data.append('rows', 9999)
	data.append('adminId', adminId)

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

// 置顶攻略
export function setTop(id, istop) {
	let data = {}
	if (typeof id !== 'undefined') {
		data.id = id
	}
	if (typeof istop !== 'undefined') {
		data.isTop = istop
	}

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

// 获取乡镇
export function getTown() {
	return request({
		url: '/mhotel/articletownShips.action',
		method: 'get'
	})
}

// 获取民宿
export function getHotels(townId) {
	var queryString = '?townId=' + townId + '&page=&rows=';

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

// 添加攻略
export function insertStrategy(forData) {
	let data = {}
	if (typeof forData.title !== 'undefined' && forData.title !== '') {
		data.title = forData.title
	}
	if (typeof forData.content !== 'undefined' && forData.content !== '') {
		data.content = forData.content
	}
	if (typeof forData.imgs !== 'undefined' && forData.imgs.length !== 0) {
		data.images = []
		for (let i = 0; i < forData.imgs.length; i++) {
			if (forData.imgs[i].img != '') {
				data.images.push(forData.imgs[i].img);
			}
		}
	}
	if (typeof forData.post_video !== 'undefined' && forData.post_video !== '') {
		data.video = forData.post_video
	}
	if (typeof forData.hotelIds !== 'undefined' && forData.hotelIds !== '') {
		data.hotelIds = forData.hotelIds
	}
	if (typeof forData.rtownId !== 'undefined' && forData.rtownId !== '') {
		data.townId = forData.rtownId
	}
	if (typeof forData.create_id !== 'undefined' && forData.create_id !== '') {
		data.createId = forData.create_id
	}
	if (typeof forData.istop !== 'undefined' && forData.istop !== '') {
		if (forData.istop == true) {
			data.isTop = 1
		} else {
			data.isTop = 0
		}
	}

	return request({
		url: '/mhotel/articleinsertArticleTweetMana.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 updateStrategy(forData) {
	let data = {}
	if (typeof forData.id !== 'undefined' && forData.id !== '') {
		data.id = forData.id
	}
	if (typeof forData.title !== 'undefined' && forData.title !== '') {
		data.title = forData.title
	}
	if (typeof forData.content !== 'undefined' && forData.content !== '') {
		data.content = forData.content
	}
	if (typeof forData.imgs !== 'undefined' && forData.imgs.length !== 0) {
		data.images = []
		for (let i = 0; i < forData.imgs.length; i++) {
			if (forData.imgs[i].img != '') {
				data.images.push(forData.imgs[i].img);
			}
		}
	}
	if (typeof forData.post_video !== 'undefined' && forData.post_video !== '') {
		data.video = forData.post_video
	}
	if (typeof forData.hotelIds !== 'undefined' && forData.hotelIds !== '') {
		data.hotelIds = forData.hotelIds
	}
	if (typeof forData.rtownId !== 'undefined' && forData.rtownId !== '') {
		data.townId = forData.rtownId
	}
	if (typeof forData.create_id !== 'undefined' && forData.create_id !== '') {
		data.createId = forData.create_id
	}
	if (typeof forData.istop !== 'undefined' && forData.istop !== '') {
		if (forData.istop == true) {
			data.isTop = 1
		} else {
			data.isTop = 0
		}
	}

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


// 删除攻略
export function delStrategy(id) {
	let data = {};
	if (typeof id !== 'undefined' && id != '') {
		data.id = id;
	}

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

// 设置发布人
export function bindingPublisher(data) {
	return request({
		url: '/mhotel/articlebindUser.action',
		method: 'post',
		data
	})
}

// 发布人用户列表
export function publisherList(adminId) {
	let data = new FormData()
	data.append('page', 1)
	data.append('rows', 9999)
	data.append('adminId', adminId)

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