From af3aa008e4ce0def7a20cadf6042d04a035450d2 Mon Sep 17 00:00:00 2001 From: xuan Date: Wed, 22 Mar 2023 15:48:11 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(ID1001585):=20=E3=80=90?= =?UTF-8?q?=E5=86=85=E9=83=A8=E5=95=86=E5=9F=8E=E3=80=91-=E5=8A=9F?= =?UTF-8?q?=E8=83=BD{-=E8=B4=AD=E7=89=A9=E8=BD=A6}=EF=BC=9A=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=85=A8=E9=83=A8=E5=88=A0=E9=99=A4=E9=9D=A2=E6=96=99?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E7=A4=BA=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=9D=A2=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【【内部商城】-功能{-购物车}:选择全部删除面料,提示无法删除面料】 https://www.tapd.cn/53459131/bugtrace/bugs/view/1153459131001001585 --- .../components/shoppingCartItem/index.tsx | 68 ++++++++++--------- src/pages/shopping/index.tsx | 5 +- 2 files changed, 39 insertions(+), 34 deletions(-) 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 {