index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, {Component} from 'react'
  2. import {NavBar, Icon, ActivityIndicator} from 'antd-mobile'
  3. import {productbyid} from "../../../utils/gql"
  4. import {Query} from "react-apollo"
  5. import gql from "graphql-tag"
  6. import './index.css'
  7. import {withRouter} from 'react-router-dom'
  8. class Detail extends Component {
  9. constructor(props) {
  10. super(props)
  11. this.state = {
  12. id: ''
  13. }
  14. }
  15. componentWillMount() {
  16. let {location} = this.props
  17. if(location && location.state) {
  18. this.setState({
  19. id: location.state.id
  20. })
  21. }
  22. }
  23. render() {
  24. let {id} = this.state
  25. return (
  26. <div className='detail-wrap'>
  27. <div className='detail-navbar-wrap'>
  28. <NavBar
  29. className='detail-navbar'
  30. mode="light"
  31. icon={<Icon type="left"/>}
  32. onLeftClick={() => {this.props.history.push({pathname: '/'})}}
  33. rightContent={[
  34. <Icon key="1" type="ellipsis"/>,
  35. ]}
  36. >商品详情</NavBar>
  37. </div>
  38. <Query query={gql(productbyid)} variables={{id}}>
  39. {
  40. ({loading, error, data}) => {
  41. if (loading) {
  42. return (
  43. <div className="loading-center">
  44. <ActivityIndicator text="Loading..." size="large"/>
  45. </div>
  46. )
  47. }
  48. if (error) {
  49. return 'error!'
  50. }
  51. return (
  52. <DetailRender data={data.productbyid}/>
  53. )
  54. }
  55. }
  56. </Query>
  57. </div>
  58. )
  59. }
  60. }
  61. export default withRouter(Detail)
  62. class DetailRender extends Component {
  63. constructor(props) {
  64. super(props)
  65. this.state = {
  66. }
  67. }
  68. render() {
  69. let {data} = this.props;
  70. return (
  71. <div className='detail-wrapper'>
  72. <div className='detail-simple-show'>
  73. <div className='detail-img' style={{backgroundImage: "url('"+ data.img + "')"}}/>
  74. <div className='detail-below-img-in-simle-show-hahahahah'>
  75. <div className='detail-name'>{data.name}</div>
  76. <div className='detail-price'>{data.price}</div>
  77. <div className='detail-stock'>{data.stock}</div>
  78. </div>
  79. </div>
  80. <div className='detail-complicate-show'>详情详情</div>
  81. <div className='detail-bottom'>
  82. <div className='detail-bottom-cart'>购物车</div>
  83. <div className='detail-bottom-home'>店铺</div>
  84. <div className='detail-bottom-add'>加入购物车</div>
  85. <div className='detail-bottom-buy'>立即购买</div>
  86. </div>
  87. </div>
  88. )
  89. }
  90. }