36 lines
950 B
JavaScript
36 lines
950 B
JavaScript
import { createBoxes } from '@/data/demo-data.js'
|
|
import { createItemStates } from '@/utils/picking-state.js'
|
|
|
|
function clone(value) {
|
|
return JSON.parse(JSON.stringify(value))
|
|
}
|
|
|
|
function createInitialState() {
|
|
const boxes = createBoxes()
|
|
return {
|
|
boxes,
|
|
currentBoxIndex: 0,
|
|
itemStates: createItemStates(boxes[0].items),
|
|
partialQuantities: {}, boxDrafts: {}, completedBoxes: {}, scanValue: '', scanHistory: []
|
|
}
|
|
}
|
|
|
|
let state = createInitialState()
|
|
|
|
export function getPickingSession() {
|
|
return clone(state)
|
|
}
|
|
|
|
export function savePickingSession(nextState) {
|
|
state = clone(nextState)
|
|
}
|
|
|
|
export function resetPickingSession() {
|
|
state = createInitialState()
|
|
}
|
|
|
|
export function getPickingOverview() {
|
|
const completedCount = Object.values(state.completedBoxes).filter(Boolean).length
|
|
return { boxes: clone(state.boxes), completedBoxes: { ...state.completedBoxes }, completedCount, pendingBoxCount: state.boxes.length - completedCount }
|
|
}
|