page.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React from 'react';
  2. import { Button, Upload } from 'antd';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import ActionLayout from '@src/layouts/ActionLayout';
  7. import TableLayout from '@src/layouts/TableLayout';
  8. import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools';
  9. import { System } from '../../../stores/system';
  10. export default class extends Page {
  11. constructor(props) {
  12. super(props);
  13. this.itemList = [{
  14. key: 'id',
  15. type: 'hidden',
  16. }, {
  17. key: 'totalScore',
  18. type: 'number',
  19. name: '总分',
  20. }, {
  21. key: 'totalRank',
  22. type: 'number',
  23. name: '总排名',
  24. }, {
  25. key: 'quantScore',
  26. type: 'number',
  27. name: 'Q分',
  28. }, {
  29. key: 'quantRank',
  30. type: 'number',
  31. name: 'Q排名',
  32. }, {
  33. key: 'verbalScore',
  34. type: 'number',
  35. name: 'V分',
  36. }, {
  37. key: 'verbalRank',
  38. type: 'number',
  39. name: 'V排名',
  40. }];
  41. this.columns = [{
  42. title: '总分',
  43. dataIndex: 'totalScore',
  44. }, {
  45. title: '总排名',
  46. dataIndex: 'totalRank',
  47. }, {
  48. title: 'Q分',
  49. dataIndex: 'quantScore',
  50. }, {
  51. title: 'Q排名',
  52. dataIndex: 'quantRank',
  53. }, {
  54. title: 'V分',
  55. dataIndex: 'verbalScore',
  56. }, {
  57. title: 'V排名',
  58. dataIndex: 'verbalRank',
  59. }];
  60. this.actionList = [{
  61. key: 'import',
  62. name: '批量导入',
  63. render: (item) => {
  64. return <Upload
  65. showUploadList={false}
  66. beforeUpload={(file) => System.importRank(file).then((result) => {
  67. asyncSMessage(result);
  68. })}
  69. >
  70. <Button>{item.name}</Button>
  71. </Upload>;
  72. },
  73. }, {
  74. key: 'del',
  75. name: '批量删除',
  76. type: 'danger',
  77. needSelect: 1,
  78. }];
  79. }
  80. initData() {
  81. System.listRank().then(result => {
  82. this.setState({ list: result });
  83. });
  84. }
  85. addAction() {
  86. asyncForm('新增', this.itemList, {}, data => {
  87. return System.addRank(data).then(() => {
  88. asyncSMessage('新增成功!');
  89. this.refresh();
  90. });
  91. });
  92. }
  93. editRow(row) {
  94. asyncForm('编辑', this.itemList, row, data => {
  95. return System.editRank(data).then(() => {
  96. asyncSMessage('编辑成功!');
  97. this.refresh();
  98. });
  99. });
  100. }
  101. delAction() {
  102. const { selectedKeys } = this.state;
  103. asyncDelConfirm('删除确认', '是否删除选中数据?', () => {
  104. return Promise.all(selectedKeys.map(row => System.delRank({ id: row })));
  105. }).then(() => {
  106. asyncSMessage('操作成功!');
  107. this.refresh();
  108. });
  109. }
  110. renderView() {
  111. return <Block flex>
  112. <ActionLayout
  113. itemList={this.actionList}
  114. selectedKeys={this.state.selectedKeys}
  115. onAction={key => this.onAction(key)}
  116. />
  117. <TableLayout
  118. columns={this.columns}
  119. list={this.state.list}
  120. pagination={false}
  121. loading={this.props.core.loading}
  122. />
  123. </Block>;
  124. }
  125. }