🐞 fix(#1000680): 修复购物车勾选商品后总计条数未统计的问题
https://www.tapd.cn/53459131/bugtrace/bugs/view/1153459131001000680
This commit is contained in:
parent
2bf7b7084b
commit
2f73350e04
@ -48,7 +48,14 @@ let ColorKindItem: FC<PropsType> = props => {
|
|||||||
type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX,
|
type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX,
|
||||||
data: {
|
data: {
|
||||||
purchaserId: purchaserId,
|
purchaserId: purchaserId,
|
||||||
multipleSelection: { ...state?.multipleSelection, [itemData.id]: itemData },
|
multipleSelection: { ...state?.multipleSelection, [itemData.id]: {
|
||||||
|
id: itemData?.id,
|
||||||
|
estimate_amount: itemData.estimate_amount,
|
||||||
|
product_code: itemData.product_code,
|
||||||
|
product_color_code: itemData.product_color_code,
|
||||||
|
sale_mode: itemData.sale_mode,
|
||||||
|
count: itemData.sale_mode === EnumSaleMode.Bulk ? itemData.roll : Number(formatMeterDiv(itemData.length)),
|
||||||
|
} },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -69,7 +76,6 @@ let ColorKindItem: FC<PropsType> = props => {
|
|||||||
const getInputValue = debounce(async (num, itemData) => {
|
const getInputValue = debounce(async (num, itemData) => {
|
||||||
console.log('num===>', num)
|
console.log('num===>', num)
|
||||||
const targetColor: Record<string, any> = {
|
const targetColor: Record<string, any> = {
|
||||||
product_color_id: itemData.product_color_id,
|
|
||||||
roll: 0,
|
roll: 0,
|
||||||
length: 0,
|
length: 0,
|
||||||
}
|
}
|
||||||
@ -81,10 +87,6 @@ let ColorKindItem: FC<PropsType> = props => {
|
|||||||
targetColor.length = formatMeterMul(num)
|
targetColor.length = formatMeterMul(num)
|
||||||
}
|
}
|
||||||
const res = await fetchData({
|
const res = await fetchData({
|
||||||
// color_list: [targetColor],
|
|
||||||
// purchaser_id: purchaserId,
|
|
||||||
// sale_mode: itemData.sale_mode,
|
|
||||||
// sale_offset: itemData.sale_offset,
|
|
||||||
id: itemData.id,
|
id: itemData.id,
|
||||||
roll: targetColor.roll,
|
roll: targetColor.roll,
|
||||||
length: targetColor.length,
|
length: targetColor.length,
|
||||||
@ -93,9 +95,11 @@ let ColorKindItem: FC<PropsType> = props => {
|
|||||||
state?.Observer?.notify(purchaserId)
|
state?.Observer?.notify(purchaserId)
|
||||||
}
|
}
|
||||||
}, 460)
|
}, 460)
|
||||||
|
|
||||||
const labAndImgObj = useCallback(item => {
|
const labAndImgObj = useCallback(item => {
|
||||||
return { lab: item.lab, rgb: item.rgb, texture_url: item.product_color_texture_url }
|
return { lab: item.lab, rgb: item.rgb, texture_url: item.product_color_texture_url }
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MCheckbox
|
<MCheckbox
|
||||||
status={state?.multipleSelection?.hasOwnProperty(itemData.id) || false}
|
status={state?.multipleSelection?.hasOwnProperty(itemData.id) || false}
|
||||||
|
@ -11,7 +11,7 @@ import { EnumSaleMode } from '@/common/Enumerate'
|
|||||||
import { selectList } from '../../config'
|
import { selectList } from '../../config'
|
||||||
import { Goods, GoodsMeta, ShoppingDispatchType, ShoppingStateContextValue, useShoppingDispatch, useShoppingState } from '../../context'
|
import { Goods, GoodsMeta, ShoppingDispatchType, ShoppingStateContextValue, useShoppingDispatch, useShoppingState } from '../../context'
|
||||||
import IconFont from '@/components/iconfont/iconfont'
|
import IconFont from '@/components/iconfont/iconfont'
|
||||||
import { isEmptyObject } from '@/common/common'
|
import { alert, isEmptyObject } from '@/common/common'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import LoadingCard from '@/components/loadingCard'
|
import LoadingCard from '@/components/loadingCard'
|
||||||
import { ShoppingCartListApi } from '@/api'
|
import { ShoppingCartListApi } from '@/api'
|
||||||
@ -131,16 +131,17 @@ let ShoppingCartItem: FC<PropsType> = props => {
|
|||||||
|
|
||||||
// 统计已选条数 / 米数
|
// 统计已选条数 / 米数
|
||||||
const lengthOrRollChecked = useMemo(() => {
|
const lengthOrRollChecked = useMemo(() => {
|
||||||
|
console.log('lengthOrRollChecked item',multipleSelection);
|
||||||
if (!multipleSelection || isEmptyObject(multipleSelection)) return 0
|
if (!multipleSelection || isEmptyObject(multipleSelection)) return 0
|
||||||
return (
|
return (
|
||||||
Object.values(multipleSelection).reduce((prev, item: Goods) => {
|
Object.values(multipleSelection).reduce((prev, item: Goods) => {
|
||||||
if (item.sale_mode === selected) {
|
if (selected === EnumSaleMode.Bulk) {
|
||||||
return prev + item.count
|
return prev + item.count
|
||||||
}
|
}
|
||||||
return prev
|
return prev
|
||||||
}, 0) || 0
|
}, 0) || 0
|
||||||
)
|
)
|
||||||
}, [multipleSelection, currentCheckedPurchaserId, selected, itemData])
|
}, [multipleSelection, currentCheckedPurchaserId, selected])
|
||||||
|
|
||||||
const [isPending, startTransition] = useTransition()
|
const [isPending, startTransition] = useTransition()
|
||||||
const { fetchData } = ShoppingCartListApi()
|
const { fetchData } = ShoppingCartListApi()
|
||||||
@ -148,6 +149,7 @@ let ShoppingCartItem: FC<PropsType> = props => {
|
|||||||
// 发布订阅
|
// 发布订阅
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log('update multipleSelection',multipleSelection);
|
||||||
const unsubscribe = state?.Observer?.subscribe(async id => {
|
const unsubscribe = state?.Observer?.subscribe(async id => {
|
||||||
if (itemData?.purchaser_id !== id) return
|
if (itemData?.purchaser_id !== id) return
|
||||||
console.log('request new data start run')
|
console.log('request new data start run')
|
||||||
@ -189,13 +191,15 @@ let ShoppingCartItem: FC<PropsType> = props => {
|
|||||||
product_code: newGoodsKind[id].product_code,
|
product_code: newGoodsKind[id].product_code,
|
||||||
product_color_code: newGoodsKind[id].product_color_code,
|
product_color_code: newGoodsKind[id].product_color_code,
|
||||||
sale_mode: newGoodsKind[id].sale_mode,
|
sale_mode: newGoodsKind[id].sale_mode,
|
||||||
count: selected === EnumSaleMode.Bulk ? newGoodsKind[id].roll : Number(formatMeterDiv(newGoodsKind[id].length)),
|
count: newGoodsKind[id].count,
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
setItemData(() => res.data[0])
|
setItemData(() => res.data[0])
|
||||||
|
}else{
|
||||||
|
alert.error('请求失败')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 取消订阅
|
// 取消订阅
|
||||||
@ -218,7 +222,7 @@ let ShoppingCartItem: FC<PropsType> = props => {
|
|||||||
<View className={styles.summary}>
|
<View className={styles.summary}>
|
||||||
<Text>
|
<Text>
|
||||||
已选 {materialChecked} 种面料,{colorChecked} 个颜色,共{' '}
|
已选 {materialChecked} 种面料,{colorChecked} 个颜色,共{' '}
|
||||||
{selected === EnumSaleMode.Bulk ? `${lengthOrRollChecked} 条` : `${lengthOrRollChecked} 米`}
|
{selected === EnumSaleMode.Bulk ? `${lengthOrRollChecked} 条` : `${formatMeterDiv(lengthOrRollChecked).toLocaleString()} 米`}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
@ -40,6 +40,8 @@ export type Goods = {
|
|||||||
estimate_amount: number // 预估金额
|
estimate_amount: number // 预估金额
|
||||||
count: number // 已选的条数或米数
|
count: number // 已选的条数或米数
|
||||||
sale_mode: EnumSaleMode
|
sale_mode: EnumSaleMode
|
||||||
|
roll?: number
|
||||||
|
length?: number
|
||||||
}
|
}
|
||||||
// 分组
|
// 分组
|
||||||
export interface GoodsMeta {
|
export interface GoodsMeta {
|
||||||
|
@ -259,30 +259,5 @@ const ShoppingCartContainer: FC<InternalContainer> = () => {
|
|||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// interface ScrollListPropType {
|
|
||||||
// height: string
|
|
||||||
// }
|
|
||||||
// const ScrollList = memo<ScrollListPropType>((props) => {
|
|
||||||
// const { height } = props
|
|
||||||
// const [shoppingCartData, setShoppingCartData] = useState<{ list: ShoppingCartData[]; total: number }>({ list: [], total: 0 })
|
|
||||||
|
|
||||||
// //数据加载状态
|
|
||||||
// const statusMore = useMemo(() => {
|
|
||||||
// return dataLoadingStatus({ list: shoppingCartData.list, total: shoppingCartData.total, status: state.loading })
|
|
||||||
// }, [shoppingCartData, state])
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <View className={classnames('flex-item', 'flex-col', styles['shopping--context'])}>
|
|
||||||
// <View className={classnames(styles.shopping__list__container, 'flex-item')} style={{ height: height }}>
|
|
||||||
// <InfiniteScroll statusMore={statusMore} refresherEnabled={true} selfOnRefresherRefresh={handleRefresh} refresherTriggered={refreshStatus}>
|
|
||||||
// {!!shoppingCartData?.list?.length &&
|
|
||||||
// shoppingCartData?.list?.map((item, index) => {
|
|
||||||
// return <ItemList itemData={item} key={index}></ItemList>
|
|
||||||
// })}
|
|
||||||
// </InfiniteScroll>
|
|
||||||
// </View>
|
|
||||||
// </View>
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
|
|
||||||
export default Shopping
|
export default Shopping
|
||||||
|
Loading…
x
Reference in New Issue
Block a user