import React, { PureComponent } from 'react';
import { message, Card, Modal, List, Form, Input, Button, Icon, Switch } from 'antd';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import Selector from '../../../components/AXTableSelector/Selector';
import FooterToolbar from '../../../components/FooterToolbar';
import { boolToStatus } from '../../../utils/utils';
const Message = message;
const fieldLabels = {
campus: '所属校区',
name: '终端名称',
password: '终端密码',
confirm: '确认密码',
status: '初始状态',
};
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 7 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 14 },
md: { span: 10 },
},
};
@Form.create()
@connect(({ loading, terminal, campus }) => ({
campus,
terminal,
cLoading: loading.models.campus,
submitting: loading.models.terminal,
}))
export default class TerminalCreatePage extends PureComponent {
state = {
campusSelectorDestroy: true,
};
componentWillUnmount() {
this.props.dispatch({
type: 'terminal/cleanState',
});
}
checkPassword = (rule, value, callback) => {
if (value && value !== this.props.form.getFieldValue('password')) {
callback('两次输入的密码不一致');
} else {
callback();
}
};
handleCampusSelectorModalShow = () => {
this.setState({
campusSelectorDestroy: false,
});
this.props.dispatch({
type: 'campus/fetchCampusList',
payload: {},
});
};
handleCampusSelectorFinish = (rows) => {
this.setState({
campusSelectorDestroy: true,
});
if (!rows || !rows.length) {
return;
}
const { id, code, name, merchantName } = rows[0];
this.props.dispatch({
type: 'terminal/fixCurrentItem',
payload: {
merchantName,
campusId: id,
campusCode: code,
campusName: name,
},
});
};
handleCampusSelectorCancel = () => {
this.setState({
campusSelectorDestroy: true,
});
};
handleCampusSelectorChange = (params) => {
this.props.dispatch({
type: 'campus/fetchCampusList',
payload: params,
});
};
handlePageSubmit = () => {
this.props.form.validateFieldsAndScroll((error, values) => {
const { currentItem } = this.props.terminal;
const { campusId } = currentItem;
if (!campusId) {
Message.error('请选择校区');
return;
}
const { status, ...restProps } = values;
restProps.status = boolToStatus(status);
restProps.campusId = campusId;
if (!error) {
this.props.dispatch({
type: 'terminal/createTerminalItem',
payload: restProps,
states: this.props.location.state,
});
}
});
};
handlePageBack = () => {
this.props.dispatch(routerRedux.push({
pathname: '/terminal/user/list',
state: this.props.location.state,
}));
};
render() {
const { campusSelectorDestroy } = this.state;
const { form, cLoading, submitting, campus, terminal } = this.props;
const { getFieldDecorator } = form;
const { currentItem } = terminal;
const { campusCode, campusName, merchantName } = currentItem;
const getCampusModal = () => {
return (