修复sku选择bug

main
王文龙 2024-02-27 14:19:43 +08:00
parent 37a7089aa9
commit 0e7ad5270f
5 changed files with 34 additions and 33 deletions

View File

@ -19,15 +19,6 @@ import { useAsyncCallback } from '@/hooks'
import { classNames, showToast } from '@/utils' import { classNames, showToast } from '@/utils'
import './index.scss' import './index.scss'
// 数据类型
// interface ISkuItem: {
// specName: string
// specId: string
// }
// skuList: ISkuItem[]
// specItems
const initialState = { const initialState = {
curImage: null, curImage: null,
selection: [], selection: [],
@ -35,7 +26,8 @@ const initialState = {
curItem: null, curItem: null,
skuText: '', skuText: '',
num: 1, num: 1,
loading: false loading: false,
isClickSku: false
} }
function SpSkuSelect (props, ref) { function SpSkuSelect (props, ref) {
@ -51,7 +43,7 @@ function SpSkuSelect (props, ref) {
// console.log('SpSkuSelect:info', info) // console.log('SpSkuSelect:info', info)
// const [state, setState] = useImmer(initialState) // const [state, setState] = useImmer(initialState)
const [state, setState] = useAsyncCallback(initialState) const [state, setState] = useAsyncCallback(initialState)
const { selection, curImage, disabledSet, curItem, skuText, num, loading } = state const { selection, curImage, disabledSet, curItem, skuText, num, loading, isClickSku } = state
const dispatch = useDispatch() const dispatch = useDispatch()
const skuDictRef = useRef({}) const skuDictRef = useRef({})
@ -68,7 +60,7 @@ function SpSkuSelect (props, ref) {
skuDictRef.current[key] = item skuDictRef.current[key] = item
if (item.store > 0) { if (item.store > 0) {
} else { } else {
console.log("🚀 ~ item库存为0:", key, item.specItem.map((item) => item.specName).join('_')) // console.log("🚀 ~ item库存为0:", key, item.specItem.map((item) => item.specName).join('_'))
} }
}) })
// 默认选中有库存并且前端可销售的sku // 默认选中有库存并且前端可销售的sku
@ -105,10 +97,12 @@ function SpSkuSelect (props, ref) {
for (let i = 0, l = skuList.length; i < l; i++) { for (let i = 0, l = skuList.length; i < l; i++) {
const { skuValue } = skuList[i] const { skuValue } = skuList[i]
for (let j = 0, k = skuValue.length; j < k; j++) { if (i === 2) {
const id = skuValue[j].specId for (let j = 0, k = skuValue.length; j < k; j++) {
if (!disabledSet.has(id) && !isNotDisabled(selection, i, id)) { const id = skuValue[j].specId
disabledSet.add(id) if (!disabledSet.has(id) && !isNotDisabled(selection, i, id)) {
disabledSet.add(id)
}
} }
} }
} }
@ -125,7 +119,7 @@ function SpSkuSelect (props, ref) {
// const skuText = curItem // const skuText = curItem
// ? `已选:${curItem.specItem.map((item) => `${item.skuName}:${item.specName}`).join(',')}` // ? `已选:${curItem.specItem.map((item) => `${item.skuName}:${item.specName}`).join(',')}`
// : '请选择规格' // : '请选择规格'
const skuText = curItem const skuText = curItem?.store > 0
? `已选择 ${curItem.specItem.map((item, index) => `${index === 1 ? item.specName.substr(0, 2) : item.specName}`).join(' ')}` ? `已选择 ${curItem.specItem.map((item, index) => `${index === 1 ? item.specName.substr(0, 2) : item.specName}`).join(' ')}`
: '请选择规格' : '请选择规格'
@ -143,13 +137,19 @@ function SpSkuSelect (props, ref) {
// console.log('disabledSet:', disabledSet) // console.log('disabledSet:', disabledSet)
const handleSelectSku = ({ specId }, idx) => { const handleSelectSku = (spec, idx) => {
// console.log("🚀 ~ { specId }, idx:", specId, idx) const { specId } = spec
const _selection = [...selection]
_selection[idx] = specId
const key = _selection.join('_')
const row = skuDictRef.current[key] || {}
if (disabledSet.has(specId)) return if (disabledSet.has(specId)) return
setState( setState(
(draft) => { (draft) => {
draft.selection[idx] = selection[idx] == specId ? specId : specId //null draft.selection[idx] = specId //null
draft.curImage = 1 draft.curImage = 1
draft.isClickSku = idx === 2 || row.store > 0
}, },
(row) => { (row) => {
calcDisabled(row.selection, idx) calcDisabled(row.selection, idx)
@ -166,7 +166,6 @@ function SpSkuSelect (props, ref) {
} }
} }
onChangeImg && onChangeImg(img) onChangeImg && onChangeImg(img)
// console.log('img:', img)
return img return img
} }
@ -213,7 +212,7 @@ function SpSkuSelect (props, ref) {
const fastBuy = async () => { const fastBuy = async () => {
const { nospec } = info const { nospec } = info
if (!nospec && !curItem) { if ((!nospec && !curItem) || !isClickSku) {
showToast('请选择规格') showToast('请选择规格')
return return
} }
@ -398,12 +397,12 @@ function SpSkuSelect (props, ref) {
) )
)} )}
</ScrollView>} </ScrollView>}
{index > 0 && item.skuValue.map((spec, idx) => ( {index > 0 && (item.skuValue.length > 0 ? item.skuValue.map((spec, idx) => (
<> <>
{!disabledSet.has(spec.specId) && <View {index === 2 && disabledSet.has(spec.specId) ? null : <View
className={classNames('sku-btn btn-noac', { className={classNames('sku-btn btn-noac', {
'active': spec.specId == selection[index], 'active': spec.specId == selection[index] && isClickSku,
'btn-primary': spec.specId == selection[index], 'btn-primary': index !== 2 ? spec.specId == selection[index] : spec.specId == selection[index] && isClickSku,
'disabled': disabledSet.has(spec.specId), 'disabled': disabledSet.has(spec.specId),
'sku-img': spec.specImgs.length > 0 'sku-img': spec.specImgs.length > 0
})} })}
@ -416,7 +415,7 @@ function SpSkuSelect (props, ref) {
<View className={classNames('spec-name', { 'pad': index === 2 })}>{spec.specName}</View> <View className={classNames('spec-name', { 'pad': index === 2 })}>{spec.specName}</View>
</View>} </View>}
</> </>
))} )) : <View className="spec-name">暂无库存</View>)}
</View> </View>
</View> </View>
))} ))}

View File

@ -10,6 +10,7 @@ const CompSeries = (props) => {
const [activeIndex, setActiveIndex] = useState(0) const [activeIndex, setActiveIndex] = useState(0)
const [showChild, setShowChild] = useState(false) const [showChild, setShowChild] = useState(false)
const [selChild, setSelChild] = useState({}) const [selChild, setSelChild] = useState({})
const { windowWidth } = Taro.getSystemInfoSync()
const { info, pluralType = true, imgType = true } = props const { info, pluralType = true, imgType = true } = props
@ -64,12 +65,12 @@ const CompSeries = (props) => {
<View className='group-box'> <View className='group-box'>
{/* handleCustomClick(item.category_id) */} {/* handleCustomClick(item.category_id) */}
<View className='group' key={item.category_id} onClick={() => handleClickItem(item)}> <View className='group' key={item.category_id} onClick={() => handleClickItem(item)}>
<View className='group-title'>探索全部 <View className='group-title'>{item.name}
<Text className='iconfont icon-qianwang-01' style={{ fontSize: 'inherit', marginLeft: '4px' }}></Text> <Text className='iconfont icon-qianwang-01' style={{ fontSize: 'inherit', marginLeft: '4px' }}></Text>
</View> </View>
<SpImage <SpImage
className={classNames(imgType ? 'cat-img' : 'cat-img-no')} className={classNames(imgType ? 'cat-img' : 'cat-img-no')}
mode='aspectFill' mode='aspectFit'
height={350} height={350}
src={item.img} src={item.img}
/> />
@ -159,8 +160,8 @@ const CompSeries = (props) => {
</View> </View>
<SpImage <SpImage
className={classNames(imgType ? 'cat-img' : 'cat-img-no')} className={classNames(imgType ? 'cat-img' : 'cat-img-no')}
mode='aspectFill' mode='aspectFit'
height={350} height={windowWidth > 400 ? 276 : 240}
src={item.img} src={item.img}
/> />
</View> : <View </View> : <View

View File

@ -115,6 +115,7 @@
transform: translateX(-50%); transform: translateX(-50%);
border-bottom: 2px solid #fff; border-bottom: 2px solid #fff;
font-size: 26px; font-size: 26px;
z-index: 1;
// padding: 20px 0; // padding: 20px 0;
// font-weight: bold; // font-weight: bold;
} }

View File

@ -731,7 +731,7 @@ export default class RecommendList extends Component {
loop={false} loop={false}
// muted={true} // muted={true}
showProgress={true} showProgress={true}
showFullscreenBtn={true} showFullscreenBtn={false}
showPlayBtn={true} showPlayBtn={true}
showCenterPlayBtn={false} showCenterPlayBtn={false}
enableProgressGesture={true} enableProgressGesture={true}

View File

@ -147,7 +147,7 @@ export default class TradeList extends Component {
total = 0, total = 0,
rate_status = false rate_status = false
if (params.status === '---') { if (params.status === '---') {
params.aftersales_status = 0 // params.aftersales_status = 0
const { list: _list, total_count: _total } = await api.aftersales.list(params) const { list: _list, total_count: _total } = await api.aftersales.list(params)
list = _list list = _list
total = _total total = _total