123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import React from 'react';
- // import { Link } from 'react-router-dom';
- // import { Button } from 'antd';
- import './index.less';
- import Page from '@src/containers/Page';
- import Block from '@src/components/Block';
- import FilterLayout from '@src/layouts/FilterLayout';
- import ActionLayout from '@src/layouts/ActionLayout';
- import TableLayout from '@src/layouts/TableLayout';
- import { asyncSMessage, asyncDelConfirm, asyncForm } from '@src/services/AsyncTools';
- import { getMap } from '@src/services/Tools';
- import { Ready } from '../../../stores/ready';
- import { RoomPosition } from '../../../../Constant';
- const RoomPositionMap = getMap(RoomPosition, 'value', 'label');
- export default class extends Page {
- init() {
- this.filterForm = [{
- key: 'position',
- type: 'select',
- allowClear: true,
- name: '区域',
- placeholder: '请选择',
- select: RoomPosition,
- onChange: (text) => {
- this.changeSearch(this.filterForm, this, text);
- },
- }, {
- key: 'areaId',
- type: 'select',
- allowClear: true,
- name: '省份',
- select: [],
- number: true,
- placeholder: '请选择',
- }];
- this.formF = null;
- this.itemList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'position',
- type: 'select',
- name: '区域',
- select: RoomPosition,
- onChange: (text) => {
- this.changeSearch(this.itemList, this.formF, text, 2);
- },
- required: true,
- }, {
- key: 'areaId',
- type: 'select',
- name: '省份',
- select: [],
- required: true,
- }, {
- key: 'title',
- type: 'input',
- name: '考场',
- required: true,
- }, {
- key: 'address',
- type: 'input',
- name: '地址',
- required: true,
- }, {
- key: 'description',
- type: 'textarea',
- name: '详细说明',
- }];
- this.actionList = [{
- key: 'add',
- type: 'primary',
- name: '创建',
- }];
- this.columns = [{
- title: '区域',
- dataIndex: 'position',
- render: (text) => {
- return RoomPositionMap[text] || '';
- },
- }, {
- title: '省份',
- dataIndex: 'areaId',
- render: (text) => {
- return this.areaMap[text] || '';
- },
- }, {
- title: '考场',
- dataIndex: 'title',
- }, {
- title: '地址',
- dataIndex: 'address',
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {<a onClick={() => {
- this.editAction(record);
- }}>编辑</a>}
- {<a onClick={() => {
- this.deleteAction(record);
- }}>删除</a>}
- </div>;
- },
- }];
- Ready.allArea().then(result => {
- this.areaList = result.map(row => {
- row.value = row.id;
- return row;
- });
- this.areaMap = getMap(result, 'id', 'title');
- this.changeSearch(this.filterForm, this, this.state.search.position);
- });
- }
- changeSearch(list, component, value, index = 1) {
- if (value) {
- list[index].select = this.areaList.filter(row => row.position === value);
- list[index].disabled = list[index].select.length === 0;
- list[index].required = list[index].select.length > 0;
- } else {
- list[index].disabled = true;
- list[index].required = false;
- list[index].select = [];
- }
- component.setState({ load: false });
- }
- initData() {
- Ready.listRoom(this.state.search).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- addAction() {
- asyncForm('创建', this.itemList, {}, data => {
- data.isOverseas = data.position === 'overseas' ? 1 : 0;
- return Ready.addRoom(data).then(() => {
- asyncSMessage('添加成功!');
- this.refresh();
- });
- }).then(component => {
- this.formF = component;
- this.changeSearch(this.itemList, this.formF, null, 2);
- });
- }
- editAction(row) {
- asyncForm('编辑', this.itemList, row, data => {
- data.isOverseas = data.position === 'overseas' ? 1 : 0;
- return Ready.editRoom(data).then(() => {
- asyncSMessage('编辑成功!');
- this.refresh();
- });
- }).then(component => {
- this.formF = component;
- this.changeSearch(this.itemList, this.formF, row.position, 2);
- });
- }
- deleteAction(row) {
- asyncDelConfirm('删除确认', '是否删除选中?', () => {
- const handler = Ready.delRoom({ id: row.id });
- return handler.then(() => {
- asyncSMessage('删除成功!');
- this.refresh();
- });
- });
- }
- renderView() {
- return <Block flex>
- <FilterLayout
- show
- itemList={this.filterForm}
- data={this.state.search}
- onChange={data => {
- data.page = 1;
- this.search(data);
- }} />
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- columns={this.tableSort(this.columns)}
- list={this.state.list}
- pagination={this.state.page}
- loading={this.props.core.loading}
- onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
- onSelect={(keys, rows) => this.tableSelect(keys, rows)}
- selectedKeys={this.state.selectedKeys}
- />
- </Block>;
- }
- }
|