import request from '@/utils/request'
import { download, downloadPdf } from '@/utils/request'
const baseUrl = import.meta.env.VITE_APP_PRODUCTION_API

// 查询外协单
export function listOrder(query) {
	return request({
		url: baseUrl + '/business/outsource/list',
		method: 'get',
		params: query
	})
}

export function innerOrderList(query) {
	return request({
		url: baseUrl + '/business/outsource/innerList',
		method: 'get',
		params: query
	})
}
export function listOutsourceDeptList(query) {
	return request({
		url: baseUrl + '/business/outsource/getOutsourceDept',
		method: 'get',
		params: query
	})
}

// 查询外协单
export function getOrder(id) {
	return request({
		url: baseUrl + '/business/outsource/' + id,
		method: 'get'
	})
}
// 查询内部外协单
export function getInnerOrder(query) {
	return request({
		url: baseUrl + '/business/outsource/getInnerOrder',
		method: 'get',
		params: query
	})
}

export function carrierForOutsource(query) {
	return request({
		url: baseUrl + '/business/outsource/carrierForOutsource',
		method: 'get',
		params: query
	})
}


// 保存外协单
export function saveOrder(data) {
	return request({
		url: baseUrl + '/business/outsource/add',
		method: 'post',
		data: data
	})
}

// 保存外协单
export function submitDetails(data) {
	return request({
		url: baseUrl + '/business/outsource/submitDetails',
		method: 'post',
		data: data
	})
}
export function submitInnerDetails(data) {
	return request({
		url: baseUrl + '/business/outsource/submitInnerDetails',
		method: 'post',
		data: data
	})
}

export function submitDetailsOnFirst(data) {
	return request({
		url: baseUrl + '/business/outsource/submitDetailsOnFirst',
		method: 'post',
		data: data
	})
}
export function processesForOutsource(data) {
	return request({
		url: baseUrl + '/business/outsource/processesForOutsource',
		method: 'post',
		data: data
	})
}

// 导出
export function exportOutsource(data) {
	download(
		baseUrl + "/business/outsource/export",
		{
			...data,
		},
		`外协发出单_${new Date().getTime()}.xlsx`
	)
}

//打印
export function printOutsource(data) {
	downloadPdf(
		baseUrl + "/business/outsource/printDetailPdf",
		{
			...data,
		},
		`外协发出单_${new Date().getTime()}.pdf`
	)
}


// 修改外协单
export function submitOrder(data) {
	return request({
		url: baseUrl + '/business/outsource',
		method: 'put',
		data: data
	})
}

// 删除外协单
export function delOrder(id) {
	return request({
		url: baseUrl + '/business/outsource/' + id,
		method: 'delete'
	})
}
export function delInnerOrder(id) {
	return request({
		url: baseUrl + '/business/outsource/delInnerOrder/' +id,
		method: 'delete',
	})
}

export function delOrderForFirst(id) {
	return request({
		url: baseUrl + '/business/outsource/removeForFirst/' + id,
		method: 'delete'
	})
}

export function getCarrierInfo(data) {
	return request({
		url: baseUrl + '/business/outsource/getCarrierInfo',
		method: 'post',
		data: data
	})
}

export function getProductionPlan(query) {
	return request({
		url: baseUrl + '/business/outsource/getProductionPlan',
		method: 'get',
		params: query
	})
}

export function getLotByProductionPlanSub(data) {
	return request({
		url: baseUrl + '/business/outsource/getLotByProductionPlanSub',
		method: 'post',
		data: data
	})
}

export function getFirstOrder(id) {
	return request({
		url: baseUrl + '/business/outsource/getFirst/' + id,
		method: 'get'
	})
}