import {
	http
} from '@/config/index.js'
/*
 * params 参数 <object>
 *config 配置项 <object> 可传 {header: {}, custom: {load: false}}
 */
//图片
export const downloadFileById = (id, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/api/file/file/findListByIds/'+id, {
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

//平台切换

export const customerChangeToken = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/jwt/customerChangeToken?token=${params.token}&platformCode=${params.platformCode}`, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

//获取用户平台列表
export const getUserPlatformList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post(`/api/admin/platformInfo/getUserPlatformList`, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

//手机号获取platformCode
export const findPlatformCodeByMobile = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/admin/user/findPlatformCodeByMobile/${params.mobile}`, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 登录、获取token
export const customerWxToken = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/jwt/customerWxToken', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 登录、获取token
export const customerToken = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		// http.post('/jwt/customerToken', {
		http.post('/jwt/mobileToken', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 刷新token
export const refreshToken = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/jwt/refreshCustomerWxToken', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取user信息
export const getUserInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/jwt/user', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取企业信息
export const getOneself = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/api/customer/customer/getOneself', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 首页获取数据
export const getHomeData = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/portal/pass/home/homeData', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取自营商城数据
export const getPageData = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/portal/pass/home/pageData', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取自营商城数据
export const getHomePageData = (params, config = {}) => {
	let path = '/api/portal/pass/home/sellerPageData?'
	if (params.source != 'seller') {
		path = '/api/portal/pass/platformProduct/supplier/pageData?'
	}
	path = path +
		`keyword=${params.keyword||""}&page=${params.page}&rows=15&varieties=${params.varieties||""}&deliverPlace=${params.deliverPlace||""}&manufacturer=${params.manufacturer||""}&brandNumber=${params.brandNumber||""}&lowestPrice=${params.min||""}&highestPrice=${params.max||""}`
	return new Promise((resolve, reject) => {
		http.post(path, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}


export const getScreenData = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/business/CentralizedPurchasingProduct/listByKeyword', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 加入购物车
export const addCartPost = (params, config = {}) => {

	return new Promise((resolve, reject) => {
		http.post('/api/order/cart/addCart', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 购物车删除
export const deleteCartGet = (id, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/order/cart/deleteCartById/${id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取购物车
export const getCartList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/api/order/cart/getCartList', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取选中的购物车数据
export const findByIds = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/cart/findByIds', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取新闻详情
export const getNewsDetail = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post(`/api/portal/pass/news/detail/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取自营商城筛选条件
export const getScreenList = (params, config = {}) => {
	if (params.current == 0) {
		return new Promise((resolve, reject) => {
			http.post('/api/portal/pass/platformProduct/self/searchCriteria', {
					...params
				}, {
					...config
				})
				.then(res => {
					resolve(res)
				})
				.catch(err => {
					reject(err)
				})
		})
	} else {
		return new Promise((resolve, reject) => {
			http.get('api/portal/pass/home/categoryData', {
					...params
				}, {
					...config
				})
				.then(res => {
					resolve(res)
				})
				.catch(err => {
					reject(err)
				})
		})
	}
}

// 下单时获取isCreditFacilities
export const getIsCreditUser = (params = {}, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/customer/customerCreditFacilities/isCreditUser', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 下单时获取订单详情
export const getSearchById = (params, config = {}) => {
	let type = params.platformType;
	let path;

	if (type == 'supplier') {
		path = `/api/portal/pass/platformProduct/supplier/searchById?sellerProductId=${params.id}`
	} else if (type == "seller") {
		path = `/api/portal/pass/saleProduct/searchById?sellerProductId=${params.id}`
	} else {
		path = `/api/portal/pass/platformProduct/self/searchById?id=${params.id}`
	}
	return new Promise((resolve, reject) => {
		http.post(path, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取店铺信息
export const getShopInfo = (params, config = {}) => {
	let keyName = params.platformType == 'supplier' ? 'supplierCode' : 'sellerCode'

	if (params.platformType == 'buyer,seller') {
		keyName = "supplierCode"
	}
	params[keyName] = params.code
	let path = params.platformType == 'supplier' ? 'supplierManage' : 'brandManage'
	if (params.platformType == 'buyer,seller') {
		path = "supplierManage"
	}

	return new Promise((resolve, reject) => {
		http.post(`/api/portal/pass/${path}/detail?id=${params.id}&${keyName}=${params.code}`, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 收藏活或者取消收藏店铺
export const collectShop = (id, collect, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post(`/api/portal/brandManage/followOrCancel?id=${id}&type=${collect?'F':'T'}`, {

			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

export const getProductClass = (params, config = {}) => {
	let type = params.type == 'operator' ? 'seller' : 'supplier'
	return new Promise((resolve, reject) => {
		http.post(
				`/api/product/commodityManagement/getCateGoryLevelList?categoryLevel=${params.level}&type=${type}&categoryCode=${params.categoryCode}`, {}, {
					...config
				})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取店铺商品列表
export const getShopProductList = (params, config = {}) => {
	let keyName = (params.platformType == 'supplier' || params.platformType == "buyer,seller") ? 'supplierCode' :
		'sellerCode'
	let code = params.code

	let path =
		`/api/portal/pass/platformProduct/self/pageData?page=${params.page}&rows=10&${keyName}=${code}&categoryCode=${params.categoryCode}`
	if (keyName == 'supplierCode') {
		path =
			`/api/portal/pass/platformProduct/supplier/pageData?page=${params.page}&rows=10&${keyName}=${code}&categoryCode=${params.categoryCode}`
	}
	return new Promise((resolve, reject) => {
		http.post(
				path, {}, {
					...config
				})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 下单时获取订单地址
export const getInfoForCart = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/customer/customerExtra/infoForCart', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 立即购买提交订单
export const submitOrder = (params, config = {}) => {

	let path = 'api/order/selforder/save'
	if (params.type == 'seller') {
		path = 'api/order/selforder/saveFactoryOrder'
	}
	if (params.type == 'supplier') {
		path = 'api/order/supplierorder/saveSupplierOrder'
	}

	return new Promise((resolve, reject) => {
		http.post(path, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 待办列表
export const getBuyerList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/getSellerList', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 集采列表
export const getSchedule = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/business/centralizedPurchasingSchedule/list', {
			...params
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 集采保证金列表
export const getCentralizedPurchasingRegisterList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/business/centralizedPurchasingRegister/list', {
			...params
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
export const centralizedPurchasingSchedule = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/centralizedPurchasingSchedule/getOne/${params.id}`, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 集采保证金详情
export const centralizedPurchasingRegister = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/centralizedPurchasingRegister/getOne/${params.id}`, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 集采保证金审核
export const centralizedPurchasingRegisterAudit = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/business/centralizedPurchasingRegister/audit', {
			...params
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 集采转销售
export const centralizedPurchasingRegisterSales = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/business/centralizedPurchasingSchedule/sales', {
			...params
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
 // 集采上架下架
export const scheduleUpdateStatus = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/centralizedPurchasingSchedule/updateStatus/${params.id}/${params.value}`, {
			...params
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 集采按id删除
export const scheduleDelete = (id, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/centralizedPurchasingSchedule/delete/${id}`,  {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 竞价专场分页
export const auctionSpecialPage = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/business/auctionSpecial/page', {
			...params
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 新增竞价专场
export const auctionSpecialUpdateStatus = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/auctionSpecial/updateStatus/${params.id}/${params.value}`, {
			...params
		}, {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 查询竞价专场/{id}
export const auctionSpecialGet = (id, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/auctionSpecial/get/${id}`,  {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 查询竞价专场/{id}
export const findAuctionMarginInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post(`/api/business/auction/findAuctionMarginInfo?businessId=${params.businessId}&businessTypes=${params.businessTypes}&page=${params.page}&rows=${params.rows}`,  {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

export const pageAudit = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post(`/api/business/auction/pageAudit?specialId=${params.specialId}&page=${params.page}&rows=${params.rows}`,  {
			...config
		})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 买家保证金审核
export const auditBuyerMarginInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post(`/api/business/auction/auditAuctionMarginInfo`, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 购物车提交订单
export const generateOrder = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/cart/generateOrder', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 取消订单
export const cancelById = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/cancelOrder', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 关闭订单
export const closeById = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/closeOrder', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 删除订单
export const deleteByIds = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/deleteByIds', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取验货列表
export const orderInspectionProcess = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/orderInspectionProcess/page',{}, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 验货 回复
export const saveInspectionProcess = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/orderInspectionProcess/save', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 订单详情
export const getOrderDetail = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/order/order/getById/${params.id}`, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 订单流程
export const getOrderProcessList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/order/orderProcess/getOrderProcessList/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 线上验货
export const onlineInspectionApi = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/order/order/confirmInspection/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取合同列表
export const getContractList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/contract/getContractList', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 上传合同
export const getUploadFileId = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/getUploadFileId', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 对接法大大
export const getActorUrlApi = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order//order/getActorUrl', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 删除合同
export const deleteContract = (id, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/order/orderProcess/getOrderProcessList/${id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 上传pdf
export const uploadFile = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.upload('/api/file/file/upload/uploadFile', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 保存合同
export const uploadSaveContract = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/contract/uploadSaveContract', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 保存合同
export const contractConfirmation = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/contract/contractConfirmation', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 订单流程
export const getOrderMarginInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/margin/getOrderMarginInfo/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 定金记录
export const getOrderMarginRecords = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/margin/getOrderMarginRecords/${params.id}/pay`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 定金退款记录
export const getOrderMarginRefundRecords = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/margin/getOrderMarginRecords/${params.id}/refund`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 缴纳定金
export const PayDeposit = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/business/margin/save', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 地址列表
export const getAddressList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/customer/customerReceiveInfo/getReceiveList', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 定金删除
export const deleteMargin = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/business/margin/deleteMargin/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 定金确认
export const depositConfirmSubmit = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/examineMargin', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 定金确认
export const examineMarginRefund = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/examineMarginRefund', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 尾款驳回
export const paymentRejectPay = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/finalPayment/rejectPay', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 尾款同意
export const paymentConfirmPay = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/finalPayment/confirmPay', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取收货数量记录
export const getGoodsCountByOrderId = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/logistics/sendGoods/getGoodsCountByOrderId/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 根据订单id查询付尾款记录
export const getFnalPayment = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/logistics/finalPayment/getByOrderId/${params.id}/pay`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 根据订单id查询退尾款记录
export const getFnalRefundPayment = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/logistics/finalPayment/getByOrderId/${params.id}/refund`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 支付尾款
export const finalPayment = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/finalPayment/create', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 提交尾款
export const normalConfirmPay = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/finalPayment/normalConfirmPay', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 新增自提信息
export const addDelivery = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/billLading/create', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 更新自提信息
export const updateSelf = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/billLading/update', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 新增配送地址
export const saveDelivery = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/customer/customerReceiveInfo/save', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 修改单价
export const editProductPrice = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/editOrderPrice', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 订单驳回
export const operatorSaleOrderAudit = (params, config = {}) => {
	const userInfo = JSON.parse(uni.getStorageSync('userInfo'))
	let httpUrl = ''
	if(userInfo.userCurrentPlat === 'operator') httpUrl = '/api/order/order/operatorSaleOrderAudit'
	if(userInfo.userCurrentPlat === 'supplier') httpUrl = '/api/order/order/supplierSaleOrderAudit'
	if(userInfo.userCurrentPlat === 'seller') httpUrl = '/api/order/order/sellerSaleOrderAudit'
	return new Promise((resolve, reject) => {
		http.post(httpUrl, {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 更新配送地址
export const updateDelivery = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/updateDelivery', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 根据订单id和商品配送类型查看提货单，以此判断是否可以修改地址
export const getByOrderIdAndType = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/billLading/getByOrderIdAndType', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取对账信息
export const getAccountStatementByOrderId = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/reconcilationRecords/getAccountStatementByOrderId', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 驳回开票信息
export const rejectProductInvoice = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/productInvoice/rejectProductInvoice', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 同意开票信息
export const agreeProductInvoice = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/productInvoice/agreeProductInvoice', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取配送单
export const getDeliveryNoticeByOrder = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/deliveryNotice/getDeliveryNoticeByOrder', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 更改订单状态
export const updateStatusStage = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/rpc/order/updateStatusStage', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取收货记录
export const getSendGoodsByOrder = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/sendGoods/getSendGoodsByOrder', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取收货记录
// export const receiveGoods = (params, config = {})=> {
//     return new Promise((resolve, reject)=> {
//         http.post('/api/logistics/sendGoods/receiveGoods',
//             { ...params },
//             { ...config })
//         .then(res=> { resolve(res) })
//         .catch(err=> { reject(err) })
//     })
// }

// 确认出库
export const receiveGoods = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/deliveryNotice/takeGoods', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取物理发票
export const getCustomerInvoive = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/api/customer/customer/getCustomerInvoive', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取未对账单
export const getNoAccountStatement = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/reconcilationRecords/getNoAccountStatement', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 删除发票
export const deleteInvoiceInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/customer/customerInvoiceInfo/delete/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取发票详情
export const getInvoiceInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/customer/customerInvoiceInfo/getOne/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 新增发票
export const saveInvoiceInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/customer/customerInvoiceInfo/save', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取商品发票记录
export const getProductInvoiceByOrderId = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/productInvoice/getProductInvoiceByOrderId', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 物理发票添加或列表
export const getInvoiceInfoByOrderId = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/logistics/invoiceInfo/getInvoiceInfoByOrderId/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 选择物理发票
export const choseInvoice = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/invoiceInfo/saveInvoice', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 删除物理发票
export const deletePhysicalInvoiceInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/logistics/invoiceInfo/delete/${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 保存或者修改物理发票
export const saveProductInvoiceInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/invoiceInfo/batchUpdate', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 对账驳回
export const rejectAccountStatement = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/reconcilationRecords/rejectAccountStatement', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 对账同意
export const agreeAccountStatement = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/reconcilationRecords/agreeAccountStatement', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 提交物理发票
export const batchSaveInvoice = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/productInvoice/batchSaveInvoice', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 删除商品发票
export const deleteProductInvoiceInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get(`/api/logistics/productInvoice/delete${params.id}`, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 退出登录
export const logout = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/jwt/logout', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取购物车数量
export const getCartNumApi = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/portal/pass/cart/getCartNum', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 提收货通知列表
export const getDeliveryNoticeApi = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/deliveryNotice/page', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取收货列表
export const getNoticeNeedList = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/deliveryNotice/getNoticeNeedByOrder', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 提发货通知单详情
export const sendGoodsBToBuyer = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/sendGoods/sendGoods', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 提发货通知单详情
export const getOrderDetailByDelivery = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/deliveryNotice/getOrderDetailByDelivery', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 确认对账
export const saveAccountStatement = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/reconcilationRecords/saveAccountStatement', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 审核尾款退款
export const onExamineFinalRefund = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/order/order/examineFinalRefund', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 更新提发货通知单数量
export const updateReceiveCount = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post('/api/logistics/sendGoods/updateReceiveCount', {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取发货商品对应的批次号
export const getProductBranchList = (id, config = {}) => {
return new Promise((resolve, reject) => {
	http.get(`/api/logistics/billLading/getProductBranchList/${id}`, {}, {
			...config
		})
		.then(res => {
			resolve(res)
		})
		.catch(err => {
			reject(err)
		})
})
}

// 获取承运商列表
export const getPageCarrier = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get('/api/customer/customer/pageCarrier', {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 获取收藏列表
export const getCollectList = (params, config = {}) => {
	let path = `/api/portal/pass/brandManage/pageData?page=${params.page}&rows=15&followed=T`
	if (params.current == 1) {
		path = `/api/portal/pass/supplierManage/pageData?page=${params.page}&rows=15&followed=T`
	}
	return new Promise((resolve, reject) => {
		http.post(path, {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 获取未使用优惠券
export const getUnusedCoupons = (params, config = {}) => {
	let path = `/api/customer/customerCouponPossess/page?useStatus=unUsed`
	return new Promise((resolve, reject) => {
		http.post(path, {
				useStatus: 'unUsed'
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 获取优惠券列表
export const getCouponsList = (params, config = {}) => {

	return new Promise((resolve, reject) => {
		http.post("/api/customer/customerCoupon/possessPage", {}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
// 领取优惠券
export const couponGet = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post("/api/customer/customerCouponPossess/save", {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

// 注册提交账号信息
export const registerFirstStep = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post("/api/customer/customerRetained/save", {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

//  获取客户分类
export const getCustomerType = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post("/api/customer/industry/cascaderData", {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

/// 获取经营主体
export const getBusinessEntity = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get("/api/admin/dictionary/getDicByType/businessEntitytype", {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

/// 获取楼层信息
export const getFloorInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get("/api/portal/pass/home/getSelfFloorList", {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

/// 完善企业信息
export const updateEnterpriseInfo = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.post("/api/customer/authentication/save", {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}

/// 店铺类型
export const getShopType = (params, config = {}) => {
	return new Promise((resolve, reject) => {
		http.get("/api/admin/dictionary/getDicByType/shop_type", {
				...params
			}, {
				...config
			})
			.then(res => {
				resolve(res)
			})
			.catch(err => {
				reject(err)
			})
	})
}
