提交 32e4472f 作者: 翁进城

商品详情规格内容对接

上级 72820481
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import Layout from "~/components/layout"; import Layout from "~/components/layout";
import { Space, Image as AImage, Row, Col, Button, Divider, Badge } from "antd"; import { Space, Image as AImage, Row, Col, Button, Divider, Badge } from "antd";
import { useEffect, useState } from "react"; import { useContext, useEffect, useState } from "react";
import { DownOutlined, RightOutlined } from "@ant-design/icons"; import { DownOutlined, RightOutlined } from "@ant-design/icons";
import Image from "next/image"; import Image from "next/image";
import errImg from "~/assets/errImg"; import errImg from "~/assets/errImg";
...@@ -15,16 +15,28 @@ import "swiper/css"; ...@@ -15,16 +15,28 @@ import "swiper/css";
import "swiper/css/navigation"; import "swiper/css/navigation";
import api, { GetAppGoodsInfoDetailResult } from "./api"; import api, { GetAppGoodsInfoDetailResult } from "./api";
import IntentionModal from "./components/intentionModal"; import IntentionModal from "./components/intentionModal";
import { UserContext } from "~/lib/userProvider";
export default function MallDetail() { export default function MallDetail() {
const [visible, setVisible] = useState(false); const { userInfo, setNeedLogin } = useContext(UserContext);
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<GetAppGoodsInfoDetailResult | null>( const [detail, setDetail] = useState<GetAppGoodsInfoDetailResult | null>(
null null
); //详情数据 ); //详情数据
const [intentionModalOpen, setIntentionModalOpen] = useState(false); //意向弹窗 const [intentionModalOpen, setIntentionModalOpen] = useState(false); //意向弹窗
//打开意向modal
const openIntentionModal = () => {
if (userInfo) {
setIntentionModalOpen(true);
} else {
setNeedLogin(true);
}
};
//提交意向
const handleIntentionOk = () => { const handleIntentionOk = () => {
setIntentionModalOpen(false); setIntentionModalOpen(false);
}; };
...@@ -52,7 +64,12 @@ export default function MallDetail() { ...@@ -52,7 +64,12 @@ export default function MallDetail() {
return ( return (
<Layout> <Layout>
{/* 意向弹窗 */} {/* 意向弹窗 */}
<IntentionModal open={intentionModalOpen} onOk={handleIntentionOk} onCancel={handleIntentionCancel}></IntentionModal> <IntentionModal
open={intentionModalOpen}
detail={detail}
onOk={handleIntentionOk}
onCancel={handleIntentionCancel}
></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
...@@ -134,7 +151,9 @@ export default function MallDetail() { ...@@ -134,7 +151,9 @@ export default function MallDetail() {
</Col> </Col>
<Col> <Col>
<Row align="middle" style={{ cursor: "pointer" }}> <Row align="middle" style={{ cursor: "pointer" }}>
<Col className={styles.font4} onClick={() => setIntentionModalOpen(true)}>共3种可选</Col> <Col className={styles.font4} onClick={openIntentionModal}>
共3种可选
</Col>
<Col style={{ marginLeft: 9 }}> <Col style={{ marginLeft: 9 }}>
<DownOutlined <DownOutlined
style={{ style={{
...@@ -169,8 +188,14 @@ export default function MallDetail() { ...@@ -169,8 +188,14 @@ export default function MallDetail() {
</Row> </Row>
</Space> </Space>
<Space size={12} style={{ marginTop: 123 }}> <Space size={12} style={{ marginTop: 123 }}>
<Button className={styles.btn1}>加入购物车</Button> <Button className={styles.btn1} onClick={openIntentionModal}>
<Button className={styles.btn2} type="primary" onClick={() => setIntentionModalOpen(true)}> 加入购物车
</Button>
<Button
className={styles.btn2}
type="primary"
onClick={openIntentionModal}
>
提交意向 提交意向
</Button> </Button>
<Space size={20} style={{ marginLeft: 19 }}> <Space size={20} style={{ marginLeft: 19 }}>
......
...@@ -46,7 +46,7 @@ export interface GoodsSpec { ...@@ -46,7 +46,7 @@ export interface GoodsSpec {
skuId: number; skuId: number;
brandInfoId: number; brandInfoId: number;
skuName: string; skuName: string;
productSpecList: ProductSpecList[]; productSpecList: ProductSpec[];
industrySpecList?: any; industrySpecList?: any;
chooseType: number; chooseType: number;
skuUnitId: number; skuUnitId: number;
...@@ -55,7 +55,7 @@ export interface GoodsSpec { ...@@ -55,7 +55,7 @@ export interface GoodsSpec {
flag?: any; flag?: any;
} }
export interface ProductSpecList { export interface ProductSpec {
id: number; id: number;
productSpec: number; productSpec: number;
productSkuId: number; productSkuId: number;
......
import { Button, Col, Image, Modal, Row, Space } from "antd"; import { Button, Col, Image, Modal, Row, Space } from "antd";
import { useState } from "react"; import { useState } from "react";
import errImg from "~/assets/errImg"; import errImg from "~/assets/errImg";
import { GetAppGoodsInfoDetailResult } from "../../api";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
type Props = { type Props = {
open?: boolean; open?: boolean;
onOk?: (e: React.MouseEvent<HTMLButtonElement>) => void; onOk?: (e: React.MouseEvent<HTMLButtonElement>) => void;
onCancel?: (e: React.MouseEvent<HTMLButtonElement>) => void; onCancel: (e: React.MouseEvent<HTMLButtonElement>) => void;
detail: GetAppGoodsInfoDetailResult | null;
}; };
export default function IntentionModal(props: Props) { export default function IntentionModal(props: Props) {
const list = [1, 1, 1, 1, 1, 1, 1, 1, 1]; const [checkedMap, setCheckedMap] = useState<{ string?: boolean }>({}); //通过索引记录选中的产品规格 例: {'1,1': true|false}
//添加规格到购物车
function addProductSpec(goodsSpecIndex: number, productSpecIndex: number) {
let temp = {};
//@ts-ignore
temp[`${goodsSpecIndex},${productSpecIndex}`] =
//@ts-ignore
!checkedMap[`${goodsSpecIndex},${productSpecIndex}`];
setCheckedMap({
...checkedMap,
...temp,
});
}
return ( return (
<Modal <Modal
...@@ -21,7 +37,13 @@ export default function IntentionModal(props: Props) { ...@@ -21,7 +37,13 @@ export default function IntentionModal(props: Props) {
className={styles.model} className={styles.model}
footer={ footer={
<div style={{ padding: "13px 36px" }}> <div style={{ padding: "13px 36px" }}>
<Button type="primary" className={styles.font5} style={{width: '100%', height: 44}}>提交意向</Button> <Button
type="primary"
className={styles.font5}
style={{ width: "100%", height: 44 }}
>
提交意向
</Button>
</div> </div>
} }
> >
...@@ -32,6 +54,7 @@ export default function IntentionModal(props: Props) { ...@@ -32,6 +54,7 @@ export default function IntentionModal(props: Props) {
height={100} height={100}
fallback={errImg} fallback={errImg}
style={{ borderRadius: 8 }} style={{ borderRadius: 8 }}
src={props.detail?.images?.[0]?.imgUrl}
></Image> ></Image>
</Col> </Col>
<Col flex="auto" style={{ marginLeft: 13, width: 230 }}> <Col flex="auto" style={{ marginLeft: 13, width: 230 }}>
...@@ -39,13 +62,13 @@ export default function IntentionModal(props: Props) { ...@@ -39,13 +62,13 @@ export default function IntentionModal(props: Props) {
className={`${styles.font1} ${styles.ellipsis1}`} className={`${styles.font1} ${styles.ellipsis1}`}
style={{ marginTop: 28 }} style={{ marginTop: 28 }}
> >
垂直起降固定翼 插翅虎M9 {props.detail?.goodsName}
</div> </div>
<div <div
className={`${styles.font2} ${styles.ellipsis2}`} className={`${styles.font2} ${styles.ellipsis2}`}
style={{ marginTop: 7 }} style={{ marginTop: 7 }}
> >
已选:入云龙【机壳喷绘】+金眼彪Z40【222222222222222222222222233333555555555555555 已选:
</div> </div>
</Col> </Col>
</Row> </Row>
...@@ -54,40 +77,59 @@ export default function IntentionModal(props: Props) { ...@@ -54,40 +77,59 @@ export default function IntentionModal(props: Props) {
<div className={styles.font3} style={{}}> <div className={styles.font3} style={{}}>
无人机 无人机
</div> </div>
<div> {props.detail?.goodsSpec?.map((item, goodsSpecIndex) => {
<div return (
className={styles.font2} <div key={item.id}>
style={{ marginBottom: 5, marginTop: 11 }} <div
> className={styles.font2}
入云龙 style={{ marginBottom: 5, marginTop: 11 }}
</div> >
<Space size={10} direction="vertical" style={{ width: "100%" }}> {item.goodsSpecName}
{list.map((item, i) => { </div>
return ( <Space size={10} direction="vertical" style={{ width: "100%" }}>
<Row {item.productSpecList?.map((product, productSpecIndex) => {
key={i} return (
align="middle" <Row
wrap={false} key={product.id}
style={{ align="middle"
borderRadius: 5, wrap={false}
border: "1px solid #d6d6d6", style={{
height: 50, borderRadius: 5,
}} //@ts-ignore
> border: checkedMap[
<Col style={{ marginLeft: 7 }}> `${goodsSpecIndex},${productSpecIndex}`
<Image width={52} height={36} src="" fallback={errImg} preview={false}></Image> ]
</Col> ? "1px solid #FF552D"
<Col : "1px solid #d6d6d6",
className={`${styles.ellipsis1} ${styles.font4}`} height: 50,
style={{ width: 238, marginLeft: 18 }} cursor: "pointer",
> }}
入云龙1-机壳喷绘 onClick={() =>
</Col> addProductSpec(goodsSpecIndex, productSpecIndex)
</Row> }
); >
})} <Col style={{ marginLeft: 7 }}>
</Space> <Image
</div> width={52}
height={36}
src={product.specImage}
fallback={errImg}
preview={false}
></Image>
</Col>
<Col
className={`${styles.ellipsis1} ${styles.font4}`}
style={{ width: 238, marginLeft: 18 }}
>
{product.specName}
</Col>
</Row>
);
})}
</Space>
</div>
);
})}
</div> </div>
</div> </div>
</Modal> </Modal>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论