index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. let contentHeight = window.innerHeight
  26. return (
  27. <div className='detail-wrap' style={{height: contentHeight}}>
  28. <div className='detail-navbar-wrap'>
  29. <NavBar
  30. className='detail-navbar'
  31. mode="light"
  32. icon={<Icon type="left"/>}
  33. onLeftClick={() => {this.props.history.push({pathname: '/'})}}
  34. rightContent={[
  35. <Icon key="1" type="ellipsis"/>,
  36. ]}
  37. >商品详情</NavBar>
  38. </div>
  39. <Query query={gql(productbyid)} variables={{id}}>
  40. {
  41. ({loading, error, data}) => {
  42. if (loading) {
  43. return (
  44. <div className="loading-center">
  45. <ActivityIndicator text="Loading..." size="large"/>
  46. </div>
  47. )
  48. }
  49. if (error) {
  50. return 'error!'
  51. }
  52. return (
  53. <DetailRender data={data.productbyid} history={this.props.history}/>
  54. )
  55. }
  56. }
  57. </Query>
  58. </div>
  59. )
  60. }
  61. }
  62. export default withRouter(Detail)
  63. class DetailRender extends Component {
  64. constructor(props) {
  65. super(props)
  66. this.state = {
  67. }
  68. }
  69. render() {
  70. let {data} = this.props;
  71. return (
  72. <div className='detail-wrapper'>
  73. <div className='detail-simple-show'>
  74. <div className='detail-img' style={{backgroundImage: "url('"+ data.img + "')"}}/>
  75. <div className='detail-below-img-in-simle-show-hahahahah'>
  76. <div className='detail-name'>{data.name}</div>
  77. <div className='detail-price'>{data.price}</div>
  78. <div className='detail-stock'>{data.stock}</div>
  79. </div>
  80. </div>
  81. <div className='detail-complicate-show'>详情详情</div>
  82. <div className='detail-bottom'>
  83. <span className='detail-bottom-cart' onClick={()=>{this.props.history.push({pathname: '/cart'})}}><div className='detail-icon-wrap'><div className='detail-icon detail-icon-cart'/><div>购物袋</div></div></span>
  84. <span className='detail-bottom-home' onClick={()=>{this.props.history.push({pathname: '/home'})}}><div className='detail-icon-wrap'><div className='detail-icon detail-icon-shop'/><div>店铺</div></div></span>
  85. <span className='detail-bottom-add' onClick={()=>{}}>加入购物车</span>
  86. <span className='detail-bottom-buy' onClick={()=>{}}>立即购买</span>
  87. </div>
  88. </div>
  89. )
  90. }
  91. }