import request from '@/utils/request'

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

	if (typeof forData.type !== 'undefined') {
		data += '&type=' + forData.type
	}
	if (typeof forData.status !== 'undefined') {
		data += '&status=' + forData.status
	}
	if (typeof forData.name !== 'undefined') {
		data += '&name=' + forData.name
	}
	if (forData.search_datatime !== undefined && forData.search_datatime !== null) {
		data += '&grantStartDate=' + forData.search_datatime[0]
		data += '&grantEndDate=' + forData.search_datatime[1]
	}

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


// 批量失效
export function coupomsaveBatchLapse(forData) {
	let data = new FormData()
	if (typeof forData.ids !== 'undefined') {
		data.append('ids', forData.ids)
	}

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

// 新增代金券
export function coupominsterVoucher(forData) {
	let data = new FormData()

	data.append('name', forData.name)
	data.append('deductionPrice', forData.deductionPrice)
	data.append('grantNumber', forData.grantNumber)
	data.append('limitNumber', forData.limitNumber)

	data.append('grantStartDate', forData.grantTimes[0])
	data.append('grantEndDate', forData.grantTimes[1])

	data.append('meetPrice', forData.meetPrice)

	if (forData.effectiveType == 1) {
		data.append('effectiveStartDate', forData.effectiveDateTime[0])
		data.append('effectiveEndDate', forData.effectiveDateTime[1])
	} else if (forData.effectiveType == 2) {
		data.append('effectiveDay', forData.effectiveDay)
		data.append('effectiveLoseDay', forData.effectiveLoseDay)
	}

	data.append('hotelIds', forData.hotelIds)
	data.append('createId', forData.createId)
	data.append('effectiveType', forData.effectiveType)
	data.append('type', forData.type)
	data.append('status', forData.status)

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

// 新增折扣券
export function coupominsterCoupon(forData) {
	let data = new FormData()

	data.append('name', forData.name)
	data.append('rebatePrice', forData.rebatePrice)
	data.append('maxDeduction', forData.maxDeduction)
	data.append('grantNumber', forData.grantNumber)
	data.append('limitNumber', forData.limitNumber)

	data.append('grantStartDate', forData.grantTimes[0])
	data.append('grantEndDate', forData.grantTimes[1])

	data.append('meetPrice', forData.meetPrice)

	if (forData.effectiveType == 1) {
		data.append('effectiveStartDate', forData.effectiveDateTime[0])
		data.append('effectiveEndDate', forData.effectiveDateTime[1])
	} else if (forData.effectiveType == 2) {
		data.append('effectiveDay', forData.effectiveDay)
		data.append('effectiveLoseDay', forData.effectiveLoseDay)
	}

	data.append('hotelIds', forData.hotelIds)
	data.append('createId', forData.createId)
	data.append('effectiveType', forData.effectiveType)
	data.append('type', forData.type)
	data.append('status', forData.status)

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

// 修改代金券
// export function coupominsterModifyVoucher(forData) {
// 	let data = new FormData()

// 	data.append('name', forData.name)
// 	data.append('deductionPrice', forData.deductionPrice)
// 	data.append('grantNumber', forData.grantNumber)
// 	data.append('limitNumber', forData.limitNumber)

// 	data.append('grantStartDate', forData.grantTimes[0])
// 	data.append('grantEndDate', forData.grantTimes[1])

// 	data.append('meetPrice', forData.meetPrice)

// 	if (forData.effectiveType == 1) {
// 		data.append('effectiveStartDate', forData.effectiveDateTime[0])
// 		data.append('effectiveEndDate', forData.effectiveDateTime[1])
// 	} else if (forData.effectiveType == 2) {
// 		data.append('effectiveDay', forData.effectiveDay)
// 		data.append('effectiveLoseDay', forData.effectiveLoseDay)
// 	}

// 	data.append('hotelIds', forData.hotelIds)
// 	data.append('createId', forData.createId)
// 	data.append('effectiveType', forData.effectiveType)
// 	data.append('type', forData.type)
// 	data.append('status', forData.status)
// 	data.append('id', forData.id)

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

// 修改折扣券
// export function coupominsterModifyCoupon(forData) {
// 	let data = new FormData()

// 	data.append('name', forData.name)
// 	data.append('rebatePrice', forData.rebatePrice)
// 	data.append('maxDeduction', forData.maxDeduction)
// 	data.append('grantNumber', forData.grantNumber)
// 	data.append('limitNumber', forData.limitNumber)

// 	data.append('grantStartDate', forData.grantTimes[0])
// 	data.append('grantEndDate', forData.grantTimes[1])

// 	data.append('meetPrice', forData.meetPrice)

// 	if (forData.effectiveType == 1) {
// 		data.append('effectiveStartDate', forData.effectiveDateTime[0])
// 		data.append('effectiveEndDate', forData.effectiveDateTime[1])
// 	} else if (forData.effectiveType == 2) {
// 		data.append('effectiveDay', forData.effectiveDay)
// 		data.append('effectiveLoseDay', forData.effectiveLoseDay)
// 	}

// 	data.append('hotelIds', forData.hotelIds)
// 	data.append('createId', forData.createId)
// 	data.append('effectiveType', forData.effectiveType)
// 	data.append('type', forData.type)
// 	data.append('status', forData.status)
// 	data.append('id', forData.id)

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

// 获取民宿列表
export function hotelqueryAllHotel() {

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