/* eslint-disable array-callback-return,no-undef */
import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import { Layout, Spin, Button, Row, Col } from 'antd-v4';
import CommonListEvent from './CommonListEvent';/* 继承销售模块业务功能 */
import * as commonFunc from './commonFunc';/* 通用单据方法 */ /* 通用单据方法 */
import StaticEditTable from './CommonTable';/* 可编辑表格 */
import CommonBase from './CommonBase';/* 获取配置及数据 */
import * as commonBusiness from './commonBusiness';/* 单据业务功能 */
import SearchComponent from './SearchComponent';/* 搜索组件 */
import commonConfig from '../../utils/config';

const { Content } = Layout;

class ProductionPlanChangeMachineInfoComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }
  /**   确认下单   */
  handleSelect = () => {
    const { slaveSelectedData, app } = this.props;
    this.props.app.currentPane.select(app.currentPane.name, app.currentPane.config, slaveSelectedData);
    this.props.app.currentPane.selectCancel(app.currentPane.name);
  };
  /**   关闭   */
  handleCancelModal = () => {
    const { app } = this.props;
    this.props.app.currentPane.selectCancel(app.currentPane.name);
  };
  // ----------------------------数据修改回带end  ---------------------------- //

  render() {
    const { pageLoading } = this.props;
    return (
      <div style={{ height: '100%' }}>
        <Spin spinning={pageLoading}>
          <div style={{ height: '100%' }}>
            <CommonListComponent
              {...this.props}
              {...this.state}
              onSelect={this.handleSelect}
              onCancel={this.handleCancelModal}
              onDoubleClick={this.handleSelect}
            />
          </div>
        </Spin>
      </div>
    );
  }
}

const CommonListComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const { form, onReturnForm, slavePagination } = props;
  /*   回带表单   */
  onReturnForm(form);
  const pagination = {
    ...slavePagination,
    size: 'large',
    pageSize: commonConfig.pageSize,
    showQuickJumper: true,
    hideOnSinglePage: true,
  };
  const tableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    tableProps: { rowKey: 'sId', pagination, onChange: props.onTitleChange },
  };
  const teamProps = {
    ...commonBusiness.getTableTypes('team', props),
    tableProps: { rowKey: 'sId', pagination, onChange: props.onTitleChange },
  };
  return (
    <Form >
      <Layout>
        <Layout>
          <div id="modalChooseProcess">
            <div style={{ maxHeight: '100%', zIndex: 20 }}>
              <SearchComponent {...props} />
            </div>
            <Content className="xly-normal-list">
              <Row>
                <Col span={24} key="{groupProps.name}Col" >
                  <StaticEditTable {...tableProps} footer="hidden" tableBelone="list" showConfig={props.showConfig} />
                </Col>
                <Col span={24} key="{groupProps.name}Col" >
                  <StaticEditTable {...teamProps} footer="hidden" tableBelone="list" showConfig={props.showConfig} />
                </Col>
              </Row>
            </Content>
          </div>
        </Layout>
        <div style={{ textAlign: 'right', marginRight: '9px', marginBottom: '9px' }}>
          <Button key="back" style={{ marginRight: '8px' }} onClick={props.onCancel}>取消</Button>
          <Button type="primary" onClick={props.onSelect}>确认</Button>
        </div>
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonListEvent(ProductionPlanChangeMachineInfoComponent));
