/**
 * 出库单接口
 */
import { request } from '../../utils/request'

/**
 * 获取我的领用出库单列表
 * @param pageNum 页码
 * @param pageSize 每页数量
 * @param keyword 关键字
 * @param receiverUserId 领用人ID
 * @param signStatus 签收状态 PENDING-待签收
 * @returns 
 */
export const getProductSalseList = (pageNum: number, pageSize: number, keyword: string, receiverUserId: string, signStatus: string): Promise<any> => {
	let url = `/mes/wm/productsalse/myList?pageNum=${pageNum}&pageSize=${pageSize}`
	if (receiverUserId != null && receiverUserId.length > 0) {
		url += `&receiverUserId=${receiverUserId}`
	}
	if (keyword != null && keyword.length > 0) {
		url += `&salseCode=${encodeURIComponent(keyword)}`
	}
	if (signStatus != null && signStatus.length > 0) {
		url += `&signStatus=${signStatus}`
	}
	return request({
		url: url,
		method: 'GET'
	})
}

/**
 * 获取出库单详情
 * @param salseId 出库单ID
 * @returns 
 */
export const getProductSalseById = (salseId: string): Promise<any> => {
	return request({
		url: `/mes/wm/productsalse/sign/${salseId}`,
		method: 'GET'
	})
}

/**
 * 签收取货
 * @param salseId 出库单ID
 * @returns 
 */
export const signReceive = (salseId: string): Promise<any> => {
	return request({
		url: `/mes/wm/productsalse/signReceive/${salseId}`,
		method: 'PUT'
	})
}

/**
 * 签收（明细级）
 * @param lineId 出库单明细ID
 * @returns 
 */
export const signReceiveLine = (lineId: string): Promise<any> => {
	return request({
		url: `/mes/wm/productsalse/signReceiveLine/${lineId}`,
		method: 'PUT'
	})
}

/**
 * 一键签收
 * @param salseId 出库单ID
 * @returns 
 */
export const signReceiveAll = (salseId: string): Promise<any> => {
	return request({
		url: `/mes/wm/productsalse/signReceiveAll/${salseId}`,
		method: 'PUT'
	})
}

/**
 * 获取待签收物料明细列表
 * @param pageNum 页码
 * @param pageSize 每页数量
 * @param receiverUserId 领用人ID
 * @returns 
 */
export const getPendingReceiveLines = (pageNum: number, pageSize: number, receiverUserId: string): Promise<any> => {
	return request({
		url: `/mes/wm/productsalse/lineList?pageNum=${pageNum}&pageSize=${pageSize}&receiverUserId=${receiverUserId}&receiverStatus=N`,
		method: 'GET'
	})
}
