index.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import React, {Component} from 'react'
  2. import {withRouter} from 'react-router-dom'
  3. import {Row, Col} from 'antd'
  4. import {NavBar, Icon, ActivityIndicator, Button} from 'antd-mobile'
  5. import {Query} from "react-apollo"
  6. import gql from "graphql-tag"
  7. import classNames from 'classnames'
  8. import {orderbyprops, orderProduct_by_props} from "../../../../utils/gql"
  9. import './index.css'
  10. class Display extends Component {
  11. constructor(props) {
  12. super(props)
  13. this.state = {
  14. navTitle: '待付款',
  15. kind: 'pay',
  16. orderStatus: '0'
  17. }
  18. }
  19. componentWillMount() {
  20. let {location} = this.props
  21. if (location && location.state) {
  22. let navTitle = '',
  23. orderStatus = '0'
  24. let kind = location.state.kind
  25. switch (kind) {
  26. case 'pay':
  27. navTitle = '待付款'
  28. orderStatus = '0'
  29. break
  30. case 'ship':
  31. navTitle = '待发货'
  32. orderStatus = '1'
  33. break
  34. case 'unbox':
  35. navTitle = '待收货'
  36. orderStatus = '2'
  37. break
  38. case 'judge':
  39. navTitle = '待评价'
  40. orderStatus = '3'
  41. break
  42. default:
  43. navTitle = '无效页面'
  44. break
  45. }
  46. this.setState({
  47. navTitle,
  48. kind,
  49. orderStatus
  50. })
  51. }
  52. }
  53. render() {
  54. let {navTitle, orderStatus} = this.state
  55. return (
  56. <div className='order-wrap'>
  57. <div className='navbar'>
  58. <NavBar
  59. mode="light"
  60. icon={<Icon type="left"/>}
  61. onLeftClick={() => {
  62. this.props.history.go(-2)
  63. }}
  64. >{navTitle}</NavBar>
  65. </div>
  66. <Query query={gql(orderbyprops)} variables={{user_id: "obR_j5GbxDfGlOolvSeTdZUwfpKA", orderStatus}}>
  67. {
  68. ({loading, error, data}) => {
  69. if (loading) {
  70. return (
  71. <div className="loading-center">
  72. <ActivityIndicator text="Loading..." size="large"/>
  73. </div>
  74. )
  75. }
  76. if (error) {
  77. return 'error!'
  78. }
  79. return (
  80. <DisplayRender data={data.orderbyprops} orderStatus={orderStatus}
  81. history={this.props.history}/>
  82. )
  83. }
  84. }
  85. </Query>
  86. </div>
  87. )
  88. }
  89. }
  90. class DisplayRender extends Component {
  91. constructor(props) {
  92. super(props)
  93. this.state = {}
  94. }
  95. orderCardContentRender = (data) => {
  96. if (data.length === 1) {
  97. return (
  98. <Row style={{width: '100%'}}>
  99. <Col span={6} style={{height: '100%'}}>
  100. <div className='order-product-img'
  101. style={{backgroundImage: `url('${data[0].product_id.img}')`}}/>
  102. </Col>
  103. <Col span={16} offset={2}>
  104. <div className='order-product-name'>{data[0].product_id.name}</div>
  105. </Col>
  106. </Row>
  107. )
  108. } else {
  109. return (data.map(data => (
  110. <div className='order-product-img' style={{backgroundImage: `url('${data.product_id.img}')`}}
  111. key={data.id}/>
  112. )))
  113. }
  114. }
  115. render() {
  116. let {data, orderStatus, button = true} = this.props
  117. let content = orderStatus === '0' ? '需付款' : '实付款'
  118. return (
  119. <div className={classNames({'content-wrap': button})}>
  120. {
  121. data.length === 0 ?
  122. <div>
  123. 还没有这种订单呢
  124. </div>
  125. :
  126. data.map(order => (
  127. <div key={order.id} className='order-card'>
  128. <div className='order-card-top'>订单号: {order.id}</div>
  129. <Query query={gql(orderProduct_by_props)} variables={{order_id: order.id}}>
  130. {
  131. ({loading, error, data}) => {
  132. if (loading) {
  133. return (
  134. <div className="loading-center">
  135. <ActivityIndicator text="Loading..." size="large"/>
  136. </div>
  137. )
  138. }
  139. if (error) {
  140. return 'error!'
  141. }
  142. data = data.orderProductbyprops
  143. return (
  144. <div>
  145. <div className='order-card-content' onClick={() => {
  146. this.props.history.push({
  147. pathname: '/my/order/detail',
  148. state: {
  149. data: order
  150. }
  151. })
  152. }}>
  153. {
  154. this.orderCardContentRender(data)
  155. }
  156. </div>
  157. </div>
  158. )
  159. }
  160. }
  161. </Query>
  162. <div className='order-card-bottom'>
  163. <div
  164. className='order-card-count'>共{order.count}件商品&nbsp;&nbsp;{content}:
  165. </div>
  166. <div className='order-card-pay'>¥{Math.round(order.productTotalPay * 100) / 100}</div>
  167. </div>
  168. {
  169. button?
  170. <ButtonGroupRender orderStatus={this.props.orderStatus}/>
  171. :
  172. ''
  173. }
  174. </div>
  175. ))
  176. }
  177. </div>
  178. )
  179. }
  180. }
  181. const ButtonGroupRender = (props) => {
  182. let {orderStatus} = props
  183. switch (orderStatus) {
  184. case '0':
  185. return (
  186. <div className='order-card-button-group'>
  187. <Button size="small" className='pay-button order-button'>去支付</Button>
  188. </div>
  189. )
  190. case '1':
  191. return (
  192. <div className='order-card-button-group'>
  193. <Button size="small" className='ship-button order-button'>催发货</Button>
  194. &nbsp;&nbsp;
  195. <Button size="small" className='cancel-button order-button'>取消订单</Button>
  196. </div>
  197. )
  198. case '2':
  199. return (
  200. <div className='order-card-button-group'>
  201. <Button size="small" className='unbox-button order-button'>查看物流</Button>
  202. &nbsp;&nbsp;
  203. <Button size="small" className='cancel-button order-button'>取消订单</Button>
  204. </div>
  205. )
  206. case '3':
  207. return (
  208. <div className='order-card-button-group'>
  209. <Button size="small" className='judge-button order-button'>去评价</Button>
  210. &nbsp;&nbsp;
  211. <Button size="small" className='more-button order-button'>售后</Button>
  212. </div>
  213. )
  214. default:
  215. return (
  216. <div>
  217. ok
  218. </div>
  219. )
  220. }
  221. }
  222. export default withRouter(Display)
  223. export {
  224. DisplayRender,
  225. ButtonGroupRender
  226. }