✨ feat(ID1001140购物车的面料减少到0的时候提示删除该商品):
This commit is contained in:
parent
d37b82698f
commit
c4917e540f
@ -159,7 +159,6 @@ const CounterDisplayName = (props: params) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
const Counter = memo(CounterDisplayName)
|
const Counter = memo(CounterDisplayName)
|
||||||
const CounterWithMemo = (props: params) => {
|
export default (props: params) => {
|
||||||
return <Counter {...props}></Counter>
|
return <Counter {...props}></Counter>
|
||||||
}
|
}
|
||||||
export default memo(CounterWithMemo)
|
|
||||||
|
|||||||
@ -57,13 +57,14 @@ export interface StateType {
|
|||||||
sale_mode?: saleModeType
|
sale_mode?: saleModeType
|
||||||
checkList?: { [key in number]: boolean }
|
checkList?: { [key in number]: boolean }
|
||||||
recommendId?: number
|
recommendId?: number
|
||||||
|
delCommendId?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActionsMap {
|
export interface ActionsMap {
|
||||||
setInitData: StateType
|
setInitData: StateType
|
||||||
updateProduct: StateType
|
updateProduct: StateType
|
||||||
setRecommendId: StateType
|
setRecommendId: StateType
|
||||||
|
setDelCommendId: StateType
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Actions = {
|
export type Actions = {
|
||||||
@ -95,7 +96,7 @@ export default (props: PropsType) => {
|
|||||||
price_number: 0,
|
price_number: 0,
|
||||||
},
|
},
|
||||||
recommendId: 0,
|
recommendId: 0,
|
||||||
|
delCommendId: 0,
|
||||||
}
|
}
|
||||||
function reducer(state: StateType, action: Actions) {
|
function reducer(state: StateType, action: Actions) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@ -105,6 +106,8 @@ export default (props: PropsType) => {
|
|||||||
return onUpdateData(state, action)
|
return onUpdateData(state, action)
|
||||||
case 'setRecommendId':
|
case 'setRecommendId':
|
||||||
return { ...state, recommendId: action.data.recommendId }
|
return { ...state, recommendId: action.data.recommendId }
|
||||||
|
case 'setDelCommendId':
|
||||||
|
return { ...state, delCommendId: action.data.delCommendId }
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
@ -127,7 +130,7 @@ const onInitData = (state: StateType, action: Actions) => {
|
|||||||
citem.checked = false
|
citem.checked = false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return { ...state, list: data.list, sale_mode: data.sale_mode, recommendId: data.recommendId, statistics }
|
return { ...state, list: data.list, sale_mode: data.sale_mode, recommendId: 0, statistics, delCommendId: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新数据
|
// 更新数据
|
||||||
|
|||||||
@ -44,7 +44,7 @@ export default memo((props: ParamType) => {
|
|||||||
...res.data,
|
...res.data,
|
||||||
sale_mode_type: filter.sale_mode,
|
sale_mode_type: filter.sale_mode,
|
||||||
}
|
}
|
||||||
onSubmitData(res.data.defaultNum, res.data.screw_color_id)
|
onSubmitData(SALE_MODE_SETTING[filter.sale_mode].defaultNum, res.data.screw_color_id)
|
||||||
setProductData(res.data)
|
setProductData(res.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,6 +69,7 @@ export default memo((props: ParamType) => {
|
|||||||
// 整理提交数据
|
// 整理提交数据
|
||||||
const onSubmitData = (num = 0, product_color_id = 0) => {
|
const onSubmitData = (num = 0, product_color_id = 0) => {
|
||||||
const data = { product_color_id, length: 0, roll: 0 }
|
const data = { product_color_id, length: 0, roll: 0 }
|
||||||
|
console.log('num::::', num)
|
||||||
if (filter.sale_mode === 0) {
|
if (filter.sale_mode === 0) {
|
||||||
data.roll = num
|
data.roll = num
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ export default () => {
|
|||||||
const res = await getShoppingCartFetchData(filter)
|
const res = await getShoppingCartFetchData(filter)
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
dispatch({ type: 'setInitData', data: { list: JSON.parse(JSON.stringify(res?.data?.product_list)), sale_mode: filter.sale_mode, recommendId: 0 } })
|
dispatch({ type: 'setInitData', data: { list: JSON.parse(JSON.stringify(res?.data?.product_list)), sale_mode: filter.sale_mode } })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,6 +216,14 @@ export default () => {
|
|||||||
getShoppingCart()
|
getShoppingCart()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
// 当减到0时删除商品
|
||||||
|
useEffect(() => {
|
||||||
|
if (state.delCommendId) {
|
||||||
|
getShoppingCart()
|
||||||
|
getProductColorNum()
|
||||||
|
}
|
||||||
|
}, [state.delCommendId])
|
||||||
|
|
||||||
return <View className={styles.shop_main}>
|
return <View className={styles.shop_main}>
|
||||||
<View className={styles.shop_header}>
|
<View className={styles.shop_header}>
|
||||||
<Operation onSelect={onSortChange} onChange={onChangeSetting} />
|
<Operation onSelect={onSortChange} onChange={onChangeSetting} />
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { CustomWrapper, Text, View } from '@tarojs/components'
|
import { CustomWrapper, Text, View } from '@tarojs/components'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import { memo, useCallback, useEffect, useMemo } from 'react'
|
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import Big from 'big.js'
|
import Big from 'big.js'
|
||||||
import ColorCheckbox from '../colorCheckbox'
|
import ColorCheckbox from '../colorCheckbox'
|
||||||
import RecommendProduct from '../recommendProduct'
|
import RecommendProduct from '../recommendProduct'
|
||||||
@ -10,7 +10,7 @@ import Counter from '@/components/counter'
|
|||||||
import type { ColorType } from '@/context/ContextShop'
|
import type { ColorType } from '@/context/ContextShop'
|
||||||
import { useCurrenShop } from '@/context/ContextShop'
|
import { useCurrenShop } from '@/context/ContextShop'
|
||||||
import { formatPriceDiv } from '@/common/fotmat'
|
import { formatPriceDiv } from '@/common/fotmat'
|
||||||
import { GetShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart'
|
import { DelShoppingCartApi, GetShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart'
|
||||||
import { debounce } from '@/common/util'
|
import { debounce } from '@/common/util'
|
||||||
import { SALE_MODE_SETTING } from '@/common/enum'
|
import { SALE_MODE_SETTING } from '@/common/enum'
|
||||||
|
|
||||||
@ -27,16 +27,37 @@ type IndexItemType = {
|
|||||||
export default memo((props: ColorItemType) => {
|
export default memo((props: ColorItemType) => {
|
||||||
const { fetchData: updateShoppingCartFetchData } = UpdateShoppingCartApi()
|
const { fetchData: updateShoppingCartFetchData } = UpdateShoppingCartApi()
|
||||||
const { fetchData: getShoppingCartFetchData } = GetShoppingCartApi()
|
const { fetchData: getShoppingCartFetchData } = GetShoppingCartApi()
|
||||||
|
const { fetchData: delShopFetchData } = DelShoppingCartApi()
|
||||||
const { colorItem } = props
|
const { colorItem } = props
|
||||||
const { state, dispatch } = useCurrenShop()
|
const { state, dispatch } = useCurrenShop()
|
||||||
const indexs = colorItem.index_str.split(',')
|
const indexs = colorItem.index_str.split(',')
|
||||||
const colorItemNew: ColorType = state.list[indexs[0]].color_list[indexs[1]]
|
const colorItemNew: ColorType = state.list[indexs[0]].color_list[indexs[1]]
|
||||||
const onChangeNum = useCallback(async(val) => {
|
const onChangeNum = useCallback(async(val) => {
|
||||||
await updateShoppingCartFetchData(val)
|
if (val.roll == 0 && val.length == 0) {
|
||||||
const res = await getShoppingCartFetchData({ id: colorItem.id })
|
Taro.showModal({
|
||||||
if (res.success) {
|
content: '确定删除该商品?',
|
||||||
state.list[indexs[0]].color_list[indexs[1]] = { ...state.list[indexs[0]].color_list[indexs[1]], ...res.data.color_list[0] }
|
confirmText: '删除',
|
||||||
dispatch({ type: 'updateProduct', data: { list: state.list } })
|
async success(res) {
|
||||||
|
if (res.confirm) {
|
||||||
|
const res = await delShopFetchData({ id: [colorItemNew.id] })
|
||||||
|
if (res.success) {
|
||||||
|
dispatch({ type: 'setDelCommendId', data: { list: state.list, delCommendId: colorItemNew.id } })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (res.cancel) {
|
||||||
|
state.list[indexs[0]].color_list[indexs[1]] = { ...state.list[indexs[0]].color_list[indexs[1]] }
|
||||||
|
dispatch({ type: 'updateProduct', data: { list: state.list } })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await updateShoppingCartFetchData(val)
|
||||||
|
const res = await getShoppingCartFetchData({ id: colorItem.id })
|
||||||
|
if (res.success) {
|
||||||
|
state.list[indexs[0]].color_list[indexs[1]] = { ...state.list[indexs[0]].color_list[indexs[1]], ...res.data.color_list[0] }
|
||||||
|
dispatch({ type: 'updateProduct', data: { list: state.list } })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [colorItemNew])
|
}, [colorItemNew])
|
||||||
|
|
||||||
@ -51,7 +72,12 @@ const Index = memo((props: IndexItemType) => {
|
|||||||
const rga = useMemo(() => {
|
const rga = useMemo(() => {
|
||||||
return { lab: colorItem.lab, rgb: colorItem.rgb, texture_url: colorItem.texture_url, title: colorItem.product_color_code }
|
return { lab: colorItem.lab, rgb: colorItem.rgb, texture_url: colorItem.texture_url, title: colorItem.product_color_code }
|
||||||
}, [colorItem])
|
}, [colorItem])
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
useEffect(() => {
|
||||||
|
setCount(() => colorItem.sale_mode === 0 ? colorItem.roll : colorItem.length / 100)
|
||||||
|
}, [colorItem])
|
||||||
const getCount = debounce(async(num) => {
|
const getCount = debounce(async(num) => {
|
||||||
|
setCount(num)
|
||||||
const data = { id: colorItem.id, length: 0, roll: 0 }
|
const data = { id: colorItem.id, length: 0, roll: 0 }
|
||||||
if (colorItem.sale_mode === 0) {
|
if (colorItem.sale_mode === 0) {
|
||||||
data.roll = num
|
data.roll = num
|
||||||
@ -98,9 +124,10 @@ const Index = memo((props: IndexItemType) => {
|
|||||||
minNum={saleSetting.minNum}
|
minNum={saleSetting.minNum}
|
||||||
maxNum={saleSetting.maxNum}
|
maxNum={saleSetting.maxNum}
|
||||||
onBlue={getCount}
|
onBlue={getCount}
|
||||||
defaultNum={colorItem.sale_mode === 0 ? colorItem.roll : colorItem.length / 100}
|
defaultNum={count}
|
||||||
unit={colorItem.sale_mode === 0 ? '条' : '米'}
|
unit={colorItem.sale_mode === 0 ? '条' : '米'}
|
||||||
digits={saleSetting.digits}
|
digits={saleSetting.digits}
|
||||||
|
returnZero
|
||||||
/>
|
/>
|
||||||
</CustomWrapper>
|
</CustomWrapper>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user