index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React, {Component} from "react"
  2. import {withRouter} from 'react-router-dom'
  3. import {Query} from "react-apollo"
  4. import gql from "graphql-tag"
  5. import {Grid, Carousel, WhiteSpace, ActivityIndicator} from 'antd-mobile'
  6. import {category_by_props, productbyprops} from "../../../utils/gql"
  7. import './index.css'
  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 categoryFilter = {
  17. "status": "1",
  18. "limit": 7,
  19. "sort_by": {"order": "asc"}
  20. }
  21. const more = {
  22. icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/more.png',
  23. text: '更多',
  24. id: 'more'
  25. }
  26. return (
  27. <div>
  28. <Carousel
  29. autoplay={true}
  30. infinite
  31. style={{minHeight:200}}
  32. >
  33. {this.state.data.map(val => (
  34. <a
  35. key={val}
  36. href="http://www.alipay.com"
  37. style={{
  38. display: 'inline-block',
  39. width: '100%',
  40. height: 'auto',
  41. maxHeight: '200px',
  42. overflow: 'hidden'
  43. }}
  44. >
  45. <img
  46. src={`https://zos.alipayobjects.com/rmsportal/${val}.png`}
  47. alt=""
  48. style={{width: '100%', verticalAlign: 'top'}}
  49. />
  50. </a>
  51. ))}
  52. </Carousel>
  53. <Query query={gql(category_by_props)} variables={categoryFilter}>
  54. {
  55. ({loading, error, data}) => {
  56. if (loading) {
  57. return (
  58. <div className="loading-center">
  59. <ActivityIndicator text="Loading..." size="large"/>
  60. </div>
  61. )
  62. }
  63. if (error) {
  64. return 'error!'
  65. }
  66. let categoryList = data.categorybyprops
  67. let dataList = categoryList.concat(more)
  68. return (
  69. <Grid
  70. data={dataList}
  71. hasLine={false}
  72. onClick={(kind)=>{
  73. this.props.history.push({
  74. pathname: '/home/kind',
  75. state: {
  76. id: kind.id,
  77. category:kind.text
  78. }
  79. })
  80. }}/>
  81. )
  82. }
  83. }
  84. </Query>
  85. <WhiteSpace/>
  86. <div className='guess-wrap'>
  87. <Query query={gql(productbyprops)} variables={{status: '1', recommend: 1}}>
  88. {
  89. ({loading, error, data}) => {
  90. if (loading) {
  91. return (
  92. <div className="loading-center">
  93. <ActivityIndicator text="Loading..." size="large"/>
  94. </div>
  95. )
  96. }
  97. if (error) {
  98. return 'error!'
  99. }
  100. return (
  101. <Recommend data={data.productbyprops} history={this.props.history}/>
  102. )
  103. }
  104. }
  105. </Query>
  106. </div>
  107. </div>
  108. )
  109. }
  110. }
  111. class Recommend extends Component {
  112. constructor(props) {
  113. super(props)
  114. this.state = {}
  115. }
  116. render() {
  117. let {data} = this.props
  118. return (
  119. <div className='guess-wrapper'>
  120. <div className='guess-title'>- 店长推荐 -</div>
  121. <Grid data={data}
  122. columnNum={2}
  123. hasLine={false}
  124. onClick={(recommend)=>{
  125. this.props.history.push({
  126. pathname: '/home/detail',
  127. state: {
  128. id: recommend.id
  129. }
  130. })
  131. }}
  132. renderItem={dataItem => (
  133. <div key={dataItem.id} className='product-item'>
  134. <div className='product-item-img' style={{backgroundImage: "url('" + dataItem.img + "')"}}/>
  135. <div className='product-item-description'>
  136. <div className='product-item-name'>{dataItem.name}</div>
  137. <div className='product-item-price'>
  138. <span>¥{dataItem.price}</span>&nbsp;
  139. <span>¥{dataItem.price}</span>
  140. </div>
  141. </div>
  142. </div>
  143. )}
  144. />
  145. </div>
  146. )
  147. }
  148. }
  149. export default withRouter(All)