提交 969ff207 作者: 翁进城

fix: 【产品商城】详情中副图、视频未显示,规格数未显示正确的数字

上级 736a88b0
...@@ -13,7 +13,7 @@ import { Navigation } from "swiper"; ...@@ -13,7 +13,7 @@ import { Navigation } from "swiper";
// Import Swiper styles // Import Swiper styles
import "swiper/css"; import "swiper/css";
import "swiper/css/navigation"; import "swiper/css/navigation";
import api, { GetLeaseGoodsDetailResp } from "./api"; import api, { GetLeaseGoodsDetailResp, ProductSpecList } from "./api";
import IntentionModal from "./components/intentionModal"; import IntentionModal from "./components/intentionModal";
import { UserContext } from "~/lib/userProvider"; import { UserContext } from "~/lib/userProvider";
...@@ -22,11 +22,25 @@ export default function MallDetail() { ...@@ -22,11 +22,25 @@ export default function MallDetail() {
const [visible, setVisible] = useState(false); //商品图预览 const [visible, setVisible] = useState(false); //商品图预览
const router = useRouter(); const router = useRouter();
const [id, setId] = useState<number | null>(null); const [id, setId] = useState<number | null>(null);
const [detail, setDetail] = useState<GetLeaseGoodsDetailResp | null>( const [detail, setDetail] = useState<GetLeaseGoodsDetailResp | null>(null); //详情数据
null
); //详情数据
const [intentionModalOpen, setIntentionModalOpen] = useState(false); //意向弹窗 const [intentionModalOpen, setIntentionModalOpen] = useState(false); //意向弹窗
const [productImg, setProductImg] = useState(''); //展示的商品图 const [productImg, setProductImg] = useState(""); //展示的商品图
const [previewIndex, setPreviewIndex] = useState(0); //预览开始索引
const [checkItems, setCheckItems] = useState<ProductSpecList[]>([]); //选中的规格
const [specCount, setSpecCount] = useState(0); //规格数量
useEffect(() => {
if(detail){
let count = 0;
detail.goodsSpec?.forEach(good => {
good.productSpecList?.forEach(product => {
count++;
})
})
setSpecCount(count);
}
}, [detail])
//打开意向modal //打开意向modal
const openIntentionModal = () => { const openIntentionModal = () => {
...@@ -55,7 +69,7 @@ export default function MallDetail() { ...@@ -55,7 +69,7 @@ export default function MallDetail() {
api api
.getLeaseGoodsDetail({ .getLeaseGoodsDetail({
goodsId: id, goodsId: id,
type: 0 type: 0,
}) })
.then((res) => { .then((res) => {
setDetail(res.result || null); setDetail(res.result || null);
...@@ -72,11 +86,12 @@ export default function MallDetail() { ...@@ -72,11 +86,12 @@ export default function MallDetail() {
detail={detail} detail={detail}
onOk={handleIntentionOk} onOk={handleIntentionOk}
onCancel={handleIntentionCancel} onCancel={handleIntentionCancel}
onChange={(items: ProductSpecList[]) => setCheckItems(items)}
></IntentionModal> ></IntentionModal>
<div className="page" style={{ marginTop: 20, backgroundColor: "#fff" }}> <div className="page" style={{ marginTop: 20, backgroundColor: "#fff" }}>
<div style={{ display: "none" }}> <div style={{ display: "none" }}>
<AImage.PreviewGroup <AImage.PreviewGroup
preview={{ visible, onVisibleChange: (vis) => setVisible(vis) }} preview={{ visible, onVisibleChange: (vis) => setVisible(vis), current: previewIndex }}
> >
{detail?.images?.map((item) => { {detail?.images?.map((item) => {
return <AImage key={item.id} src={item.imgUrl} />; return <AImage key={item.id} src={item.imgUrl} />;
...@@ -107,7 +122,7 @@ export default function MallDetail() { ...@@ -107,7 +122,7 @@ export default function MallDetail() {
onSlideChange={() => console.log("slide change")} onSlideChange={() => console.log("slide change")}
onSwiper={(swiper) => console.log(swiper)} onSwiper={(swiper) => console.log(swiper)}
> >
{detail?.images?.map((item) => { {detail?.images?.map((item, i) => {
return ( return (
<SwiperSlide key={item.id}> <SwiperSlide key={item.id}>
<AImage <AImage
...@@ -117,7 +132,7 @@ export default function MallDetail() { ...@@ -117,7 +132,7 @@ export default function MallDetail() {
src={item.imgUrl} src={item.imgUrl}
fallback={errImg} fallback={errImg}
style={{ cursor: "pointer" }} style={{ cursor: "pointer" }}
onClick={() => setProductImg(item.imgUrl)} onClick={() => {setProductImg(item.imgUrl), setPreviewIndex(i)}}
/> />
</SwiperSlide> </SwiperSlide>
); );
...@@ -147,14 +162,14 @@ export default function MallDetail() { ...@@ -147,14 +162,14 @@ export default function MallDetail() {
选择 选择
</Col> </Col>
<Col flex="auto" className={styles.font4} style={{}}> <Col flex="auto" className={styles.font4} style={{}}>
已选:1 已选:{checkItems.length}
</Col> </Col>
</Row> </Row>
</Col> </Col>
<Col> <Col>
<Row align="middle" style={{ cursor: "pointer" }}> <Row align="middle" style={{ cursor: "pointer" }}>
<Col className={styles.font4} onClick={openIntentionModal}> <Col className={styles.font4} onClick={openIntentionModal}>
3种可选 {specCount}种可选
</Col> </Col>
<Col style={{ marginLeft: 9 }}> <Col style={{ marginLeft: 9 }}>
<DownOutlined <DownOutlined
......
...@@ -11,6 +11,7 @@ type Props = { ...@@ -11,6 +11,7 @@ type Props = {
onOk?: () => void; onOk?: () => void;
onCancel: () => void; onCancel: () => void;
detail: GetLeaseGoodsDetailResp | null; detail: GetLeaseGoodsDetailResp | null;
onChange?: (checkItems: ProductSpecList[]) => void;
}; };
export default function IntentionModal(props: Props) { export default function IntentionModal(props: Props) {
const [checkedMap, setCheckedMap] = useState<{ string?: boolean }>({}); //通过索引记录选中的产品规格 例: {'1,1': true|false} props.detail?.goodsSpec[1].productSpecList[1] const [checkedMap, setCheckedMap] = useState<{ string?: boolean }>({}); //通过索引记录选中的产品规格 例: {'1,1': true|false} props.detail?.goodsSpec[1].productSpecList[1]
...@@ -32,6 +33,7 @@ export default function IntentionModal(props: Props) { ...@@ -32,6 +33,7 @@ export default function IntentionModal(props: Props) {
} }
}); });
setCheckItems(list); setCheckItems(list);
props.onChange && props.onChange(list);
}, [checkedMap]); }, [checkedMap]);
//添加规格到购物车 //添加规格到购物车
...@@ -117,6 +119,7 @@ export default function IntentionModal(props: Props) { ...@@ -117,6 +119,7 @@ export default function IntentionModal(props: Props) {
style={{ width: "100%", height: 44 }} style={{ width: "100%", height: 44 }}
onClick={onSubmit} onClick={onSubmit}
loading={loading} loading={loading}
disabled={checkItems.length == 0}
> >
提交意向 提交意向
</Button> </Button>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论