page.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. return Promise.reject();
  77. })}
  78. >
  79. <Button>{item.name}</Button>
  80. </Upload>;
  81. },
  82. }, {
  83. key: 'del',
  84. name: '批量删除',
  85. type: 'danger',
  86. needSelect: 1,
  87. }];
  88. }
  89. initData() {
  90. System.listRank().then(result => {
  91. this.setState({ list: result });
  92. });
  93. }
  94. addAction() {
  95. asyncForm('新增', this.itemList, {}, data => {
  96. return System.addRank(data).then(() => {
  97. asyncSMessage('新增成功!');
  98. this.refresh();
  99. });
  100. });
  101. }
  102. editRow(row) {
  103. asyncForm('编辑', this.itemList, row, data => {
  104. return System.editRank(data).then(() => {
  105. asyncSMessage('编辑成功!');
  106. this.refresh();
  107. });
  108. });
  109. }
  110. delAction() {
  111. const { selectedKeys } = this.state;
  112. asyncDelConfirm('删除确认', '是否删除选中数据?', () => {
  113. return Promise.all(selectedKeys.map(row => System.delRank({ id: row }))).then(() => {
  114. asyncSMessage('操作成功!');
  115. this.refresh();
  116. });
  117. });
  118. }
  119. renderView() {
  120. return <Block flex>
  121. <ActionLayout
  122. itemList={this.actionList}
  123. selectedKeys={this.state.selectedKeys}
  124. onAction={key => this.onAction(key)}
  125. />
  126. <TableLayout
  127. columns={this.tableSort(this.columns)}
  128. list={this.state.list}
  129. pagination={false}
  130. loading={this.props.core.loading}
  131. />
  132. </Block>;
  133. }
  134. }