index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Logo from '../../../components/logo'
  7. import {category_by_props, productbyprops, slideshow_by_shop} from "../../../utils/gql"
  8. import './index.css'
  9. class All extends Component {
  10. constructor(props) {
  11. super(props)
  12. this.state = {
  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. <Query query={gql(slideshow_by_shop)} >
  29. {
  30. ({loading, error, data}) => {
  31. if (loading) {
  32. return (
  33. <div className="loading-center">
  34. <ActivityIndicator text="加载中..." size="large"/>
  35. </div>
  36. )
  37. }
  38. if (error) {
  39. return 'error!'
  40. }
  41. // console.log("slideshow_by_shop data",data)
  42. // let slideshow = data.slideshowbyprops || []
  43. let slideshow = data.slideshowbyshop ? data.slideshowbyshop[0].slideshow : []
  44. return (
  45. <Carousel
  46. autoplay={true}
  47. infinite
  48. style={{minHeight: 200}}
  49. >
  50. {slideshow.map(val => (
  51. <a
  52. key={val}
  53. href="http://www.alipay.com"
  54. style={{
  55. display: 'inline-block',
  56. width: '100%',
  57. height: 'auto',
  58. maxHeight: '200px',
  59. overflow: 'hidden'
  60. }}
  61. >
  62. <img
  63. src={val}
  64. alt=""
  65. style={{width: '100%', verticalAlign: 'top'}}
  66. />
  67. </a>
  68. ))}
  69. </Carousel>
  70. )
  71. }
  72. }
  73. </Query>
  74. <Query query={gql(category_by_props)} variables={categoryFilter}>
  75. {
  76. ({loading, error, data}) => {
  77. if (loading) {
  78. return (
  79. <div className="loading-center">
  80. <ActivityIndicator text="加载中..." size="large"/>
  81. </div>
  82. )
  83. }
  84. if (error) {
  85. return 'error!'
  86. }
  87. let categoryList = data.categorybyprops
  88. let dataList = categoryList.concat(more)
  89. return (
  90. <Grid
  91. data={dataList}
  92. hasLine={false}
  93. onClick={(kind) => {
  94. this.props.history.push({
  95. pathname: '/home/kind',
  96. state: {
  97. id: kind.id,
  98. category: kind.text
  99. }
  100. })
  101. }}/>
  102. )
  103. }
  104. }
  105. </Query>
  106. <WhiteSpace/>
  107. <div className='guess-wrap'>
  108. <Query query={gql(productbyprops)} variables={{status: '1', recommend: 1}}>
  109. {
  110. ({loading, error, data}) => {
  111. if (loading) {
  112. return (
  113. <div className="loading-center">
  114. <ActivityIndicator text="加载中..." size="large"/>
  115. </div>
  116. )
  117. }
  118. if (error) {
  119. return 'error!'
  120. }
  121. // console.log(data.productbyprops)
  122. return (
  123. <Recommend data={data.productbyprops} history={this.props.history}/>
  124. )
  125. }
  126. }
  127. </Query>
  128. </div>
  129. <Logo/>
  130. </div>
  131. )
  132. }
  133. }
  134. class Recommend extends Component {
  135. constructor(props) {
  136. super(props)
  137. this.state = {}
  138. }
  139. render() {
  140. let {data} = this.props
  141. return (
  142. <div className='guess-wrapper'>
  143. <div className='guess-title'>- 店长推荐 -</div>
  144. <Grid
  145. data={data}
  146. columnNum={2}
  147. hasLine={false}
  148. onClick={(recommend) => {
  149. this.props.history.push({
  150. pathname: '/home/detail',
  151. state: {
  152. id: recommend.id
  153. }
  154. })
  155. }}
  156. renderItem={dataItem => (
  157. <div key={dataItem.id} className='product-item'>
  158. <div className='product-item-img' style={{backgroundImage: "url('" + dataItem.img + "')"}}/>
  159. <div className='product-item-description'>
  160. <div className='product-item-name'>{dataItem.name}</div>
  161. <div className='product-item-price'>
  162. <span>¥{(dataItem.price * dataItem.discountRate / 100).toFixed(2)}</span>&nbsp;
  163. <span>¥{dataItem.price}</span>
  164. </div>
  165. </div>
  166. </div>
  167. )}
  168. />
  169. </div>
  170. )
  171. }
  172. }
  173. export default withRouter(All)