index.js 8.3 KB

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