page.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import React from 'react';
  2. // import { Link } from 'react-router-dom';
  3. // import { Button } from 'antd';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import FilterLayout from '@src/layouts/FilterLayout';
  8. import ActionLayout from '@src/layouts/ActionLayout';
  9. import TableLayout from '@src/layouts/TableLayout';
  10. import { asyncSMessage, asyncDelConfirm, asyncForm } from '@src/services/AsyncTools';
  11. import { getMap } from '@src/services/Tools';
  12. import { Ready } from '../../../stores/ready';
  13. import { RoomPosition } from '../../../../Constant';
  14. const RoomPositionMap = getMap(RoomPosition, 'value', 'label');
  15. export default class extends Page {
  16. init() {
  17. this.filterForm = [{
  18. key: 'position',
  19. type: 'select',
  20. allowClear: true,
  21. name: '区域',
  22. placeholder: '请选择',
  23. select: RoomPosition,
  24. onChange: (text) => {
  25. this.changeSearch(this.filterForm, this, text);
  26. },
  27. }, {
  28. key: 'areaId',
  29. type: 'select',
  30. allowClear: true,
  31. name: '省份',
  32. select: [],
  33. number: true,
  34. placeholder: '请选择',
  35. }];
  36. this.formF = null;
  37. this.itemList = [{
  38. key: 'id',
  39. type: 'hidden',
  40. }, {
  41. key: 'position',
  42. type: 'select',
  43. name: '区域',
  44. select: RoomPosition,
  45. onChange: (text) => {
  46. this.changeSearch(this.itemList, this.formF, text, 2);
  47. },
  48. required: true,
  49. }, {
  50. key: 'areaId',
  51. type: 'select',
  52. name: '省份',
  53. select: [],
  54. required: true,
  55. }, {
  56. key: 'title',
  57. type: 'input',
  58. name: '考场',
  59. required: true,
  60. }, {
  61. key: 'address',
  62. type: 'input',
  63. name: '地址',
  64. required: true,
  65. }, {
  66. key: 'description',
  67. type: 'textarea',
  68. name: '详细说明',
  69. }];
  70. this.actionList = [{
  71. key: 'add',
  72. type: 'primary',
  73. name: '创建',
  74. }];
  75. this.columns = [{
  76. title: '区域',
  77. dataIndex: 'position',
  78. render: (text) => {
  79. return RoomPositionMap[text] || '';
  80. },
  81. }, {
  82. title: '省份',
  83. dataIndex: 'areaId',
  84. render: (text) => {
  85. return this.areaMap[text] || '';
  86. },
  87. }, {
  88. title: '考场',
  89. dataIndex: 'title',
  90. }, {
  91. title: '地址',
  92. dataIndex: 'address',
  93. }, {
  94. title: '操作',
  95. dataIndex: 'handler',
  96. render: (text, record) => {
  97. return <div className="table-button">
  98. {<a onClick={() => {
  99. this.editAction(record);
  100. }}>编辑</a>}
  101. {<a onClick={() => {
  102. this.deleteAction(record);
  103. }}>删除</a>}
  104. </div>;
  105. },
  106. }];
  107. Ready.allArea().then(result => {
  108. this.areaList = result.map(row => {
  109. row.value = row.id;
  110. return row;
  111. });
  112. this.areaMap = getMap(result, 'id', 'title');
  113. this.changeSearch(this.filterForm, this, this.state.search.position);
  114. });
  115. }
  116. changeSearch(list, component, value, index = 1) {
  117. if (value) {
  118. list[index].select = this.areaList.filter(row => row.position === value);
  119. list[index].disabled = list[index].select.length === 0;
  120. list[index].required = list[index].select.length > 0;
  121. } else {
  122. list[index].disabled = true;
  123. list[index].required = false;
  124. list[index].select = [];
  125. }
  126. component.setState({ load: false });
  127. }
  128. initData() {
  129. Ready.listRoom(this.state.search).then(result => {
  130. this.setTableData(result.list, result.total);
  131. });
  132. }
  133. addAction() {
  134. asyncForm('创建', this.itemList, {}, data => {
  135. data.isOverseas = data.position === 'overseas' ? 1 : 0;
  136. return Ready.addRoom(data).then(() => {
  137. asyncSMessage('添加成功!');
  138. this.refresh();
  139. });
  140. }).then(component => {
  141. this.formF = component;
  142. this.changeSearch(this.itemList, this.formF, null, 2);
  143. });
  144. }
  145. editAction(row) {
  146. asyncForm('编辑', this.itemList, row, data => {
  147. data.isOverseas = data.position === 'overseas' ? 1 : 0;
  148. return Ready.editRoom(data).then(() => {
  149. asyncSMessage('编辑成功!');
  150. this.refresh();
  151. });
  152. }).then(component => {
  153. this.formF = component;
  154. this.changeSearch(this.itemList, this.formF, row.position, 2);
  155. });
  156. }
  157. deleteAction(row) {
  158. asyncDelConfirm('删除确认', '是否删除选中?', () => {
  159. const handler = Ready.delRoom({ id: row.id });
  160. return handler.then(() => {
  161. asyncSMessage('删除成功!');
  162. this.refresh();
  163. });
  164. });
  165. }
  166. renderView() {
  167. return <Block flex>
  168. <FilterLayout
  169. show
  170. itemList={this.filterForm}
  171. data={this.state.search}
  172. onChange={data => {
  173. data.page = 1;
  174. this.search(data);
  175. }} />
  176. <ActionLayout
  177. itemList={this.actionList}
  178. selectedKeys={this.state.selectedKeys}
  179. onAction={key => this.onAction(key)}
  180. />
  181. <TableLayout
  182. columns={this.tableSort(this.columns)}
  183. list={this.state.list}
  184. pagination={this.state.page}
  185. loading={this.props.core.loading}
  186. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  187. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  188. selectedKeys={this.state.selectedKeys}
  189. />
  190. </Block>;
  191. }
  192. }