import React from 'react';
import { connect } from 'dva';
import { Button, Row, Col, Form, Popconfirm,message} from 'antd';
import {   initFilter, } from "../../../utils/common";
import EditBaseComponent from "../../../baseComponents/EditBaseComponent";

class InitDestOrgPage extends EditBaseComponent {
  constructor(props) {
    super(props);
    this.state = {
      data: {},
    };
  };

  onLoadData(){
    const columns=[
      {controlType:1,field:'DEST_ORG_CODE',label:'目的组织编号',isRequire:true},
      {controlType:1,field:'DEST_ORG_NAME',label:'目的组织名称',isRequire:true},
    ];
    this.setEditConfig({
      editConfig:{
        columns,
      }
    });
  }





  initOrg=()=>{
    if(this.state.btnLoading)return;
    const {  form , } = this.props;
    const { validateFieldsAndScroll } = form;

    validateFieldsAndScroll((errors, values) => {
      if (errors) return;
      const json=initFilter(this.props.login.OrgId);
      json['Keyword']=this.state.data.DEST_ORG_CODE;
      json['Parameter1']=this.state.data.DEST_ORG_NAME;
      this.setState({ btnLoading: true });
      this.props.dispatch({
        type: 'PFForm/initOrgBySrcOrg',
        payload: json,
        onComplete: (ret) => {
          if(ret) {
            message.success('执行成功');
          }
          setTimeout(() => { this.setState({ btnLoading: false })}, 2000);
        }
      });
    })
  };





  render() {
    const headColumnConfig=this.getEditConfig();
    const columns= headColumnConfig?headColumnConfig.columns:[];

    return (
      <div>
        <div>
          <h2>初始化组织</h2>
        </div>
        <Form>
          <Row style={{ marginTop: '20px' }}>
            {this.createControls(columns,this.state.data)}
          </Row>

          <Row style={{ marginTop: '20px' }}>
            <Col style={{ textAlign: 'right' }}>
              <Popconfirm title="是否确定初始化?" onConfirm={this.initOrg}>
                <Button type={'primary'} icon={'check'} loading={this.state.btnLoading} >确定</Button>
              </Popconfirm>
            </Col>
          </Row>
        </Form>
      </div>
    );
  }

}

InitDestOrgPage.propTypes = {
};

export default connect(({ login, loading,custom }) => ({ login, loading,custom }))(Form.create()(InitDestOrgPage));
