荣耀手机商品详情页 - 加入购物车
import React, { Component } from 'react'
import './index.scss'
import { Swiper } from 'antd-mobile'
import { connect } from 'react-redux';
import { addCartAction } from '../../store/actions/cart';
import axios from 'axios';
import phone1 from '../../img/phone2.png'
import phone2 from '../../img/phone3.png'
import phone3 from '../../img/phone4.png'
class CartContent extends Component {
state = {
img: [],
itemObj: {},
}
componentDidMount() {
console.log(this.props);
const { id } = this.props.match.params;
axios.get(`/queryPrdDisplayDetailInfo?portal=21&version=350&lang=zh-CN&country=CNQX&_areacode=CNQX&beCode=CNQX&item_id=${id}&sbomCode=8086110027003&productId=${id}`).then(res => {
console.log(res);
this.setState({ itemObj: res.data, img: res.data.sbomList[0].groupPhotoList })
})
}
addCartFn = () => {
const { token } = this.props;
if (token !== '') {
const { disPrdId, name } = this.state.itemObj;
const { photoPath, photoName } = this.state.itemObj.sbomList[0]
const data = {
id: disPrdId,
name: name,
num: 1,
price: this.state.itemObj.sbomList[0].price || 0,
pic: `https://hshop.honorfile.com/pimages/cnqx/${photoPath}800_800_${photoName}`
}
this.props.addCartAction(data);
Navigate('/Cart')
} else {
Navigate('/Login')
}
}
render() {
const { itemObj } = this.state;
const { img } = this.state;
const { token } = this.props;
return (
{img.map((item, index) =>
)}
{
itemObj.sbomList != undefined ?
}
{
itemObj.sbomList != undefined ?
}
{
itemObj.sbomList != undefined ?
}
{/*
{/*
规格
已选:幻夜黑 5G全网通 8GB+256GB
{/* */}
)
}
}
export default connect(state => ({ cart: state.cart, token: state.user.token }),
{ addCartAction }
)(CartContent)
原文地址: https://www.cveoy.top/t/topic/oeYD 著作权归作者所有。请勿转载和采集!