修复sku选择bug
parent
37a7089aa9
commit
0e7ad5270f
|
|
@ -19,15 +19,6 @@ import { useAsyncCallback } from '@/hooks'
|
|||
import { classNames, showToast } from '@/utils'
|
||||
import './index.scss'
|
||||
|
||||
// 数据类型
|
||||
// interface ISkuItem: {
|
||||
// specName: string
|
||||
// specId: string
|
||||
// }
|
||||
// skuList: ISkuItem[]
|
||||
|
||||
// specItems
|
||||
|
||||
const initialState = {
|
||||
curImage: null,
|
||||
selection: [],
|
||||
|
|
@ -35,7 +26,8 @@ const initialState = {
|
|||
curItem: null,
|
||||
skuText: '',
|
||||
num: 1,
|
||||
loading: false
|
||||
loading: false,
|
||||
isClickSku: false
|
||||
}
|
||||
|
||||
function SpSkuSelect (props, ref) {
|
||||
|
|
@ -51,7 +43,7 @@ function SpSkuSelect (props, ref) {
|
|||
// console.log('SpSkuSelect:info', info)
|
||||
// const [state, setState] = useImmer(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 skuDictRef = useRef({})
|
||||
|
||||
|
|
@ -68,7 +60,7 @@ function SpSkuSelect (props, ref) {
|
|||
skuDictRef.current[key] = item
|
||||
if (item.store > 0) {
|
||||
} 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
|
||||
|
|
@ -105,10 +97,12 @@ function SpSkuSelect (props, ref) {
|
|||
|
||||
for (let i = 0, l = skuList.length; i < l; i++) {
|
||||
const { skuValue } = skuList[i]
|
||||
for (let j = 0, k = skuValue.length; j < k; j++) {
|
||||
const id = skuValue[j].specId
|
||||
if (!disabledSet.has(id) && !isNotDisabled(selection, i, id)) {
|
||||
disabledSet.add(id)
|
||||
if (i === 2) {
|
||||
for (let j = 0, k = skuValue.length; j < k; j++) {
|
||||
const id = skuValue[j].specId
|
||||
if (!disabledSet.has(id) && !isNotDisabled(selection, i, id)) {
|
||||
disabledSet.add(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -125,7 +119,7 @@ function SpSkuSelect (props, ref) {
|
|||
// const skuText = curItem
|
||||
// ? `已选:${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(' ')}码`
|
||||
: '请选择规格'
|
||||
|
||||
|
|
@ -143,13 +137,19 @@ function SpSkuSelect (props, ref) {
|
|||
|
||||
// console.log('disabledSet:', disabledSet)
|
||||
|
||||
const handleSelectSku = ({ specId }, idx) => {
|
||||
// console.log("🚀 ~ { specId }, idx:", specId, idx)
|
||||
const handleSelectSku = (spec, idx) => {
|
||||
const { specId } = spec
|
||||
const _selection = [...selection]
|
||||
|
||||
_selection[idx] = specId
|
||||
const key = _selection.join('_')
|
||||
const row = skuDictRef.current[key] || {}
|
||||
if (disabledSet.has(specId)) return
|
||||
setState(
|
||||
(draft) => {
|
||||
draft.selection[idx] = selection[idx] == specId ? specId : specId //null
|
||||
draft.selection[idx] = specId //null
|
||||
draft.curImage = 1
|
||||
draft.isClickSku = idx === 2 || row.store > 0
|
||||
},
|
||||
(row) => {
|
||||
calcDisabled(row.selection, idx)
|
||||
|
|
@ -166,7 +166,6 @@ function SpSkuSelect (props, ref) {
|
|||
}
|
||||
}
|
||||
onChangeImg && onChangeImg(img)
|
||||
// console.log('img:', img)
|
||||
return img
|
||||
}
|
||||
|
||||
|
|
@ -213,7 +212,7 @@ function SpSkuSelect (props, ref) {
|
|||
|
||||
const fastBuy = async () => {
|
||||
const { nospec } = info
|
||||
if (!nospec && !curItem) {
|
||||
if ((!nospec && !curItem) || !isClickSku) {
|
||||
showToast('请选择规格')
|
||||
return
|
||||
}
|
||||
|
|
@ -398,12 +397,12 @@ function SpSkuSelect (props, ref) {
|
|||
)
|
||||
)}
|
||||
</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', {
|
||||
'active': spec.specId == selection[index],
|
||||
'btn-primary': spec.specId == selection[index],
|
||||
'active': spec.specId == selection[index] && isClickSku,
|
||||
'btn-primary': index !== 2 ? spec.specId == selection[index] : spec.specId == selection[index] && isClickSku,
|
||||
'disabled': disabledSet.has(spec.specId),
|
||||
'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>}
|
||||
</>
|
||||
))}
|
||||
)) : <View className="spec-name">暂无库存</View>)}
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ const CompSeries = (props) => {
|
|||
const [activeIndex, setActiveIndex] = useState(0)
|
||||
const [showChild, setShowChild] = useState(false)
|
||||
const [selChild, setSelChild] = useState({})
|
||||
const { windowWidth } = Taro.getSystemInfoSync()
|
||||
|
||||
const { info, pluralType = true, imgType = true } = props
|
||||
|
||||
|
|
@ -64,12 +65,12 @@ const CompSeries = (props) => {
|
|||
<View className='group-box'>
|
||||
{/* handleCustomClick(item.category_id) */}
|
||||
<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>
|
||||
</View>
|
||||
<SpImage
|
||||
className={classNames(imgType ? 'cat-img' : 'cat-img-no')}
|
||||
mode='aspectFill'
|
||||
mode='aspectFit'
|
||||
height={350}
|
||||
src={item.img}
|
||||
/>
|
||||
|
|
@ -159,8 +160,8 @@ const CompSeries = (props) => {
|
|||
</View>
|
||||
<SpImage
|
||||
className={classNames(imgType ? 'cat-img' : 'cat-img-no')}
|
||||
mode='aspectFill'
|
||||
height={350}
|
||||
mode='aspectFit'
|
||||
height={windowWidth > 400 ? 276 : 240}
|
||||
src={item.img}
|
||||
/>
|
||||
</View> : <View
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@
|
|||
transform: translateX(-50%);
|
||||
border-bottom: 2px solid #fff;
|
||||
font-size: 26px;
|
||||
z-index: 1;
|
||||
// padding: 20px 0;
|
||||
// font-weight: bold;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -731,7 +731,7 @@ export default class RecommendList extends Component {
|
|||
loop={false}
|
||||
// muted={true}
|
||||
showProgress={true}
|
||||
showFullscreenBtn={true}
|
||||
showFullscreenBtn={false}
|
||||
showPlayBtn={true}
|
||||
showCenterPlayBtn={false}
|
||||
enableProgressGesture={true}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ export default class TradeList extends Component {
|
|||
total = 0,
|
||||
rate_status = false
|
||||
if (params.status === '---') {
|
||||
params.aftersales_status = 0
|
||||
// params.aftersales_status = 0
|
||||
const { list: _list, total_count: _total } = await api.aftersales.list(params)
|
||||
list = _list
|
||||
total = _total
|
||||
|
|
|
|||
Loading…
Reference in New Issue