/* 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, Tabs } from 'antd-v4';
import styles from '@/index.less';
import * as commonUtils from '@/utils/utils';/* 通用方法 */
import CommonBase from '@/components/Common/CommonBase';
import CommonSystemSettingEvent from '@/components/Common/CommonSystemSettingEvent';
import StaticEditTable from '@/components/Common/CommonTable';/* 可编辑表格 */
import * as commonBusiness from '@/components/Common/commonBusiness';/* 单据业务功能 */
import * as commonFunc from '@/components/Common/commonFunc';
import Toolbar from '@/components/Common/ToolBar/ToolBarNew';
import selfStyles from './index.less';
import TabFinancePeriod from './TabFinancePeriod';
import TabsSalesBuyer from './TabSalesBuyer';
import TabFinanceOffer from './TabFinanceOffer';
import TabSysParam from './TabSysParam';

const { Header, Content } = Layout;
const { TabPane } = Tabs;

class CommonSystemSetting extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
    this.form = {}; /*   表单对象   */
  }

  handleFilterData = (name, dataIndex, value, record) => {
    const { sysbillnosettingsSelectedRowKeys, sysbillnosettingsData } = this.props;
    if (name === 'syspushMsg' && commonUtils.isNotEmptyArr(sysbillnosettingsData)) {
      return commonUtils.isNotEmptyStr(record.sParentId) && sysbillnosettingsSelectedRowKeys.includes(record.sParentId);
    }
  };

  handleGetFilterData = (name) => {
    const {
      [`${name}Data`]: data, sysbillnosettingsData, sysbillnosettingsSelectedRowKeys,
    } = this.props;
    if (data !== undefined) {
      const newArr = data.filter((item) => {
        if (name === 'syspushMsg' && commonUtils.isNotEmptyArr(sysbillnosettingsData)) {
          return commonUtils.isNotEmptyStr(item.sParentId) && sysbillnosettingsSelectedRowKeys.includes(item.sParentId);
        }
      });
      return newArr.length;
    }
  };
  render() {
    const { pageLoading } = this.props;
    return (
      <div>
        <Spin spinning={pageLoading}>
          <div>
            <CommonSystemSettingComponent
              {...this.props}
              {...this.state}
              onFilterData={this.handleFilterData}
              onGetFilterData={this.handleGetFilterData}
            />
          </div>
        </Spin>
      </div>
    );
  }
}
const CommonSystemSettingComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const { form, onReturnForm, syspushMsgConfig } = props;
  /*   回带表单   */
  onReturnForm(form);
  const tableProps = {
    ...commonBusiness.getTableTypes('sysbillnosettings', props),
    tableProps: { AutoTableHeight: '70vh' },
  };

  const tableSysPushMsgProps = {
    ...commonBusiness.getTableTypes('syspushMsg', props),
    filteredValue: props.sysbillnosettingsSelectedRowKeys,
    OnGetFilterData: props.onGetFilterData,
    onFilterData: props.onFilterData,
    tableProps: { AutoTableHeight: 200 },
  };
  const AccountingPeriod = commonFunc.showLocalMessage(props, 'AccountingPeriod', '会计期间');
  const SalesProductionParameters = commonFunc.showLocalMessage(props, 'SalesProductionParameters', '销售采购生产参数');
  const FinancialWarehouseParameters = commonFunc.showLocalMessage(props, 'FinancialWarehouseParameters', '财务仓库报价参数');
  const DocumentNumberSetup= commonFunc.showLocalMessage(props, 'DocumentNumberSetup', '单据编号设置');
  const SystemSetting = commonFunc.showLocalMessage(props, 'SystemSetting', '系统参数');
  return (
    <Form>
      <Layout>
        <Header className={styles.header}>
          <Toolbar {...props} />
        </Header>
        <Layout className={styles.clayout}>
          <Content className={selfStyles.container}>
            <div>
              <Tabs className={styles.slaveTabs}>
                <TabPane tab={AccountingPeriod} key={1}>
                  <TabFinancePeriod {...props} />
                </TabPane>
                <TabPane tab={SalesProductionParameters} key={2}>
                  <TabsSalesBuyer {...props} />
                </TabPane>
                <TabPane tab={FinancialWarehouseParameters} key={3}>
                  <TabFinanceOffer {...props} />
                </TabPane>
                <TabPane tab={DocumentNumberSetup} key={4}>
                  <div className="xly-bill-list" >
                    <StaticEditTable {...tableProps} setOpterationColumn="Y" footer="hidden" />
                  </div>
                  {
                    commonUtils.isNotEmptyObject(syspushMsgConfig) ?
                      <div className="xly-bill-list" >
                        <StaticEditTable {...tableSysPushMsgProps} setOpterationColumn="Y" footer="hidden" />
                      </div> : ''
                  }
                </TabPane>
                <TabPane tab={SystemSetting} key={5}>
                  <TabSysParam {...props} />
                </TabPane>
              </Tabs>
            </div>
          </Content>
        </Layout>
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonSystemSettingEvent(CommonSystemSetting));

