2025-10-31 22:49:51 +08:00
|
|
|
|
import { httpGet, httpPost, httpDelete } from './http.js';
|
|
|
|
|
|
import { ENV } from './env.js';
|
|
|
|
|
|
|
|
|
|
|
|
const BASE_PATH = '/wmsServer/wms/api/orderIn';
|
|
|
|
|
|
|
|
|
|
|
|
function buildUrl(endpoint) {
|
|
|
|
|
|
return `${BASE_PATH}${endpoint}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 统一的响应数据解包器
|
|
|
|
|
|
* @param {object} response - HTTP 响应对象 { code, data, message }
|
|
|
|
|
|
* @param {string} fallbackMessage - 失败时的默认错误消息
|
|
|
|
|
|
* @returns {object} 解包后的业务数据(附带 httpStatus)
|
|
|
|
|
|
* @throws {Error} 当 HTTP 状态码不是 200 或响应格式不正确时抛出错误
|
|
|
|
|
|
*/
|
|
|
|
|
|
function unwrapResponse(response, fallbackMessage) {
|
|
|
|
|
|
const { code: statusCode, data, message } = response || {};
|
|
|
|
|
|
if (statusCode !== 200) {
|
|
|
|
|
|
throw new Error(message || fallbackMessage || '请求失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!data || typeof data !== 'object') {
|
|
|
|
|
|
throw new Error(fallbackMessage || '响应格式不正确');
|
|
|
|
|
|
}
|
|
|
|
|
|
return Object.assign({ httpStatus: statusCode }, data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const WmsApiClient = {
|
|
|
|
|
|
async engineStockIn({ standId, vehicleNo, goodsId, model, goodsNum = 0, timeout = 10000 }) {
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
efSelect: standId,
|
|
|
|
|
|
vehicleNo,
|
|
|
|
|
|
goodsId,
|
|
|
|
|
|
goodsNum,
|
|
|
|
|
|
model,
|
|
|
|
|
|
};
|
|
|
|
|
|
const res = await httpPost(buildUrl('/loginInBad'), payload, { timeout });
|
|
|
|
|
|
return unwrapResponse(res, '发动机入库失败');
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async emptyVehicleIn({ standId, vehicleNo = 'D99999999', timeout = 8000 }) {
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
efSelect: standId,
|
|
|
|
|
|
vehicleNo,
|
|
|
|
|
|
goodsId: '',
|
|
|
|
|
|
goodsNum: 0,
|
|
|
|
|
|
model: '',
|
|
|
|
|
|
};
|
|
|
|
|
|
const res = await httpPost(buildUrl('/loginToByVehicle'), payload, { timeout });
|
|
|
|
|
|
return unwrapResponse(res, '空载具入库失败');
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async bindVehicle({ vehicleNo, goodsId, goodsNum = 0, userName = 'PDA', timeout = 8000 }) {
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
goodsId,
|
|
|
|
|
|
goodsNum,
|
|
|
|
|
|
vehicleNo,
|
|
|
|
|
|
userName,
|
|
|
|
|
|
};
|
|
|
|
|
|
const res = await httpPost(buildUrl('/bindingVehicl'), payload, { timeout });
|
|
|
|
|
|
return unwrapResponse(res, '绑定物料失败');
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async getOrderInWithVehicleNo({ vehicleNo, timeout = 8000 }) {
|
|
|
|
|
|
const res = await httpGet(buildUrl('/getOrderInWithVehicleNo'), { vehicleNo }, { timeout });
|
|
|
|
|
|
return unwrapResponse(res, '获取物料列表失败');
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2025-11-01 16:04:06 +08:00
|
|
|
|
async rawStockIn({ vehicleNo, standId, orderInType, timeout = 10000 }) {
|
2025-10-31 22:49:51 +08:00
|
|
|
|
const payload = {
|
|
|
|
|
|
vehicleNo,
|
|
|
|
|
|
selectByIn: standId,
|
2025-11-01 16:04:06 +08:00
|
|
|
|
orderInType,
|
2025-10-31 22:49:51 +08:00
|
|
|
|
};
|
|
|
|
|
|
const res = await httpPost(buildUrl('/addInByTask'), payload, { timeout });
|
|
|
|
|
|
return unwrapResponse(res, '原材料入库失败');
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async deleteOrderIn({ rowId, timeout = 8000 }) {
|
|
|
|
|
|
const res = await httpDelete(`${buildUrl('/deleteOrderIn')}/${rowId}`, { timeout });
|
|
|
|
|
|
return unwrapResponse(res, '删除物料失败');
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async testLink({ vehicleNo = 'LSP00168', timeout = 8000 } = {}) {
|
|
|
|
|
|
const res = await httpGet(buildUrl('/getOrderInWithVehicleNo'), { vehicleNo }, { timeout });
|
|
|
|
|
|
return unwrapResponse(res, '接口不通');
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|