SubOrderProfile.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. import React, { Component } from 'react';
  2. import { connect } from 'dva';
  3. import { routerRedux } from 'dva/router';
  4. import queryString from 'query-string';
  5. import { Card, Form, Modal, Steps, Button, Table, Input, Icon } from 'antd';
  6. import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
  7. import FooterToolbar from '../../../components/FooterToolbar';
  8. import { Codes, productType } from '../../../utils/config';
  9. import { provCodeToName } from '../../../utils/city';
  10. @connect(state => ({ orderDetail: state.orderDetail }))
  11. @Form.create()
  12. export default class SubOrderProfile extends Component {
  13. /**
  14. * 返回订单列表
  15. */
  16. handlePageCancel = () => {
  17. const { orderDetail, dispatch } = this.props;
  18. const { filters } = orderDetail;
  19. dispatch(routerRedux.push({
  20. pathname: '/trade/order',
  21. search: queryString.stringify(filters),
  22. }));
  23. }
  24. /**
  25. * 显示发货弹框
  26. */
  27. showSendModal = () => {
  28. this.props.dispatch({
  29. type: 'orderDetail/showDeliveryModal',
  30. });
  31. }
  32. /**
  33. * 隐藏发货弹框
  34. */
  35. hideSendModal = () => {
  36. this.props.dispatch({
  37. type: 'orderDetail/hideDeliveryModal',
  38. });
  39. this.props.form.resetFields();
  40. }
  41. /**
  42. * 点击确认发货
  43. */
  44. confirmSend = () => {
  45. const { dispatch, form, orderDetail } = this.props;
  46. const { validateFields, getFieldsValue } = form;
  47. const { currentItem, filters } = orderDetail;
  48. const { id } = currentItem;
  49. validateFields((errors) => {
  50. if (!errors) {
  51. const { trackNo } = getFieldsValue();
  52. dispatch({
  53. type: 'orderDetail/orderSend',
  54. payload: { id, trackNo },
  55. callback: () => dispatch(routerRedux.push({
  56. pathname: `/trade/order/sub/profile/${id}`,
  57. search: queryString.stringify(filters),
  58. })),
  59. });
  60. }
  61. });
  62. }
  63. /**
  64. * 点击确认收货
  65. */
  66. confirmReceipt = () => {
  67. Modal.confirm({
  68. title: '是否确认收货?',
  69. okText: '确定',
  70. cancelText: '取消',
  71. onOk: () => {
  72. const { dispatch, orderDetail } = this.props;
  73. const { currentItem, filters } = orderDetail;
  74. const { id } = currentItem;
  75. dispatch({
  76. type: 'orderDetail/orderReceive',
  77. payload: { id },
  78. callback: () => dispatch(routerRedux.push({
  79. pathname: `/trade/order/sub/profile/${id}`,
  80. search: queryString.stringify(filters),
  81. })),
  82. });
  83. },
  84. });
  85. }
  86. /**
  87. * 根据订单状态来生成操作按钮
  88. */
  89. renderFooter = (status) => {
  90. switch (status) {
  91. // 待发货订单
  92. case Codes.CODE_FORSEND:
  93. return (
  94. <FooterToolbar>
  95. <Button onClick={this.handlePageCancel}>返回订单列表</Button>
  96. <Button onClick={this.showSendModal} type="primary">立即发货</Button>
  97. </FooterToolbar>
  98. );
  99. // 待收货订单
  100. case Codes.CODE_SENT:
  101. return (
  102. <FooterToolbar>
  103. <Button onClick={this.handlePageCancel}>返回订单列表</Button>
  104. <Button onClick={this.confirmReceipt} type="primary">确认收货</Button>
  105. </FooterToolbar>
  106. );
  107. // 已完成订单
  108. case Codes.CODE_COMPLETE:
  109. return (
  110. <FooterToolbar>
  111. <Button onClick={this.handlePageCancel}>返回订单列表</Button>
  112. </FooterToolbar>
  113. );
  114. // 已取消订单
  115. case Codes.CODE_CANCEL:
  116. return (
  117. <FooterToolbar>
  118. <Button onClick={this.handlePageCancel}>返回订单列表</Button>
  119. </FooterToolbar>
  120. );
  121. default:
  122. return (
  123. <FooterToolbar>
  124. <Button onClick={this.handlePageCancel}>返回订单列表</Button>
  125. </FooterToolbar>
  126. );
  127. }
  128. }
  129. render() {
  130. const { orderDetail, form } = this.props;
  131. const { getFieldDecorator } = form;
  132. const { currentItem, deliveryModalShow } = orderDetail;
  133. const {
  134. userCode,
  135. provinceCode,
  136. cityName,
  137. zoneName,
  138. classroomName,
  139. orderStatus,
  140. merchantName,
  141. // originPrice,
  142. // finalPrice,
  143. // adjustPrice,
  144. name,
  145. type,
  146. mobile,
  147. address,
  148. note,
  149. trackNo,
  150. goods,
  151. } = currentItem;
  152. // simply table columns
  153. const simplyTableColumns = [{
  154. title: 'field',
  155. dataIndex: 'field',
  156. key: 1,
  157. width: '20%',
  158. }, {
  159. title: 'value',
  160. dataIndex: 'value',
  161. key: 2,
  162. width: '80%',
  163. }];
  164. // 收货人信息 - table data
  165. const consumerInfoTableData = [{
  166. field: '购买终端编号',
  167. value: userCode,
  168. key: 1,
  169. }, {
  170. field: '购买终端名称',
  171. value: `${classroomName}`,
  172. key: 2,
  173. }, {
  174. field: '终端所属校区',
  175. value: `${provCodeToName(provinceCode)}-${cityName}-${zoneName}`,
  176. key: 3,
  177. }, {
  178. field: '终端所属渠道',
  179. value: merchantName,
  180. key: 4,
  181. }, {
  182. field: '收货人姓名',
  183. value: name,
  184. key: 5,
  185. }, {
  186. field: '收货人电话',
  187. value: mobile,
  188. key: 6,
  189. }, {
  190. field: '收货地址',
  191. value: address,
  192. key: 7,
  193. }];
  194. // 物流信息 - table datas
  195. const deliveryTableData = [{
  196. field: '物流单号',
  197. value: trackNo,
  198. key: 1,
  199. }];
  200. // 商品清单
  201. const goodsTableColumns = [{
  202. title: '商品编号',
  203. dataIndex: 'code',
  204. key: 1,
  205. width: '25%',
  206. }, {
  207. title: '商品名称',
  208. dataIndex: 'name',
  209. key: 2,
  210. width: '25%',
  211. }, {
  212. title: '商品类型',
  213. dataIndex: 'type',
  214. render: text => productType[text],
  215. key: 3,
  216. width: '15%',
  217. }, {
  218. title: '商品价格',
  219. key: 4,
  220. render: (_, record) => {
  221. const { chargeUnit, merchantPrice } = record;
  222. return `¥${merchantPrice}/${chargeUnit}`;
  223. },
  224. width: '25%',
  225. }, {
  226. title: '商品数量',
  227. dataIndex: 'quantity',
  228. key: 5,
  229. width: '10%',
  230. }];
  231. // 结算信息 - table data
  232. /*
  233. const strs = [];
  234. (goods || []).forEach(item => strs.push(`${item.merchantPrice}(元) * ${item.quantity}`));
  235. const accountTableDatas = [{
  236. field: '商品总价',
  237. value: `${strs.join(' + ')} = ${originPrice}(元)`,
  238. key: 1,
  239. }, {
  240. field: '支付金额',
  241. value:
  242. <span>
  243. {`总价:${originPrice}(元) - 商品优惠:${adjustPrice}(元) = 订单总金额:`}
  244. <strong style={{ color: 'red' }}>{`${finalPrice}(元)`}</strong>
  245. </span>,
  246. key: 2,
  247. }];
  248. */
  249. const entityStepMap = {
  250. [Codes.CODE_UNPAID]: 0,
  251. [Codes.CODE_PAID]: 1,
  252. [Codes.CODE_FORSEND]: 1,
  253. [Codes.CODE_SENT]: 2,
  254. [Codes.CODE_RECEIVED]: 3,
  255. [Codes.CODE_CANCEL]: 4,
  256. [Codes.CODE_COMPLETE]: 4,
  257. };
  258. const virtualStepMap = {
  259. [Codes.CODE_UNPAID]: 0,
  260. [Codes.CODE_PAID]: 1,
  261. [Codes.CODE_FORSEND]: 1,
  262. [Codes.CODE_SENT]: 1,
  263. [Codes.CODE_RECEIVED]: 1,
  264. [Codes.CODE_CANCEL]: 4,
  265. [Codes.CODE_COMPLETE]: 4,
  266. };
  267. const formItemLayout = {
  268. labelCol: { span: 7 },
  269. wrapperCol: { span: 15 },
  270. };
  271. return (
  272. <PageHeaderLayout title="子订单详情">
  273. {type === Codes.CODE_ENTITY ?
  274. (
  275. <Card title="订单状态" bordered={false} style={{ marginBottom: 20 }}>
  276. <Steps current={entityStepMap[orderStatus]}>
  277. <Steps.Step title="提交订单" icon={<Icon type="schedule" />} />
  278. <Steps.Step title="付款成功" icon={<Icon type="red-envelope" />} />
  279. <Steps.Step title="商品出库" icon={<Icon type="inbox" />} />
  280. <Steps.Step title="等待收货" icon={<Icon type="rocket" />} />
  281. <Steps.Step title="完成" icon={<Icon type="check" />} />
  282. </Steps>
  283. </Card>
  284. )
  285. :
  286. (
  287. <Card title="订单状态" bordered={false} style={{ marginBottom: 20 }}>
  288. <Steps current={virtualStepMap[orderStatus]}>
  289. <Steps.Step title="提交订单" icon={<Icon type="schedule" />} />
  290. <Steps.Step title="付款成功" icon={<Icon type="red-envelope" />} />
  291. <Steps.Step title="完成" icon={<Icon type="check" />} />
  292. </Steps>
  293. </Card>
  294. )
  295. }
  296. <Card title="商品清单" bordered={false} style={{ marginBottom: 20 }}>
  297. <Table
  298. size="small"
  299. rowKey={record => record.id}
  300. columns={goodsTableColumns}
  301. dataSource={goods || []}
  302. bordered
  303. pagination={false}
  304. />
  305. </Card>
  306. <Card title="收货人信息" bordered={false} style={{ marginBottom: 20 }}>
  307. <Table
  308. size="small"
  309. columns={simplyTableColumns}
  310. dataSource={consumerInfoTableData}
  311. bordered
  312. pagination={false}
  313. showHeader={false}
  314. />
  315. </Card>
  316. {orderStatus === Codes.CODE_SENT ?
  317. (
  318. <Card title="物流信息" bordered={false} style={{ marginBottom: 20 }}>
  319. <Table
  320. size="small"
  321. columns={simplyTableColumns}
  322. dataSource={deliveryTableData}
  323. bordered
  324. pagination={false}
  325. showHeader={false}
  326. />
  327. </Card>
  328. ) : null}
  329. <Card title="订单备注" bordered={false} style={{ marginBottom: 20 }}>
  330. {note || '无'}
  331. </Card>
  332. {/* <Card title="结算信息" bordered={false}>
  333. <Table
  334. size="small"
  335. columns={simplyTableColumns}
  336. dataSource={accountTableDatas}
  337. bordered
  338. pagination={false}
  339. showHeader={false}
  340. />
  341. </Card> */}
  342. <Modal
  343. title="发货信息"
  344. visible={deliveryModalShow}
  345. onOk={this.confirmSend}
  346. onCancel={this.hideSendModal}
  347. >
  348. <Form layout="horizontal">
  349. <Form.Item label="物流单号:" hasFeedback {...formItemLayout}>
  350. {getFieldDecorator('trackNo', {
  351. rules: [{ required: true, type: 'string', message: '请填写正确的物流单号!' }],
  352. })(<Input placeholder="请填写物流单号" />)}
  353. </Form.Item>
  354. </Form>
  355. </Modal>
  356. {this.renderFooter(orderStatus)}
  357. </PageHeaderLayout>
  358. );
  359. }
  360. }