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
; }, }]; 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