pda-uni-app-perkins/common/wmsApi.js

89 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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, '获取物料列表失败');
},
async rawStockIn({ vehicleNo, standId, orderInType, timeout = 10000 }) {
const payload = {
vehicleNo,
selectByIn: standId,
orderInType,
};
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, '接口不通');
},
};