diff --git a/src/components/sp-sku-select-new/index.js b/src/components/sp-sku-select-new/index.js index b2d826b..bde0d7c 100755 --- a/src/components/sp-sku-select-new/index.js +++ b/src/components/sp-sku-select-new/index.js @@ -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) { ) )} } - {index > 0 && item.skuValue.map((spec, idx) => ( + {index > 0 && (item.skuValue.length > 0 ? item.skuValue.map((spec, idx) => ( <> - {!disabledSet.has(spec.specId) && 0 })} @@ -416,7 +415,7 @@ function SpSkuSelect (props, ref) { {spec.specName} } - ))} + )) : 暂无库存)} ))} diff --git a/src/pages/category/comps/comp-series.js b/src/pages/category/comps/comp-series.js index 56db8b2..d129f6a 100755 --- a/src/pages/category/comps/comp-series.js +++ b/src/pages/category/comps/comp-series.js @@ -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) => { {/* handleCustomClick(item.category_id) */} handleClickItem(item)}> - 探索全部 + {item.name} @@ -159,8 +160,8 @@ const CompSeries = (props) => { 400 ? 276 : 240} src={item.img} /> :