From 488fc664813a11b5604cbb15dc00fe2645a0845a Mon Sep 17 00:00:00 2001 From: xuan Date: Thu, 23 Mar 2023 19:54:00 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(ID1001599):=20=E3=80=90?= =?UTF-8?q?=E5=86=85=E9=83=A8=E5=B0=8F=E7=A8=8B=E5=BA=8F=E3=80=91-?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=8F=90=E4=BA=A4=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E9=A2=84=E4=BC=B0=E9=87=91=E9=A2=9D=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【【内部小程序】-购物车提交订单后,预估金额没有更新】 https://www.tapd.cn/53459131/bugtrace/bugs/view/1153459131001001599 --- src/pages/searchPage/index.tsx | 3 +- .../components/shoppingCartItem/index.tsx | 24 +++--- src/pages/shopping/context/index.ts | 2 +- src/pages/shopping/index.tsx | 77 ++++++++++++++----- 4 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/pages/searchPage/index.tsx b/src/pages/searchPage/index.tsx index efc448e..f60d3de 100644 --- a/src/pages/searchPage/index.tsx +++ b/src/pages/searchPage/index.tsx @@ -417,8 +417,7 @@ const SearchPage = () => { return ( - - 搜索 + diff --git a/src/pages/shopping/components/shoppingCartItem/index.tsx b/src/pages/shopping/components/shoppingCartItem/index.tsx index 4ffb18a..1538bca 100644 --- a/src/pages/shopping/components/shoppingCartItem/index.tsx +++ b/src/pages/shopping/components/shoppingCartItem/index.tsx @@ -473,17 +473,7 @@ const withStateSlice = (comp, slice: (state: ShoppingStateContextValue, props: P console.log('itemData 有变化') needMemo = false } - if (prevProps.itemData.purchaser_name === '皮特织业') { - console.log('------withStateSlice props-------') - console.log('withStateSlice props prevProps', prevProps) - console.log('withStateSlice props prevProps comparison itemData', prevProps.itemData === nextProps.itemData) - console.log('withStateSlice props nextProps', nextProps) - console.log('withStateSlice props prevProps comparison multipleSelection', prevProps.state.multipleSelection === nextProps.state.multipleSelection) - console.log('withStateSlice props prevProps comparison currentCheckedPurchaserId', prevProps.state.currentCheckedPurchaserId === nextProps.state.currentCheckedPurchaserId) - console.log('withStateSlice props prevProps comparison Observer', prevProps.state.Observer === nextProps.state.Observer) - console.log('withStateSlice props prevProps comparison state', prevProps.state === nextProps.state) - console.log('------withStateSlice props-------') - } + if (prevProps.state.Observer !== nextProps.state.Observer) { console.log('Observer 有变化') needMemo = false @@ -496,6 +486,18 @@ const withStateSlice = (comp, slice: (state: ShoppingStateContextValue, props: P console.log('currentCheckedPurchaserId 有变化') needMemo = false } + if (prevProps.itemData.purchaser_name === '孜然烤鱿鱼') { + console.log('更新 孜然烤鱿鱼', !needMemo) + console.log('------withStateSlice props-------') + console.log('withStateSlice props prevProps', prevProps) + console.log('withStateSlice props prevProps comparison itemData', prevProps.itemData === nextProps.itemData) + console.log('withStateSlice props nextProps', nextProps) + console.log('withStateSlice props prevProps comparison multipleSelection', prevProps.state.multipleSelection === nextProps.state.multipleSelection) + console.log('withStateSlice props prevProps comparison currentCheckedPurchaserId', prevProps.state.currentCheckedPurchaserId === nextProps.state.currentCheckedPurchaserId) + console.log('withStateSlice props prevProps comparison Observer', prevProps.state.Observer === nextProps.state.Observer) + console.log('withStateSlice props prevProps comparison state', prevProps.state === nextProps.state) + console.log('------withStateSlice props-------') + } return needMemo }) const Wrapper = (props: PropsType, ref) => { diff --git a/src/pages/shopping/context/index.ts b/src/pages/shopping/context/index.ts index d4d5b6d..9b5d56c 100644 --- a/src/pages/shopping/context/index.ts +++ b/src/pages/shopping/context/index.ts @@ -77,7 +77,7 @@ export interface ShoppingDispatchContextValue { [ShoppingDispatchType.UPDATE_CURRENT_CHECKED_SALEMODE]: (saleMode: ShoppingStateContextValue['currentCheckedSaleMode']) => void [ShoppingDispatchType.UPDATE_COLOR_STORE]: (colorStore: React.SetStateAction) => void [ShoppingDispatchType.UPDATE_SELECTED_AMOUNT]: (amount: React.SetStateAction) => void - [ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX]: (amount: React.SetStateAction) => void + [ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX]: (amount: React.SetStateAction) => void } export interface ShoppingAction { diff --git a/src/pages/shopping/index.tsx b/src/pages/shopping/index.tsx index c17e1f3..a58e96c 100644 --- a/src/pages/shopping/index.tsx +++ b/src/pages/shopping/index.tsx @@ -40,26 +40,75 @@ const ShoppingCartContainer: FC = () => { } const listHeightRef = useRef('auto') - // 强制刷新 - const [, setForceUpdate] = useState({}) const { fetchData, state } = ShoppingCartListApi() const [searchOptions, setSearchOptions] = useState({}) + const clearMultiSelection = () => { + console.log('clearMultiSelection', shoppingCartData?.list) + const target = shoppingCartData?.list?.find(item => item.purchaser_id === currentCheckedPurchaserId) + console.log('BackEndSaleModeListFieldMap', BackEndSaleModeListFieldMap[currentCheckedSaleMode], target) + const newGoodsKind = Object.fromEntries( + target?.[BackEndSaleModeListFieldMap[currentCheckedSaleMode]].map(item => [ + item?.id, + { + id: item?.id, + estimate_amount: item.estimate_amount, + product_code: item.product_code, + product_color_code: item.product_color_code, + sale_mode: item.sale_mode, + count: currentCheckedSaleMode === EnumSaleMode.Bulk ? item.roll : Number(formatMeterDiv(item.length)), + }, + ]), + ) + const prevMultipleSelection = colorStore?.[currentCheckedPurchaserId]?.multipleSelection + console.log('clearMultiSelection', prevMultipleSelection) + const nextMultipleSelection = prevMultipleSelection + ? Object.fromEntries( + Object.values(prevMultipleSelection).filter(value => !Object.keys(newGoodsKind).includes(String(value.id))) + .map(value => [ + value.id, + { + id: value.id, + estimate_amount: value.estimate_amount, + product_code: value.product_code, + product_color_code: value.product_color_code, + sale_mode: value.sale_mode, + count: value.count, + }, + ], + )) + : {} + console.log('nextMultipleSelection', nextMultipleSelection) + // 清空多选 + dispatch({ + type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX, + data: { + purchaserId: currentCheckedPurchaserId, + goodsKind: newGoodsKind, + multipleSelection: nextMultipleSelection, + }, + }) + } - useDidShow(() => { + const getData = async() => { + await fetchData(getFilterData(searchOptions)) + clearMultiSelection() + } + + useDidShow(async() => { // 第二次进入该页面时触发 if (!isFirst.current) { + console.log('重新刷新') // 重新刷新 - // setShoppingCartData({ list: [], total: 0 }) - fetchData(getFilterData(searchOptions)) + getData() } }) useEffect(() => { console.log('useEffect fetchData', getFilterData(searchOptions)) if (!isFirst.current) { - fetchData(getFilterData(searchOptions)) + getData() } }, [searchOptions]) @@ -92,21 +141,6 @@ const ShoppingCartContainer: FC = () => { console.log('useLayoutEffect') await fetchData(getFilterData(searchOptions)) isFirst.current = false - // const query = Taro.createSelectorQuery() - // console.log('query', query) - // query.select('#shoppingContainer').boundingClientRect() - // query.select('#topBar').boundingClientRect() - // query.select('#bottomBar').boundingClientRect() - // query.exec((res) => { - // console.log('res==>', res) - // const containerHeight = res[0].height - // const topBarHeight = res[1].height - // const bottomBarHeight = res[2].height - // const listHeight = containerHeight - topBarHeight - bottomBarHeight - // listHeightRef.current = `${listHeight}px` - // // 强制刷新 - // setForceUpdate({}) - // }) })() }, []) @@ -233,6 +267,7 @@ const ShoppingCartContainer: FC = () => { setRefreshStatus(true) const res = await fetchData(getFilterData(searchOptions)) if (res.success) { + clearMultiSelection() setRefreshStatus(false) alert.success('刷新成功') }