/* eslint-disable no-param-reassign,no-trailing-spaces */ import React, { Component } from 'react'; import pathToRegexp from 'path-to-regexp'; import moment from 'moment'; import { Card, Modal, Form, DatePicker, Button, List } from 'antd'; import { connect } from 'dva'; import { routerRedux } from 'dva/router'; import Selector from '../../../components/AXTableSelector/Selector'; import FooterToolbar from '../../../components/FooterToolbar'; import { Hotax } from '../../../utils/config'; const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 9 }, }, wrapperCol: { xs: { span: 24 }, sm: { span: 14 }, md: { span: 10 }, }, }; @Form.create() @connect(({ loading, terminal }) => ({ terminal, tLoading: loading.models.terminal, })) export default class WhiteListCreatePage extends Component { state = { terminalSelectorDestroy: true, }; componentDidMount() { const matchId = this.isEdit(); if (matchId) { this.props.dispatch({ type: 'terminal/fetchSpecialTerminalItem', payload: { userId: matchId }, }); } else { this.props.dispatch({ type: 'terminal/fetchTerminalList', payload: {}, }); } } componentWillUnmount() { this.props.dispatch({ type: 'terminal/cleanState', }); } handleTerminalSelectorModalShow = () => { this.setState({ terminalSelectorDestroy: false, }); this.props.dispatch({ type: 'terminal/fetchTerminalList', payload: {}, }); } handleTerminalSelectorFinish = (rows) => { this.setState({ terminalSelectorDestroy: true, }); if (!rows || !rows.length) { return; } const { id, code, merchantName } = rows[0]; this.props.dispatch({ type: 'terminal/fixCurrentItem', payload: { code, merchantName, userId: id, }, }); }; handleTerminalSelectorCancel = () => { this.setState({ terminalSelectorDestroy: true, }); }; handleTerminalSelectorChange = (params) => { this.props.dispatch({ type: 'terminal/fetchTerminalList', payload: params, }); } isEdit = () => { const { location } = this.props; const match = pathToRegexp('/terminal/whitelist/edit/:id').exec(location.pathname); if (match) { return match[1]; } return false; } handlePageSubmit = () => { this.props.form.validateFieldsAndScroll((error, values) => { if (!error) { const { terminal } = this.props; const { currentItem } = terminal; const { id, code, userId, status } = currentItem; values = { id, code, userId, status, ...values }; // 编辑模式 if (this.isEdit()) { this.props.dispatch({ type: 'terminal/updateSpecialTerminalItem', payload: values, states: this.props.location.state, }); // 创建模式 } else { delete values.id; values.status = Hotax.STATUS_NORMAL; this.props.dispatch({ type: 'terminal/createSpecialTerminalItem', payload: values, states: this.props.location.state, }); } } }); } handlePageBack = () => { this.props.dispatch(routerRedux.push({ pathname: '/terminal/whitelist', state: this.props.location.state, })); } render() { const { terminalSelectorDestroy } = this.state; const { form, tLoading, terminal } = this.props; const { getFieldDecorator } = form; const { currentItem } = terminal; const { code, merchantName, startTime, endTime } = currentItem; const getTerminalModal = () => { return ( ); }; return (
选择终端 : '终端账号'} {...formItemLayout} > {item}} style={{ width: 280 }} /> {getFieldDecorator('startTime', { rules: [{ required: true, message: '请选择起始日期' }], initialValue: startTime && moment(startTime), })( )} {getFieldDecorator('endTime', { initialValue: endTime && moment(endTime), })( )}
{!terminalSelectorDestroy && getTerminalModal()}
); } }