import { InvoiceControllerState, IGood } from '../'; import LineAttributeType from '../../InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType'; /** * 删除一个货物 */ export default async (state: InvoiceControllerState, $index?: string) => { if (!$index) return; // 查下要删除的货物 const goods = state.goodsListState.goodsList.filter((e) => e.$index === $index)[0]; if (!goods) return; // 如果正在编辑 就取消编辑 if (state.goodsListState.editGood && state.goodsListState.editGood.$index === $index) { state.goodsListState.editGood = undefined; } const goodsList = state.goodsListState.goodsList; const goodsMap = state.goodsListState.goodsMap; goodsMap.delete($index); for (let i = 0; i < goodsList.length; i++) { if (goodsList[i].$index === $index) { const good = goodsList[i]; if (good.lineAttribute === LineAttributeType.折扣行 && goodsList[i - 1] && goodsList[i - 1].lineAttribute === LineAttributeType.被折扣行) { goodsList[i - 1].lineAttribute = LineAttributeType.正常; } goodsList.splice(i, 1); break; } } state.goodsListState.goodsList = [...goodsList]; state.goodsListState.goodsMap = new Map(goodsMap); };