index.js 6.2 KB

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