Cards.jsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React, { Component } from 'react';
  2. import { Link } from 'react-router-dom'
  3. import { Card, WingBlank, WhiteSpace } from 'antd-mobile';
  4. //import { Item } from 'antd-mobile/lib/tab-bar';
  5. import './Cards.css'
  6. import {PageContext} from '../../context/context'
  7. class Cards extends Component{
  8. constructor(props){
  9. //console.log('111',props)
  10. super(props)
  11. this.state={
  12. product_id:''
  13. }
  14. }
  15. render(){
  16. //console.log('cardProps',this.props.products)
  17. const Cardss=this.props.products.map((item,index)=>{
  18. //console.log(item)
  19. return (
  20. <PageContext.Consumer key={index} >
  21. {(changePage)=>{
  22. return(
  23. <WingBlank size="lg" className="Card">
  24. <WhiteSpace size="lg" />
  25. {/*<Link to={"/detail?product_id="+item.id}>*/}
  26. <Card onClick={(e)=>{changePage('detail',item.id)}}>
  27. <Card.Header
  28. title={<span className="title">{item.name}</span>}
  29. extra={<span className="hot">热门</span>}
  30. />
  31. <Card.Body>
  32. <div className="bodyWrap">
  33. <div className="imgWrap">
  34. <img src={item.img} alt="xxx" height="100px" width="100px"/>
  35. </div>
  36. <div className="sidebar">
  37. <p className="p1">{item.intro}</p>
  38. </div>
  39. <div className="rightsidebar">
  40. <p className="p2">{item.price}/斤</p>
  41. <p className="p3">库存:{item.stock}</p>
  42. </div>
  43. </div>
  44. </Card.Body>
  45. <Card.Footer content="" extra={<div></div>} />
  46. </Card>
  47. {/*</Link>*/}
  48. <WhiteSpace size="lg" />
  49. </WingBlank>
  50. )
  51. }}
  52. </PageContext.Consumer>
  53. )
  54. })
  55. return (
  56. <div>
  57. {Cardss}
  58. </div>
  59. )
  60. }
  61. }
  62. export default Cards