index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import React, {Component} from "react"
  2. import {productbyprops} from "../../../utils/gql"
  3. import {Query} from "react-apollo"
  4. import gql from "graphql-tag"
  5. import {Grid, Carousel, WhiteSpace, ActivityIndicator} from 'antd-mobile'
  6. import './index.css'
  7. import {withRouter} from 'react-router-dom'
  8. class All extends Component {
  9. constructor(props) {
  10. super(props)
  11. this.state = {
  12. data: ['AiyWuByWklrrUDlFignR', 'TekJlZRVCjLFexlOCuWn', 'IJOtIlfsYdTyaDTRVrLI']
  13. }
  14. }
  15. render() {
  16. const data = [
  17. {
  18. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/jacket.png',
  19. text: '夹克',
  20. id: 'jacket'
  21. },
  22. {
  23. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/coat.png',
  24. text: '外套',
  25. id: 'coat'
  26. },
  27. {
  28. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/shirt.png',
  29. text: '衬衫',
  30. id: 'shirt'
  31. },
  32. {
  33. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/skirts.png',
  34. text: '半身裙',
  35. id: 'skirt'
  36. },
  37. {
  38. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/sweater.png',
  39. text: '针织衫',
  40. id: 'sweater'
  41. },
  42. {
  43. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/windbreak.png',
  44. text: '风衣',
  45. id: 'windbreak'
  46. },
  47. {
  48. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/pants.png',
  49. text: '裤子',
  50. id: 'pants'
  51. },
  52. {
  53. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/more.png',
  54. text: '更多',
  55. id: 'more'
  56. }
  57. ]
  58. return (
  59. <div>
  60. <Carousel
  61. autoplay={true}
  62. infinite
  63. style={{minHeight:200}}
  64. >
  65. {this.state.data.map(val => (
  66. <a
  67. key={val}
  68. href="http://www.alipay.com"
  69. style={{
  70. display: 'inline-block',
  71. width: '100%',
  72. height: 'auto',
  73. maxHeight: '200px',
  74. overflow: 'hidden'
  75. }}
  76. >
  77. <img
  78. src={`https://zos.alipayobjects.com/rmsportal/${val}.png`}
  79. alt=""
  80. style={{width: '100%', verticalAlign: 'top'}}
  81. />
  82. </a>
  83. ))}
  84. </Carousel>
  85. <Grid
  86. data={data}
  87. hasLine={false}
  88. onClick={(kind)=>{
  89. this.props.history.push({
  90. pathname: '/home/kind',
  91. state: {
  92. id: kind.id
  93. }
  94. })
  95. }}/>
  96. <WhiteSpace/>
  97. <div className='guess-wrap'>
  98. <Query query={gql(productbyprops)} variables={{status: '1'}}>
  99. {
  100. ({loading, error, data}) => {
  101. if (loading) {
  102. return (
  103. <div className="loading-center">
  104. <ActivityIndicator text="Loading..." size="large"/>
  105. </div>
  106. )
  107. }
  108. if (error) {
  109. return 'error!'
  110. }
  111. return (
  112. <Like data={data.productbyprops} history={this.props.history}/>
  113. )
  114. }
  115. }
  116. </Query>
  117. </div>
  118. </div>
  119. )
  120. }
  121. }
  122. class Like extends Component {
  123. constructor(props) {
  124. super(props)
  125. this.state = {}
  126. }
  127. render() {
  128. let {data} = this.props
  129. return (
  130. <div className='guess-wrapper'>
  131. <div className='guess-title'>- 猜你喜欢 -</div>
  132. <Grid data={data}
  133. columnNum={2}
  134. hasLine={false}
  135. onClick={(guess)=>{
  136. this.props.history.push({
  137. pathname: '/home/detail',
  138. state: {
  139. id: guess.id
  140. }
  141. })
  142. }}
  143. renderItem={dataItem => (
  144. <div key={dataItem.id} className='guess-item'>
  145. <div className='guess-item-img' style={{backgroundImage: "url('" + dataItem.img + "')"}}/>
  146. <div className='guess-item-description'>
  147. <div className='guess-item-name'>{dataItem.name}</div>
  148. <div className='guess-item-price'>{dataItem.price}</div>
  149. </div>
  150. </div>
  151. )}
  152. />
  153. </div>
  154. )
  155. }
  156. }
  157. export default withRouter(All)