page.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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: 'V分',
  63. dataIndex: 'verbalScore',
  64. }, {
  65. title: 'V排名',
  66. dataIndex: 'verbalRank',
  67. }, {
  68. title: 'IR分',
  69. dataIndex: 'irScore',
  70. }, {
  71. title: 'IR排名',
  72. dataIndex: 'irRank',
  73. }];
  74. this.actionList = [{
  75. key: 'import',
  76. name: '批量导入',
  77. render: (item) => {
  78. return <Upload
  79. showUploadList={false}
  80. beforeUpload={(file) => System.importRank({ file }).then((result) => {
  81. asyncSMessage(`导入: ${result}条数据,数据正在更新中,请勿重新提交`);
  82. this.refresh();
  83. return Promise.reject();
  84. }).catch(e => {
  85. asyncSMessage(e.message, 'error');
  86. return Promise.reject();
  87. })}
  88. >
  89. <Button>{item.name}</Button>
  90. </Upload>;
  91. },
  92. }, {
  93. key: 'del',
  94. name: '批量删除',
  95. type: 'danger',
  96. needSelect: 1,
  97. }];
  98. }
  99. initData() {
  100. System.listRank(this.state.search).then(result => {
  101. this.setTableData(result.list, result.total);
  102. });
  103. }
  104. addAction() {
  105. asyncForm('新增', this.itemList, {}, data => {
  106. return System.addRank(data).then(() => {
  107. asyncSMessage('新增成功!');
  108. this.refresh();
  109. });
  110. });
  111. }
  112. editRow(row) {
  113. asyncForm('编辑', this.itemList, row, data => {
  114. return System.editRank(data).then(() => {
  115. asyncSMessage('编辑成功!');
  116. this.refresh();
  117. });
  118. });
  119. }
  120. delAction() {
  121. const { selectedKeys } = this.state;
  122. asyncDelConfirm('删除确认', '是否删除选中数据?', () => {
  123. return Promise.all(selectedKeys.map(row => System.delRank({ id: row }))).then(() => {
  124. asyncSMessage('操作成功!');
  125. this.refresh();
  126. });
  127. });
  128. }
  129. renderView() {
  130. return <Block flex>
  131. <ActionLayout
  132. itemList={this.actionList}
  133. selectedKeys={this.state.selectedKeys}
  134. onAction={key => this.onAction(key)}
  135. />
  136. <TableLayout
  137. columns={this.tableSort(this.columns)}
  138. list={this.state.list}
  139. pagination={this.state.page}
  140. loading={this.props.core.loading}
  141. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  142. />
  143. </Block>;
  144. }
  145. }