import { addMaterialCoil, updateMaterialCoil, updateMaterialCoilSimple } from "@/api/wms/coil" import { addPendingAction, updatePendingAction } from '@/api/wms/pendingAction'; import { addCoilWarehouseOperationLog } from '@/api/wms/coilWarehouseOperationLog'; export const COIL_ACTIONS = { RECEIVE: 'RECEIVE', // 收货与入库的区别在于,收货相当于计划入库,不管是否已到货都执行这个操作,计划收货也是收获 STORE: 'STORE', // 入库相当于实际收货与入库 CORRECTION: 'CORRECTION', PROCESSING: 'PROCESSING', MERGE: 'MERGE', SPLIT: 'SPLIT', PACK: 'PACK', DELIVER: 'DELIVER', MOVE: 'MOVE', EDIT: 'EDIT', // 对应“根据库位码编辑钢卷信息” ALLOCATE: 'ALLOCATE' } export const actions = Object.values(COIL_ACTIONS) export const actionStrategies = { RECEIVE: { type: COIL_ACTIONS.RECEIVE, name: '计划钢卷收货', description: '计划钢卷收货,不管是否已到货都执行这个操作,计划收货也是收货', handler: async (coil, planId) => { // 收货逻辑,创建一个dataType为10的钢卷,和一个待操作记录 const response = await addMaterialCoil({ ...coil, dataType: 10, }) await addPendingAction({ // 计划ID 对应 warehouseId, warehouseId字段并不是仓库ID,而是一个根据操作类型自适应的查询字段 warehouseId: planId, actionType: 401, currentCoilNo: coil.currentCoilNo, sourceType: 'manual', coilId: response.data.coilId, priority: 0, remark: coil.remark, actionStatus: 0, }) return response.data.coilId } }, STORE: { type: COIL_ACTIONS.STORE, name: '实际钢卷入库', description: '实际钢卷入库,只有在已到货的情况下才执行这个操作', handler: async (coil, action) => { // 更新操作记录状态 actionStatus: 2 // 并行执行更新操作记录和更新钢卷状态 await Promise.all([ updatePendingAction({ ...action, actionStatus: 2, }), updateMaterialCoilSimple({ ...coil, dataType: 1, }), // addCoilWarehouseOperationLog({ // coilId: coil.coilId, // actualWarehouseId: coil.actualWarehouseId, // operationType: 1, // inOutType: 1, // }) ]) // 如果填写了实际库区,还需要新增一条库区出入记录 if (coil.actualWarehouseId) { await addCoilWarehouseOperationLog({ coilId: coil.coilId, actualWarehouseId: coil.actualWarehouseId, operationType: 1, inOutType: 1, remark: '钢卷收货入库' }) } return true } }, } const handleCoil = (action, ...args) => { const strategy = actionStrategies[action] if (strategy && strategy.handler) { return strategy.handler(...args) } else { console.error(`No strategy found for action: ${action}`) } } export default handleCoil