import {
	httpUrlFormat,
	ajaxCarryAuthorization,ajaxSync
} from '@/utils/httpUtils.js'


import { ApiVersion,AppVersion } from '@/config/baseConfig.js'

const headerVersion = {
	'API-Version': ApiVersion(),
	'APP-Version':AppVersion()
}


const _flag = 'apiBaseUrl' // 请求的api空间

const apiUrl = {
	'order': httpUrlFormat('/order', _flag),
	'orderPreview': httpUrlFormat('/order/preview', _flag),
	'orderReceive': httpUrlFormat('/order/receive', _flag),
	'orderList': httpUrlFormat('/order/mall_order', _flag),
	'boxOrder': httpUrlFormat('/order/box_order', _flag),
	'boxRecord': httpUrlFormat('/order/box_record', _flag),
	'boxOpen': httpUrlFormat('/order/box_open', _flag),
	'boxPickup': httpUrlFormat('/order/box_pickup', _flag),
	'boxRecycle': httpUrlFormat('/order/box_recycle', _flag),
	'boxInfo': httpUrlFormat('/order/box_info', _flag),
	'orderCancel': httpUrlFormat('/order/cancel', _flag),
	'boxOpenByBoxId': httpUrlFormat('/order/box_open_by_box_id', _flag),
	'orderRefundApi': httpUrlFormat('/order/refund', _flag),
	
	
	
	
	'channelGetApi': httpUrlFormat('/pay/channel/get', _flag),
	'orderReceiptApi': httpUrlFormat('/order/receipt', _flag),
	
	'refundTimeApi': httpUrlFormat('/misc/mall/refund/expire/time', _flag),//商品退款-过期时间
	'boxRefundTimeApi': httpUrlFormat('/order/box/record/expire/time', _flag),//盲盒退款-过期时间
	'boxRefundTimeExpiredApi': httpUrlFormat('/order/box/record/expired', _flag),//盲盒退款-过期时间
	
}

//订单预览
export function orderPreview(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	console.log(headerObj)
	return ajaxCarryAuthorization({
		header: headerObj,
		url: apiUrl.orderPreview,
		method: 'POST',
		data: data
	})
}

export function channelGetApi(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: apiUrl.channelGetApi,
		method: 'GET',
		data: data
	})
}
export function createShopOrder(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: apiUrl.order,
		method: 'POST',
		data: data
	})
}








//商城订单列表
export function orderList(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.order,
		method: 'GET',
		data: data
	})
}
// 删除订单
export function delOrder(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// url: apiUrl.cart_item,
		url: apiUrl.order,
		method: 'DELETE',
		data: data
	})
}
// 取消订单
export function orderCancel(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// url: apiUrl.cart_item,
		url: apiUrl.orderCancel,
		method: 'PUT',
		data: data
	})
}
// 确认收货
export function orderReceive(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// url: apiUrl.cart_item,
		url: apiUrl.orderReceive,
		method: 'POST',
		data: data
	})
}
//创建商城订单
export function createOrder(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.orderList,
		method: 'POST',
		data: data
	})
}
//盲盒订单列表
export function boxOrderList(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.boxOrder,
		method: 'GET',
		data: data
	})
}

//创建盲盒订单
export function boxCreateOrder(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.boxOrder,
		method: 'POST',
		data: data
	})
}
//礼盒/物品列表
export function boxRecord(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.boxRecord,
		method: 'GET',
		data: data
	})
}
//开盲盒
export function boxOpen(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.boxOpen,
		method: 'POST',
		data: data
	})
}
//提取盲盒
export function boxPickup(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.boxPickup,
		method: 'POST',
		data: data
	})
}
//回收盲盒
export function boxRecycle(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.boxRecycle,
		method: 'POST',
		data: data
	})
}
// 订单详情
export function orderDetail(no,data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: httpUrlFormat(`/order/no/${no}`, _flag),
		method: 'GET',
		data: data
	})
}
export function orderIdDetail(id) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: httpUrlFormat(`/box/order/${id}`, _flag),
		method: 'GET',
	})
}
export function orderDetailId(id) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: httpUrlFormat(`/order/${id}`, _flag),
		method: 'GET',
	})
}
//盲盒详情
export function boxInfo(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: apiUrl.boxInfo,
		method: 'GET',
		data: data
	})
}
// 根据盲盒id开盒
export function boxOpenByBoxId(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.boxOpenByBoxId,
		method: 'POST',
		data: data
	})
}



export function orderReceiptApi(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		// url: apiUrl.cart_item,
		url: apiUrl.orderReceiptApi,
		method: 'PUT',
		data: data
	})
}
export function orderRefundApi(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		// url: apiUrl.cart_item,
		url: apiUrl.orderRefundApi,
		method: 'PUT',
		data: data
	})
}


// 商品退款过期时间
export function refundTimeApi(data) {
	return ajaxCarryAuthorization({
		url: apiUrl.refundTimeApi,
		method: 'GET',
		data: data
	})
}
// 盲盒退款过期时间
export function boxRefundTimeApi(data) {
	return ajaxCarryAuthorization({
		url: apiUrl.boxRefundTimeApi,
		method: 'GET',
		data: data
	})
}
export function boxRefundTimeExpiredApi(data) {
	return ajaxCarryAuthorization({
		url: apiUrl.boxRefundTimeExpiredApi,
		method: 'GET',
		data: data
	})
}