diff --git a/src/pages/shopping/components/shoppingCartItem/index.tsx b/src/pages/shopping/components/shoppingCartItem/index.tsx index 3abf4dc..4ffb18a 100644 --- a/src/pages/shopping/components/shoppingCartItem/index.tsx +++ b/src/pages/shopping/components/shoppingCartItem/index.tsx @@ -167,7 +167,7 @@ const ShoppingCartItem: FC = (props) => { console.log('rerender component ShoppingCartItem', props, props.itemData?.purchaser_name) const currentItemData = useRef(props.itemData) - // 即使更新 useRef 的数据 不然拿到的还是旧数据 + // 及时更新 useRef 的数据 不然拿到的还是旧数据 currentItemData.current = props.itemData const [itemData, setItemData] = usePropsValue({ @@ -254,43 +254,47 @@ const ShoppingCartItem: FC = (props) => { // 更新当前客户的多选项 const updatePurchaserMultipleSelection = (purchaserId: number, payload: Goods, operationType: OperationType, goodsId: number) => { - console.log('delete', colorStore, purchaserId) - if (operationType === 'add') { - const multipleSelection = { - ...colorStore?.[purchaserId]?.multipleSelection, - [goodsId]: payload, + if (itemData?.purchaser_id === purchaserId) { + console.log('updatePurchaserMultipleSelection', colorStore, purchaserId) + if (operationType === 'add') { + const multipleSelection = { + ...colorStore?.[purchaserId]?.multipleSelection, + [goodsId]: payload, + } + dispatch({ + type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX, + data: { + purchaserId, + multipleSelection, + }, + }) + // 全选标识 + if (itemData?.[BackEndSaleModeListFieldMap[selected]].length === Object.keys(multipleSelection).length) { + dispatch({ type: ShoppingDispatchType.UPDATE_MULTIPLE_SELECTION_STATUS, data: true }) + } } - dispatch({ - type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX, - data: { - purchaserId, - multipleSelection, - }, - }) - // 全选标识 - if (currentItemData.current?.purchaser_id === purchaserId && currentItemData.current?.[BackEndSaleModeListFieldMap[selected]].length === Object.keys(multipleSelection).length) { - dispatch({ type: ShoppingDispatchType.UPDATE_MULTIPLE_SELECTION_STATUS, data: true }) + else if (operationType === 'delete') { + const temp = { ...colorStore?.[purchaserId]?.multipleSelection } + delete temp?.[goodsId] + dispatch({ + type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX, + data: { + purchaserId, + multipleSelection: temp, + }, + }) + dispatch({ type: ShoppingDispatchType.UPDATE_MULTIPLE_SELECTION_STATUS, data: false }) } } - else if (operationType === 'delete') { - const temp = { ...colorStore?.[purchaserId]?.multipleSelection } - delete temp?.[goodsId] - dispatch({ - type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX, - data: { - purchaserId, - multipleSelection: temp, - }, - }) - dispatch({ type: ShoppingDispatchType.UPDATE_MULTIPLE_SELECTION_STATUS, data: false }) - } } - const handleOtherHighLight = (purchaserId: number) => { - console.log('handleOtherHighLight', purchaserId, currentCheckedPurchaserId) - if (purchaserId === currentCheckedPurchaserId) { + const handleOtherHighLight = (purchaserId: number, deletedItemData: any) => { + if (purchaserId === itemData?.purchaser_id) { + // 当前订单类型还有数据,跳过 + if (deletedItemData?.[BackEndSaleModeListFieldMap[selected]].length !== 0) { return } + // 当前订单类型没有数据,高亮其他订单类型 for (let i = 0; i < BackEndSaleModeListField.length; i++) { - if (itemData?.[BackEndSaleModeListFieldMap[i]].length !== 0) { + if (deletedItemData?.[BackEndSaleModeListFieldMap[i]].length !== 0) { // 控制高亮 onSelectOrderType(i) return diff --git a/src/pages/shopping/index.tsx b/src/pages/shopping/index.tsx index 90a7f03..0d2eaaf 100644 --- a/src/pages/shopping/index.tsx +++ b/src/pages/shopping/index.tsx @@ -162,8 +162,9 @@ const ShoppingCartContainer: FC = () => { multipleSelection: {}, }, }) - fetchData(searchOptions) - events.trigger('handleOtherHighLight', currentCheckedPurchaserId) + const deleted = await fetchData(searchOptions) + + events.trigger('handleOtherHighLight', currentCheckedPurchaserId, deleted.data.list.find(item => item.purchaser_id === currentCheckedPurchaserId)) // Observer.notify(currentCheckedPurchaserId) } else {