page.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { getMap, formatMoney, formatDate } from '@src/services/Tools';
  5. import UserLayout from '../../../layouts/User';
  6. import menu from '../index';
  7. import UserTable from '../../../components/UserTable';
  8. import { Order } from '../../../stores/order';
  9. import { RecordSource, ServiceKey } from '../../../../Constant';
  10. const RecordSourceMap = getMap(RecordSource, 'value', 'label');
  11. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  12. const columns = [
  13. { title: '订单编号', key: 'orderId' },
  14. {
  15. title: '服务',
  16. key: 'title',
  17. render: (text, record) => {
  18. if (record.productType === 'course-package') {
  19. return (record.coursePackage || {}).title;
  20. }
  21. if (record.productType === 'course') {
  22. return (record.course || {}).title;
  23. }
  24. if (record.productType === 'data') {
  25. return (record.data || {}).title;
  26. }
  27. if (record.productType === 'service') {
  28. return `${ServiceKeyMap[text]}`;
  29. }
  30. return '';
  31. },
  32. },
  33. {
  34. title: '购买时间',
  35. key: 'createTime',
  36. render: (text) => {
  37. return formatDate(text, 'YYYY-MM-DD\nHH:mm:ss');
  38. },
  39. },
  40. {
  41. title: '付款方式',
  42. key: 'source',
  43. render: (text) => {
  44. return RecordSourceMap[text];
  45. },
  46. },
  47. {
  48. title: '付款金额',
  49. key: 'money',
  50. render: (text) => {
  51. return formatMoney(text);
  52. },
  53. },
  54. ];
  55. export default class extends Page {
  56. constructor(props) {
  57. props.size = 15;
  58. super(props);
  59. }
  60. initState() {
  61. return {};
  62. }
  63. initData() {
  64. Order.list(this.state.search)
  65. .then(result => {
  66. this.setState({ list: result.list, total: result.total, page: this.state.search.page });
  67. });
  68. }
  69. onChangePage(page) {
  70. this.search({ page });
  71. }
  72. renderView() {
  73. const { config } = this.props;
  74. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  75. }
  76. renderTable() {
  77. const { list, total, page } = this.state;
  78. return (
  79. <div className="table-layout">
  80. <UserTable
  81. size="small"
  82. columns={columns}
  83. data={list}
  84. onChange={p => this.onChangePage(p)}
  85. total={total}
  86. current={page}
  87. />
  88. </div>
  89. );
  90. }
  91. }