import Store from '@/store'
import modal from '@/plugins/modal'

export function addWarehouseAccessDetailsOut(item, showMessage = true) {
    if (Store.state.data.warehouseAccessDetailsOut[item.warehouseId] == undefined) {
        item.warehouseRetrievalQuantity = 1
        Store.state.data.warehouseAccessDetailsOut[item.warehouseId] = item
    } else {
        Store.state.data.warehouseAccessDetailsOut[item.warehouseId].warehouseRetrievalQuantity++
    }
    Store.commit('data/SET_WAREHOUSEACCESSDETAILSOUT', JSON.parse(JSON.stringify(Store.state.data.warehouseAccessDetailsOut)))
    if (showMessage) {
        modal.msgSuccess('添加成功')
    }
}

export function updateWarehouseAccessDetailsOut(item, showMessage = true) {
    if (Store.state.data.warehouseAccessDetailsOut[item.warehouseId] == undefined) {
        item.warehouseRetrievalQuantity = 1
        Store.state.data.warehouseAccessDetailsOut[item.warehouseId] = item
    } else {
        Store.state.data.warehouseAccessDetailsOut[item.warehouseId].warehouseRetrievalQuantity = parseInt(item.warehouseRetrievalQuantity)
    }
    Store.commit('data/SET_WAREHOUSEACCESSDETAILSOUT', JSON.parse(JSON.stringify(Store.state.data.warehouseAccessDetailsOut)))
    if (showMessage) {
        modal.msgSuccess('修改成功')
    }
}

export function clearWarehouseAccessDetailsOut(showMessage = true) {
    Store.commit('data/SET_WAREHOUSEACCESSDETAILSOUT', {})
    if (showMessage) {
        modal.msgSuccess('已清空')
    }
}

export function removeWarehouseAccessDetailsOut(item, showMessage = true) {
    delete Store.state.data.warehouseAccessDetailsOut[item.warehouseId]
    Store.commit('data/SET_WAREHOUSEACCESSDETAILSOUT', JSON.parse(JSON.stringify(Store.state.data.warehouseAccessDetailsOut)))
    if (showMessage) {
        modal.msgSuccess('已删除')
    }
}
