import {
	postJ,
	post,
	get
} from "@/utils/request";
import Vue from "vue";


// 工单列表
export async function workorderPage(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workorder/page`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 根据工单id获取工序列表

export async function getTaskInstanceList(id) {
	const data = await get(
		Vue.prototype.apiUrl + `/pda/mes/workorder/getTaskInstanceById/${id}`,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 工单信息
export async function workorderInfo(id) {
	let timeStamp =  new Date().getTime() 
	const data = await get(
		Vue.prototype.apiUrl + `/pda/mes/workorder/getById/${id}?timeStamp=${timeStamp}`,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 根据工单ids获取工单列表

export async function workorderList(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workorder/list`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 父级ID查询分类树
export async function treeByPid(params) {
	const data = await get(
		Vue.prototype.apiUrl + `/pda/main/categoryLevel/pdaTreeByPid`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 只查第二层的分类

export async function getTwoTreeByPid(parentId) {
	const data = await get(
		Vue.prototype.apiUrl + `/main/categoryLevel/getTwoTreeByPid/${parentId}`
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 只查最后一层的分类
export async function getLastTreeByPid(parentId) {
	const data = await get(
		Vue.prototype.apiUrl + `/main/categoryLevel/getLastTreeByPid/${parentId}`
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


//根据工艺路线查选中工序的存在副产品但是未处置的工单 
export async function listWorkOrderByTaskId(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workorder/listWorkOrderByTaskId`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 批量处理回收料
export async function disposeorder(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/disposeorder/batchSave`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}





export async function qualityReview(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/feed/qualityReview`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// pda出库单-用于投料
export async function feedOutInOrder(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/feed/feedOutInOrder`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}



// 查询库存台账首页列表
export async function pageeLedgerMain(params) {
	const data = await get(
		Vue.prototype.apiUrl + `/wms/outin/getRealTimeInventory`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 
export async function assetPage(params) {
	const data = await get(
		Vue.prototype.apiUrl + `/main/asset/pdaPage`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 库存台账

export async function realTimeInventory(params) {
	const data = await get(
		Vue.prototype.apiUrl + `/wms/outin/getRealTimeInventory`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}






// 生产明细
export async function produceDetail(id) {
	const data = await get(
		Vue.prototype.apiUrl + `/pda/mes/workorder/produceDetail/${id}`,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 工艺路线
export async function producerouting(params) {
	const data = await get(
		Vue.prototype.apiUrl + `/main/producerouting/page`, params, true,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// PDA检查投料状态
export async function checkStatus(id,taskId) {
	const data = await get(
		Vue.prototype.apiUrl + `/pda/mes/feed/checkStatus/${id}/${taskId}`,
	);
	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 扫码切换工单

export async function getByCode(code) {
	const data = await get(
		Vue.prototype.apiUrl + `/pda/mes/workorder/getByCode/${code}`
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 扫码 获取台账

export async function scanLedger(code) {
	const data = await get(
		Vue.prototype.apiUrl + `/main/asset/getByCode/${code}`
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 查询仓库下拉列表

export async function getWarehouseList() {
	const data = await post(
		Vue.prototype.apiUrl + `/wms/warehouse/getWarehouseList`
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}



//  pda查询周转车
export async function getVehicle(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/getVehicle`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

//  pda报工后换车
export async function transferVehicle(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/transferVehicle`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 更换后的周转车记录
export async function getNewVehicle(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/getNewVehicle`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// pda根据工单id和工序id查询报工详情
export async function listWorkReport(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/listWorkReport`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// pda根据工单id和工序id查询报工详情  (入库)
export async function listApplystorage(params) {
	const data = await get(
		Vue.prototype.apiUrl + `/mes/applystorage/list`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}




// pda 内包装

export async function packingReport(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/packingReport`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}
// pda包装 内查询

export async function getPackingReport(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/getPackingReport`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// pda 外包装
export async function packingReportRepeat(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/packingReportRepeat`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// pda包装 外查询
export async function getPackingReportRepeat(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/getPackingReportRepeat`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// PDA抽样质检-周转车回显

export async function sampleTurnoverReview(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/feed/sampleTurnoverReview`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// PDA抽样质检 ( 获取工序参数)
export async function paramByTaskId(taskId) {
	const data = await get(
		Vue.prototype.apiUrl + `/main/taskqualityparam/listByTaskId/${taskId}`
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}




// PDA  入库查询
export async function listPDAToWarehouse(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/listPDAToWarehouse`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// PDA  碳谷 入库查询
export async function listPDAToWarehouseTG(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/listPDAToWarehouseTG`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


// 根据工单工序查委外信息
export async function checkOutsource(param) {
	const data = await get(
		Vue.prototype.apiUrl + `/mes/applyoutsource/checkOutsource`, param
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}

// 委外提交
export async function applyoutsourceSave(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/mes/applyoutsource/save`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}


//报工-跳过工序
export async function skipTask(params) {
	const data = await postJ(
		Vue.prototype.apiUrl + `/pda/mes/workreport/skipTask`, params, true,
	);

	if (data.code == 0) {
		return data.data;
	}
	return Promise.reject(data.message);
}






