Cancelled.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import React, {Component} from 'react';
  2. import {orderbyprops, updateorder} from "../../../gql";
  3. // import {deleteorder} from "../../gql";
  4. import gql from "graphql-tag";
  5. import {Query, Mutation} from "react-apollo";
  6. import {Card, WhiteSpace, Button, ActivityIndicator, WingBlank} from 'antd-mobile';
  7. import moment from 'moment';
  8. import 'moment/locale/zh-cn'
  9. import {Row, Col} from 'antd';
  10. moment.locale('zh-cn');
  11. class Cancelled extends Component {
  12. render() {
  13. let {userID} = this.props;
  14. return (
  15. <Query query={gql(orderbyprops)} variables={{user_id: userID, orderStatus: 'cancelled'}}>
  16. {
  17. ({loading, error, data}) => {
  18. if (loading) {
  19. return (
  20. <div className="tab-center">
  21. <ActivityIndicator text="Loading..." size="large"/>z
  22. </div>
  23. )
  24. }
  25. if (error) {
  26. return 'error!';
  27. }
  28. let orders = data.orderbyprops;
  29. let tip = '';
  30. if (orders.length === 0) {
  31. orders = [];
  32. tip = '还没有取消的订单'
  33. }
  34. return (
  35. <CancelledRender
  36. orders={orders}
  37. tip={tip}
  38. userID={userID}
  39. />
  40. )
  41. }
  42. }
  43. </Query>
  44. );
  45. }
  46. }
  47. export default Cancelled;
  48. class CancelledRender extends Component {
  49. constructor(props) {
  50. super(props);
  51. this.state = {}
  52. }
  53. render() {
  54. let {orders, tip, userID} = this.props;
  55. return (
  56. <div>
  57. {
  58. tip ?
  59. <div className={'center-fix'}>{tip}</div>
  60. :
  61. ''
  62. }
  63. {
  64. orders.map((order) => {
  65. return (
  66. <div key={order.id}>
  67. <WingBlank size="lg">
  68. <WhiteSpace size="lg"/>
  69. <Card className={'card'}>
  70. <Card.Body>
  71. <div>
  72. <Row>
  73. <Col span={14}>
  74. <div className={'order-name'}>{order.serverName}</div>
  75. </Col>
  76. <Col span={6}>
  77. <div className={'order-remark'}>留言: {order.remark ? order.remark : '无'}</div>
  78. </Col>
  79. <Col span={4}>
  80. {/*<DeleteButton1*/}
  81. {/*orderID={order.id}*/}
  82. {/*userID={userID}*/}
  83. {/*/>*/}
  84. <DeleteButton2
  85. orderID={order.id}
  86. userID={userID}
  87. />
  88. </Col>
  89. </Row>
  90. <Row>
  91. <div
  92. className={'order-time'}>预约于: {moment(Number(order.serviceStartTime)).format("YYYY-MM-DD HH:mm:ss")}</div>
  93. <div
  94. className={'order-time'}>取消于: {moment(Number(order.updatedAt)).format("YYYY-MM-DD HH:mm:ss")}</div>
  95. </Row>
  96. </div>
  97. </Card.Body>
  98. </Card>
  99. </WingBlank>
  100. </div>
  101. )
  102. })
  103. }
  104. </div>
  105. )
  106. }
  107. }
  108. // 用户直接删除数据库的按钮
  109. // class DeleteButton1 extends Component {
  110. // constructor(props) {
  111. // super(props);
  112. // this.state = {
  113. //
  114. // }
  115. // }
  116. //
  117. // render() {
  118. // let {orderID, userID} = this.props;
  119. // return (
  120. // <Mutation
  121. // mutation={gql(deleteorder)}
  122. // refetchQueries={[{query: gql(orderbyprops), variables: {user_id: userID, orderStatus: 'cancelled'}}]}
  123. // >
  124. // {(deleteorder, {loading, error}) => {
  125. // if (loading)
  126. // return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
  127. // if (error)
  128. // return 'error';
  129. // let varObj = {
  130. // id: orderID,
  131. // user_id: userID
  132. // };
  133. // return (
  134. // <Button inline size={'small'} type='warning' onClick={()=>{
  135. // deleteorder({variables: varObj})
  136. // }}>删除</Button>
  137. // )
  138. // }}
  139. // </Mutation>
  140. //
  141. // )
  142. // }
  143. // }
  144. // 用户无法直接删除数据库,只是改变订单状态的按钮
  145. class DeleteButton2 extends Component {
  146. constructor(props) {
  147. super(props);
  148. this.state = {}
  149. }
  150. render() {
  151. let {orderID, userID} = this.props;
  152. return (
  153. <Mutation
  154. mutation={gql(updateorder)}
  155. refetchQueries={[{query: gql(orderbyprops), variables: {user_id: userID, orderStatus: 'cancelled'}}]}
  156. >
  157. {(updateorder, {loading, error}) => {
  158. if (loading)
  159. return (
  160. <div className="tab-center">
  161. <ActivityIndicator text="Loading..." size="large"/>
  162. </div>
  163. );
  164. if (error)
  165. return 'error';
  166. let varObj = {
  167. id: orderID,
  168. user_id: userID,
  169. orderStatus: 'deleted',
  170. updatedAt: new Date().getTime()
  171. };
  172. return (
  173. <Button type='warning' inline size={'small'} onClick={() => {
  174. updateorder({variables: varObj})
  175. }}>删除</Button>
  176. )
  177. }}
  178. </Mutation>
  179. )
  180. }
  181. }