
/**
 * Web唐明明
 * 匆匆数载恍如梦，岁月迢迢华发增。
 * 碌碌无为枉半生，一朝惊醒万事空。
 * moduleName: 订单管理
 */

import { request } from '../index'

// 订单列表
const lists = data => {
	return request({
		url		: 'app/orders',
		data
	})
}

// 配置服务包
const service = orderId => {
	return request({
		url		: 'business/' + orderId + '/service',
		method	: 'POST'
	})
}

// 添加服务包
const serviceAdd = (orderId, items) => {
	return request({
		url		: 'business/' + orderId + '/service/calculate',
		method	: 'POST',
		data	: {
			items
		}
	})
}

// 删除服务包
const serviceRemove = (id, data) => {
	return request({
		url		: 'business/' + id + '/service/remove',
		method	: 'POST',
		data
	})
}

// 完成分配
const serviceOver = orderId => {
	return request({
		url		: 'business/' + orderId + '/service/over',
		method	: 'POST',
	})
}

// 订单详情
const info = orderId => {
	return request({
		url		: 'app/orders/' + orderId
	})
}

// 订单资料完善情况
const perfect = orderId => {
	return request({
		url		: 'app/orders/' + orderId + '/data',
	})
}

// 订单基础资料信息
const perfectBase = orderId => {
	return request({
		url		: 'business/' + orderId + '/user/base'
	})
}

// 提交基础资料信息
const updPerfectBase = (orderUserId, data) => {
	return request({
		url		: 'business/' + orderUserId + '/user/base',
		method	: 'POST',
		data
	})
}

// 订单机构资料
const baseBase = baseId => {
	return request({
		url		: 'business/' + baseId + '/user/bank'
	})
}

// 更新机构资料
const updBaseBase = (baseId, data) => {
	return request({
		url		: 'business/' + baseId + '/user/bank',
		method	: 'POST',
		data
	})
}

// 获取缓存机构资料
const cacheBank = id => {
	return request({
		url: 'business/' + id + '/cache/bank',
	})
}

// 存储缓存机构资料
const setCacheBank = (id, data) => {
	return request({
		url: 'business/' + id + '/cache/bank',
		method: 'POST',
		data
	})
}

// 待补差价订单
const ordersDiffs = data => {
	return request({
		url		: 'app/orders/diffs'
	})
}

// 待修改订单
const ordersEditorders = data => {
	return request({
		url		: 'app/orders/editorders'
	})
}

// 个人订单签约
const orderSign = (id, data) => {
	return request({
		url	: 'business/' + id + '/sign_url',
		data
	})
}

// 查询订单签约状态
const getOrderSignStatus = id => {
	return request({
		url: 'business/' + id + '/sign_status'
	})
}

// 机构预估方案
const getSchemes = id => {
	return request({
		url: 'business/' + id + '/item_scheme'
	})
}

// 退款单列表
const refunds = data => {
	return request({
		url: 'app/refunds',
		data
	})
}

// 完善基础资料使用历史数据
const historyBase = (business_order_user_id, user_base_id) => {
	return request({
		url: 'business/' + business_order_user_id + '/user/base/' + user_base_id,
		method: 'POST'
	})
}

// 完善机构资料使用历史数据
const historyBank = (business_order_user_bank_id, user_bank_id) => {
	return request({
		url: 'business/' + business_order_user_bank_id + '/user/bank/' + user_bank_id,
		method: 'POST',
	})
}

// 个人订单确认方案列表
const getConfirmScheme = data => {
	return request({
		url: 'business/close_schemes',
		data
	})
}

// 个人订单确认方案详情
const getConfirmSchemeInfo = business_order_scheme_id => {
	return request({
		url: 'business/close_schemes/' + business_order_scheme_id,
	})
}

// 提交确认或拒绝
const sbuConfirmScheme = (type, business_order_close_scheme_id, data) => {
	return request({
		url: 'business/close_schemes/' + business_order_close_scheme_id + '/' + type,
		data,
		method: 'POST'
	})
}

// 取消订单
const orderCancel = id => {
	return request({
		url: 'business/' + id + '/cancel',
		method: 'POST'
	})
}

// 操作记录
const orderLog = (id, page) => {
	return request({
		url: 'business/' + id + '/do_logs',
		data: {
			page
		}
	})
}

// 支付订单
export {
	lists,
	service,
	serviceAdd,
	serviceRemove,
	serviceOver,
	info,
	perfect,
	perfectBase,
	updPerfectBase,
	baseBase,
	updBaseBase,
	cacheBank,
	setCacheBank,
	ordersDiffs,
	ordersEditorders,
	orderSign,
	getOrderSignStatus,
	getSchemes,
	refunds,
	historyBase,
	historyBank,
	getConfirmScheme,
	getConfirmSchemeInfo,
	sbuConfirmScheme,
	orderCancel,
	orderLog
}
