page.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. key: 'irScore',
  42. type: 'number',
  43. name: 'IR分',
  44. }, {
  45. key: 'irRank',
  46. type: 'number',
  47. name: 'IR排名',
  48. }];
  49. this.columns = [{
  50. title: '总分',
  51. dataIndex: 'totalScore',
  52. }, {
  53. title: '总排名',
  54. dataIndex: 'totalRank',
  55. }, {
  56. title: 'Q分',
  57. dataIndex: 'quantScore',
  58. }, {
  59. title: 'Q排名',
  60. dataIndex: 'quantRank',
  61. }, {
  62. title: 'IR分',
  63. dataIndex: 'irScore',
  64. }, {
  65. title: 'IR排名',
  66. dataIndex: 'irRank',
  67. }];
  68. this.actionList = [{
  69. key: 'import',
  70. name: '批量导入',
  71. render: (item) => {
  72. return <Upload
  73. showUploadList={false}
  74. beforeUpload={(file) => System.importRank(file).then((result) => {
  75. asyncSMessage(result);
  76. })}
  77. >
  78. <Button>{item.name}</Button>
  79. </Upload>;
  80. },
  81. }, {
  82. key: 'del',
  83. name: '批量删除',
  84. type: 'danger',
  85. needSelect: 1,
  86. }];
  87. }
  88. initData() {
  89. System.listRank().then(result => {
  90. this.setState({ list: result });
  91. });
  92. }
  93. addAction() {
  94. asyncForm('新增', this.itemList, {}, data => {
  95. return System.addRank(data).then(() => {
  96. asyncSMessage('新增成功!');
  97. this.refresh();
  98. });
  99. });
  100. }
  101. editRow(row) {
  102. asyncForm('编辑', this.itemList, row, data => {
  103. return System.editRank(data).then(() => {
  104. asyncSMessage('编辑成功!');
  105. this.refresh();
  106. });
  107. });
  108. }
  109. delAction() {
  110. const { selectedKeys } = this.state;
  111. asyncDelConfirm('删除确认', '是否删除选中数据?', () => {
  112. return Promise.all(selectedKeys.map(row => System.delRank({ id: row })));
  113. }).then(() => {
  114. asyncSMessage('操作成功!');
  115. this.refresh();
  116. });
  117. }
  118. renderView() {
  119. return <Block flex>
  120. <ActionLayout
  121. itemList={this.actionList}
  122. selectedKeys={this.state.selectedKeys}
  123. onAction={key => this.onAction(key)}
  124. />
  125. <TableLayout
  126. columns={this.columns}
  127. list={this.state.list}
  128. pagination={false}
  129. loading={this.props.core.loading}
  130. />
  131. </Block>;
  132. }
  133. }