/**
 * 此组件是 列表模块是根据弹窗的路由 显示对应的模块决定
 * commonListTree是通用两层结构,功能如物料需求计划，两层都可以配制独立的数据源
 */
import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import { Layout, Spin, Button, message } from 'antd-v4';
import CommonListTreeEvent from '@/components/Common/CommonListTreeEvent';/* 继承销售模块业务功能 */
import * as commonFunc from '@/components/Common/commonFunc';/* 通用单据方法 */ /* 通用单据方法 */
import StaticEditTable from '@/components/Common/CommonTable';/* 可编辑表格 */
import CommonBase from '@/components/Common/CommonBase';/* 获取配置及数据 */
import * as commonBusiness from '@/components/Common/commonBusiness';/* 单据业务功能 */
import SearchComponent from '@/components/Common/SearchComponent';/* 搜索组件 */
import config from '@/utils/config';
import * as commonUtils from '@/utils/utils';
import Eject from '@/assets/eject.svg';
import StaticEditTree from '@/components/Common/Tree/StaticTree';
import Close from '@/assets/close.svg';
import commonConfig from '../../../utils/config';
import * as commonServices from '../../../services/services';

const { Content } = Layout;


class CommonList extends Component {
  constructor(props) {
    super(props);
    this.state = {
      btnList: [],
      openFlag: false,
    };
  }
  componentWillReceiveProps(nextProps) {
    const {
      masterConfig, gdsjurisdiction,
    } = nextProps;
    if (masterConfig) {
      // 过滤存储需要展示的按钮
      let btnList = masterConfig.gdsconfigformslave.filter(item => item.bVisible && !item.sName && item.showName && item.sControlName);
      btnList = btnList.filter(item => gdsjurisdiction.findIndex(child => item.sControlName === child.sAction) < 0 && (item.sControlName.includes('BtnAdd') || item.sControlName.includes('BtnCopyTo')));
      // 过滤权限
      this.setState({ btnList });
    }
    if (this.state.openFlag) {
      this.setState({ openFlag: false }, () => {
        this.props.onButtonClick('BtnRefresh');
      });
    }
  }

  onOpenNewTab = () => {
    this.setState({ openFlag: true });
    this.props.onOpenNewTab();
  }

  // ----------------------------数据修改回带end  ---------------------------- //
  handleEject = (e) => {
    const filterTree = e.currentTarget.parentNode;/* 获取当前页签下的树组件 */
    if (filterTree.attributes.class.value.indexOf('xly-eject') > -1) {
      // eslint-disable-next-line no-unused-expressions
      filterTree.nextSibling.style.display = 'block';
    } else if (filterTree.attributes.class.value.indexOf('xly-tree-close') > -1) {
      // eslint-disable-next-line no-unused-expressions
      filterTree.parentNode.style.display = 'none';
    }
  };

  /**   树节点选中   */
  handleTreeSelect = (name, checkedKeys, e) => {
    this.props.onSelect(name, checkedKeys, e); /* 调用CommonListEvent通用处理 */
  };

  /**   确认下单   */
  handleSelect = async () => {
    const { app, slaveInfoData, slaveInfoSelectedRowKeys } = this.props;
    console.log('aaa:', this.props);
    let { slaveSelectedData } = this.props;
    const btnName = app.currentPane.config.sControlName;
    let slaveInfoSelectedData = [];
    if (commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) {
      slaveInfoSelectedData = slaveInfoData.filter(item => slaveInfoSelectedRowKeys.includes(item.sSlaveId));
    }
    if (false) {
      const copyTo = await this.handleCopyToOrder(btnName);
      if (commonUtils.isNotEmptyObject(copyTo)) {
        slaveSelectedData = copyTo;
      }
    } else { /* 点击确定的时候添加子从表数据 */
      slaveSelectedData = slaveInfoSelectedData;
    }
    this.props.app.currentPane.select(app.currentPane.name, app.currentPane.config, slaveSelectedData);
    this.props.app.currentPane.selectCancel(app.currentPane.name);
  };
  handleDoubleClickSelect = () => {
    const { slaveConfig } = this.props;
    if (commonUtils.isNotEmptyObject(slaveConfig) && !slaveConfig.bMutiSelect) {
      this.handleSelect();
    }
  }
  /**   关闭   */
  handleCancelModal = () => {
    const { app } = this.props;
    this.props.app.currentPane.selectCancel(app.currentPane.name);
  };
  // ----------------------------数据修改回带end  ---------------------------- //
  /**   处理选择行发生改变   */
  handleTableFilterData= (name, data, record) => {
    /*   外置处理业务   */
    if (name === 'slave') {
      let slaveInfoDataNew = [];
      if (commonUtils.isNotEmptyArr(data)) {
        slaveInfoDataNew = data.filter(item => item.sSqlConditionId === record.sSqlConditionId);
      }
      return slaveInfoDataNew;
    }
  };
  // ----------------------------数据修改回带end  ---------------------------- //

  copyTo = (sActiveId) => {
    const {
      dispatch, masterConfig, masterData, contactData, addressData, slavePagination,
      sisproductclassifyProcessClassifyData, machineData, assortData, outsideData, processstyleData, processApsRuleData,
      eleemployeeData, elemachineData, eleknifemouldproductData, eleknifemouldfileData, eleteststandarditemData,
      slaveSelectedData,
    } = this.props;
    const copyTo = {};
    const copyToConfig = masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(name));
    copyTo.name = 'BtnCopyTo';
    copyTo.config = copyToConfig;
    copyTo.masterData = slaveSelectedData[0] || masterData;
    copyTo.supplyData = [];
    copyTo.stockData = [];
    copyTo.contactData = contactData;
    copyTo.addressData = addressData;
    copyTo.picFileData = [];
    copyTo.customerInfoData = [];
    copyTo.sisproductclassifyProcessClassifyData = sisproductclassifyProcessClassifyData;
    copyTo.machineData = machineData;
    copyTo.assortData = assortData;
    copyTo.outsideData = outsideData;
    copyTo.processstyleData = processstyleData;
    copyTo.processApsRuleData = processApsRuleData;
    copyTo.eleemployeeData = eleemployeeData;
    copyTo.elemachineData = elemachineData;
    copyTo.eleknifemouldproductData = eleknifemouldproductData;
    copyTo.eleknifemouldfileData = eleknifemouldfileData;
    copyTo.eleteststandarditemData = eleteststandarditemData;
    dispatch({
      type: 'content/onRouter',
      payload: {
        url: `${config.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`, /*   接口地址   */
        copyTo,
        pages: slavePagination,
        newRecordFlag: `NewRecord_${sActiveId}`,
      },
    });
  }


  /* 雅昌复制从commonListTree特殊调用 */
  handleCopyToOrder = async (btnName) => {
    /*   待用数据声明   */
    const {
      slaveConfig, token, app, sModelsId, slaveInfoSelectedRowKeys, slaveData, slaveSelectedRowKeys,
    } = this.props;
    let { slaveSelectedData } = this.props;
    const copyTo = {};
    if (true) {
      // eslint-disable-next-line no-unused-vars
      const copyToConfig = slaveConfig.gdsconfigformslave.filter(item => item.sControlName.includes(btnName));
      // eslint-disable-next-line no-unused-vars
      let copyToData = slaveSelectedData;
      if (commonUtils.isEmptyArr(slaveSelectedData)) {
        slaveSelectedData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sSlaveId));
      }
      const name = commonUtils.isNotEmptyObject(btnName) ? btnName : 'BtnCopyFrom.copyToOrderWorkInsert';
      if (name && name.includes('copyToOrder')) { /* 雅昌这个按钮执行调用接口逻辑 */
        let sType = '';/* 类型 */
        if (name.includes('Sales')) {
          sType = 'salesorder';
        } else if (name.includes('Work')) {
          sType = 'workorder';
        } else if (name.includes('Quo')) {
          sType = 'quotation';
        }
        const sControlIdsArr = []; /* 部件id集合 */
        const sSlaveIdsArr = []; /* 从表id集合 */
        let sSlaveType = ''; /* 选中表格类型 */

        if (commonUtils.isNotEmptyArr(slaveData)) {
          if (commonUtils.isNotEmptyArr(slaveSelectedData)) { /* 从表选中 */
            sSlaveType = 'slaveTable';
            slaveSelectedData.forEach((item) => {
              const sControlIds = commonUtils.isNotEmptyObject(item.sControlIds) ? item.sControlIds : '';
              if (commonUtils.isNotEmptyObject(sControlIds)) { /* 不为空传入部件ID */
                const splitData = sControlIds.split('-');
                if (commonUtils.isNotEmptyArr(splitData)) {
                  splitData.forEach((itemIds) => {
                    sControlIdsArr.push(itemIds);
                  });
                }
              } else { /* 为空传入从表ID */
                sSlaveIdsArr.push(item.sSlaveId);
              }
            });
          }
          if (commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) { /* 子表选中 */
            slaveInfoSelectedRowKeys.forEach((itemIds) => {
              sControlIdsArr.push(itemIds);
            });
          }

          const values = {
            sControlIds: sControlIdsArr,
            sSlaveIds: sSlaveIdsArr,
            sSlaveType,
          };
          const dataUrl = `${commonConfig.server_host}salesorder/getCopyToOrder/${sType}?sModelsId=${sModelsId}`;
          const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
          if (dataReturn.code === 1) {
            const returnData = dataReturn.dataset.rows[0];
            copyTo.masterData = returnData.masterData;
            copyTo.slaveData = returnData.slaveData;
            copyTo.controlData = returnData.controlData;
            copyTo.materialsData = returnData.materialsData;
            copyTo.processData = returnData.processData;
            copyTo.packData = returnData.packData;
            if (commonUtils.isEmptyArr(slaveSelectedData)) {
              copyToData = returnData.slaveData;
            }
          }
        } else {
          message.warn('请选择数据！');
        }
      }
    } else {
      message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择数据
    }
    return copyTo;
  };

  handleTableSelectRowChange = (name, selectedRowKeys) => {
    /*   外置处理业务   */
    const { slaveData } = this.props;
    let {
      slaveInfoData, slaveInfoSelectedRowKeys, slaveSelectedRowKeys,
    } = this.props;
    const addState = {};
    addState[`${name}SelectedRowKeys`] = selectedRowKeys;
    if (commonUtils.isEmptyArr(slaveInfoSelectedRowKeys)) {
      slaveInfoSelectedRowKeys = [];
    }
    slaveSelectedRowKeys = commonUtils.isEmptyArr(slaveSelectedRowKeys) ? [] : slaveSelectedRowKeys;
    slaveInfoData = commonUtils.isEmptyArr(slaveInfoData) ? [] : slaveInfoData;

    /* 如果列表是需要主从表联动 */
    if (true) {
      if (name === 'slave') {
        if (selectedRowKeys.length === 0) {
          if (commonUtils.isNotEmptyArr(slaveData)) {
            slaveData.forEach((omsRowkey, iIndexSlave) => {
              slaveData[iIndexSlave].dAuxiliaryQty = slaveData[iIndexSlave].dAuxiliaryQtyAll;
              slaveData[iIndexSlave].dMaterialsQty = slaveData[iIndexSlave].dMaterialsQtyAll;
            });
          }
          addState.slaveData = slaveData;
          addState.slaveSelectedRowKeys = [];
          addState.slaveSelectedData = [];
          addState.slaveInfoSelectedRowKeys = [];
          addState.slaveInfoSelectedData = [];
        } else {
          /* 找到勾选掉的Id */
          let oldSelectRowkeys = []; /* 取消勾选行 */
          oldSelectRowkeys = slaveSelectedRowKeys.filter(item => !selectedRowKeys.includes(item)); // 找到取消的那个行 */
          if (commonUtils.isNotEmptyArr(oldSelectRowkeys)) { /* 单层表格时 */
            oldSelectRowkeys.forEach((oldSelectRowkey) => {
              let slaveRow = {};
              /* 找到从表对应的所有子从表 */
              const iIndex = slaveData.findIndex(item => oldSelectRowkey.includes(item.sSlaveId));
              if (iIndex > -1) {
                slaveRow = slaveData[iIndex];
              }
              if (commonUtils.isNotEmptyObject(oldSelectRowkey)) { /* 找到勾选掉的从表汇总行 */
                const slaveRemoveData = slaveInfoData.filter(item => item.sFatherSlaveId === slaveRow.sSlaveId);
                if (commonUtils.isNotEmptyArr(slaveRemoveData) && commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) {
                  slaveRemoveData.forEach((itemInfo) => {
                    const indexKey = slaveInfoSelectedRowKeys.indexOf(itemInfo.sSlaveId);
                    if (indexKey > -1) {
                      slaveInfoSelectedRowKeys.splice(indexKey, 1);
                    }
                  });
                }
              }
            });
            addState.slaveInfoSelectedRowKeys = slaveInfoSelectedRowKeys;
          } else {
            oldSelectRowkeys = selectedRowKeys.filter(item => !slaveSelectedRowKeys.includes(item)); // 找到增加的那个行 */
            if (commonUtils.isNotEmptyArr(oldSelectRowkeys)) {
              oldSelectRowkeys.forEach((oldSelectRowkey) => {
                let slaveRow = {};
                /* 找到从表对应的所有子从表 */
                const iIndex = slaveData.findIndex(item => oldSelectRowkey === item.sSlaveId);
                slaveRow = iIndex > -1 ? slaveData[iIndex] : {};
                const slaveInfoAddData = slaveInfoData.filter(item => item.sFatherSlaveId === slaveRow.sSlaveId);
                if (commonUtils.isNotEmptyArr(slaveInfoAddData)) {
                  slaveInfoAddData.forEach((itemInfo) => {
                    slaveInfoSelectedRowKeys.push(itemInfo.sSlaveId);
                  });
                }
              });
            }
            addState.slaveInfoSelectedRowKeys = slaveInfoSelectedRowKeys;
          }
          addState.slaveSelectedData = slaveData.filter(item => selectedRowKeys.includes(item.sSlaveId));
          // if(commonUtils.isNotEmptyArr(selectedRowKeys)) {  /* 从表行新增勾选 */
          //   selectedRowKeys.forEach((selectedRowKey) => {
          //     let slaveRow = {};
          //     /* 找到从表对应的所有子从表 */
          //     const iIndex = slaveData.findIndex(item => selectedRowKey.includes(item.sSlaveId));
          //     if (iIndex > -1) {
          //       slaveRow = slaveData[iIndex];
          //     }
          //     if (commonUtils.isNotEmptyObject(slaveRow) && commonUtils.isNotEmptyArr(slaveInfoData)) {
          //       let dAuxiliaryQtySum = 0;
          //       let dMaterialsQtySum = 0;
          //       const slaveInfoFilterData = slaveInfoData.filter(item => item.sFatherSlaveId === slaveRow.sSlaveId);
          //       if (commonUtils.isNotEmptyArr(slaveInfoFilterData)) {
          //         slaveInfoFilterData.forEach((itemInfo) => {
          //           if(slaveInfoSelectedRowKeys.indexOf(itemInfo.sSlaveId) === -1) {
          //             slaveInfoSelectedRowKeys.push(itemInfo.sSlaveId);
          //           }
          //           dAuxiliaryQtySum += itemInfo.dAuxiliaryQty;
          //           dMaterialsQtySum += itemInfo.dMaterialsQty;
          //         });
          //         slaveRow.dAuxiliaryQty = dAuxiliaryQtySum;
          //         slaveRow.dMaterialsQty = dMaterialsQtySum;
          //         slaveData[iIndex] = {...slaveData[iIndex], ...slaveRow};
          //       }
          //     }
          //   });
          //   newSlaveSelectedData = slaveData.filter(item => selectedRowKeys.includes(item.sSlaveId)); /* 从表的所有选中行 */
          //   addState.slaveSelectedData = newSlaveSelectedData;
          //   addState.slaveData = slaveData;
          //   addState.slaveInfoSelectedRowKeys = slaveInfoSelectedRowKeys;
          // }
        }
        this.props.onSaveState({ ...addState });
      } else if (name === 'slaveInfo') {
        let oldSelectRowkeys = []; /* 取消勾选行 */
        oldSelectRowkeys = slaveInfoSelectedRowKeys.filter(item => !selectedRowKeys.includes(item)); // 找到取消的那个行 */
        if (commonUtils.isNotEmptyArr(oldSelectRowkeys)) { /* 单层表格时 */
          oldSelectRowkeys.forEach((oldSelectRowkey) => {
            let slaveInfoRow = {};
            /* 找到从表对应的所有子从表 */
            const iIndex = slaveInfoData.findIndex(item => oldSelectRowkey.includes(item.sSlaveId));
            if (iIndex > -1) {
              slaveInfoRow = slaveInfoData[iIndex];
            }
            if (commonUtils.isNotEmptyObject(oldSelectRowkey)) { /* 找到勾选掉的子从表行 */
              const slaveInfoCurrentData = slaveInfoData.filter(item => item.sFatherSlaveId === slaveInfoRow.sFatherSlaveId);
              const index = slaveInfoCurrentData.length <= 0 ? -1 : slaveInfoCurrentData.findIndex(item => selectedRowKeys.includes(item.sSlaveId));
              if (!(index > -1)) {
                const indexKey = slaveSelectedRowKeys.indexOf(slaveInfoRow.sFatherSlaveId);
                if (indexKey > -1) {
                  slaveSelectedRowKeys.splice(indexKey, 1);
                }
              }
            }
          });
          addState.slaveSelectedRowKeys = slaveSelectedRowKeys;
          addState.slaveSelectedData = slaveData.filter(item => addState.slaveSelectedRowKeys.includes(item.sSlaveId));
        } else {
          oldSelectRowkeys = selectedRowKeys.filter(item => !slaveInfoSelectedRowKeys.includes(item)); // 找到增加的那个行 */
          if (commonUtils.isNotEmptyArr(oldSelectRowkeys)) {
            oldSelectRowkeys.forEach((oldSelectRowkey) => {
              let slaveInfoRow = {};
              /* 找到从表对应的所有子从表 */
              const iIndex = slaveInfoData.findIndex(item => oldSelectRowkey.includes(item.sSlaveId));
              if (iIndex > -1) {
                slaveInfoRow = slaveInfoData[iIndex];
              }
              /* 找到从表对应的所有子从表 */
              const indexKey = slaveSelectedRowKeys.indexOf(slaveInfoRow.sFatherSlaveId);
              if (!(indexKey > -1)) {
                slaveSelectedRowKeys.push(slaveInfoRow.sFatherSlaveId);
              }
            });
          }
          addState.slaveSelectedRowKeys = slaveSelectedRowKeys;
          addState.slaveSelectedData = slaveData.filter(item => addState.slaveSelectedRowKeys.includes(item.sSlaveId));
        }

        /* 勾选行 */
        // if (selectedRowKeys.length === 0) {
        //   if(commonUtils.isNotEmptyArr(slaveData)) {
        //     slaveData.forEach((omsRowkey, iIndexSlave) => {
        //       slaveData[iIndexSlave].dAuxiliaryQty = slaveData[iIndexSlave].dAuxiliaryQtyAll;
        //       slaveData[iIndexSlave].dMaterialsQty = slaveData[iIndexSlave].dMaterialsQtyAll;
        //     });
        //   }
        //   addState.slaveData = slaveData;
        //   addState.slaveSelectedRowKeys = [];
        //   addState.slaveSelectedData = [];
        //   addState.slaveInfoSelectedRowKeys = [];
        //   addState.slaveInfoSelectedData = [];
        // } else {
        //
        //   // const newSlaveInfoSelectedData = slaveInfoData.filter(item => selectedRowKeys.includes(item.sSlaveId));
        //   // if(commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
        //   //   newSelectedRowKeys =  newSelectedRowKeys.concat(slaveSelectedRowKeys);
        //   // }
        //   // if(commonUtils.isNotEmptyArr(newSlaveInfoSelectedData)) {
        //   //   const newSlaveSelectedData = slaveData.filter(item => newSlaveInfoSelectedData.findIndex(newItem => newItem.sFatherSlaveId === item.sSlaveId) > -1);
        //   //   newSlaveSelectedData.forEach((item) => {
        //   //     const iSIndex = newSelectedRowKeys.findIndex(item => selectedRowKeys.includes(item.sSlaveId)); /* 子从表去勾选从表，若没勾选 则进行勾选 */
        //   //     if(iSIndex === -1) {
        //   //       newSelectedRowKeys.push(item.sSlaveId);
        //   //     }
        //   //     const newlist = newSlaveInfoSelectedData.filter(siItem => siItem.sFatherSlaveId === item.sSlaveId); /* 找到该子表行对应的从表 所对应的所有子从表 */
        //   //     let dAuxiliaryQty = 0;
        //   //     let dMaterialsQty = 0;
        //   //     if(commonUtils.isNotEmptyArr(newlist)) {
        //   //       newlist.forEach((item) => {
        //   //         dAuxiliaryQty = commonUtils.convertFixNum(item.dAuxiliaryQty + dAuxiliaryQty, 6);
        //   //         dMaterialsQty = commonUtils.convertFixNum(item.dMaterialsQty + dMaterialsQty, 6);
        //   //       });
        //   //     }
        //   //     const iIndex = slaveData.findIndex(itemSlave => itemSlave.sSlaveId === item.sSlaveId);
        //   //     if(iIndex > -1) {
        //   //       slaveData[iIndex].dAuxiliaryQty = dAuxiliaryQty;
        //   //       slaveData[iIndex].dMaterialsQty = dMaterialsQty;
        //   //     }
        //   //   });
        //   //   addState.slaveData = slaveData;
        //   //   addState.slaveSelectedData= newSlaveSelectedData;
        //   //   addState.slaveSelectedRowKeys = newSelectedRowKeys;
        //   //   addState.slaveInfoSelectedRowKeys = selectedRowKeys;
        //   // }
        // }
      }
      this.props.onSaveState({ ...addState });
    } else {
      this.props.onTableSelectRowChange(name, selectedRowKeys);
    }
  };

  render() {
    const { pageLoading } = this.props;
    return (
      <div style={{ height: '100%' }}>
        <Spin spinning={pageLoading}>
          <div style={{ height: '100%' }}>
            <CommonListComponent
              {...this.props}
              {...this.state}
              onOpenNewTab={this.onOpenNewTab}
              onSelect={this.handleSelect}
              onCancel={this.handleCancelModal}
              onDoubleClick={this.handleDoubleClickSelect}
              onEject={this.handleEject.bind(this)}
              onSelectTree={this.handleTreeSelect}
              onCopyTo={this.copyTo}
              onTableFilterData={this.handleTableFilterData}
              onTableSelectRowChange={this.handleTableSelectRowChange}
            />
          </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, sModelsType, onCopyTo, slaveSelectedData, slaveConfig,
  } = props;
  /*   回带表单   */
  onReturnForm(form);
  const pagination = {
    size: 'large',
    pageSize: sModelsType === 'modal/logView' ? 9999 : commonUtils.isNotEmptyNumber(props.iPageSize) && props.iPageSize !== 0 ? props.iPageSize : config.pageSize,
    ...slavePagination,
    showQuickJumper: true,
    hideOnSinglePage: true,
  };

  const tableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    onTableFilterData: props.onTableFilterData,
    tableProps: {
      rowKey: 'sSlaveId', pagination, onChange: props.onTitleChange, AutoTableHeight: '430px',
    },
  };

  const tableInfoProps = {
    ...commonBusiness.getTableTypes('slaveInfo', props),
    tableProps: { rowKey: 'sSlaveId', pagination, onChange: props.onTitleChange },
    tableBelone: 'list',
    onChange: props.onTitleChange.bind(this, 'slaveInfo'),
    // data: commonUtils.isNotEmptyObject(props.slaveInfoDataNew) ? props.slaveInfoDataNew : props.slaveInfoData,
  };

  const name = 'filterTree';
  const treeProps = {
    ...commonBusiness.getTreeTypes('tree', props),
    isSearch: false,
    checkable: false,
    disabled: false,
    checkedAll: false,
    unChecked: false,
    [`${name}Column`]: props[`${name}Column`],
    [`${name}Config`]: props[`${name}Config`],
    [`${name}Data`]: props[`${name}Data`],
    getFloatNum: props.getFloatNum,
    getSqlDropDownData: props.getSqlDropDownData,
    getSqlCondition: props.getSqlCondition,
    handleSqlDropDownNewRecord: props.handleSqlDropDownNewRecord,
    getDateFormat: props.getDateFormat,
    onDoubleClick: props.onDoubleClick,
    onSelect: props.onSelectTree,
    expandedKeys: props.expandedKeys,
  };
  // eslint-disable-next-line no-unused-vars
  let rowSelectionProps = {};
  if (props.rowSelection !== undefined) {
    rowSelectionProps = {
      rowSelection: props.rowSelection,
    };
  }
  
  const BtnSure =commonFunc.showMessage(app.commonConst, 'BtnSure') || '确认';
  const BtnCancel  =commonFunc.showMessage(app.commonConst, 'BtnCancel') || '取消';
  
  const realizeHeight = commonUtils.isNotEmptyNumber(props.realizeHeight) ? props.realizeHeight : 0;
  const btnClick = (btn) => {
    const { sControlName } = btn;
    const picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === 'picArr'));
    if (picArr.length) {
      const sActiveId = picArr[0] ? picArr[0].sActiveId : '';
      if (sControlName === 'BtnAdd') {
        const params = {
          newRecordFlag: `NewRecord_${sActiveId}`,
        };
        if (props.outerMasterData && props.outerMasterData.sCustomerId) {
          params.newRecordRelation = {
            sCustomerId: props.outerMasterData.sCustomerId,
            sCustomerNo: props.outerMasterData.sCustomerNo,
            sCustomerName: props.outerMasterData.sCustomerName,
          };
        }
        props.onAdd(params);
        props.onOpenNewTab();
      } else if (sControlName === 'BtnCopyTo') {
        if (!Array.isArray(slaveSelectedData) || slaveSelectedData.length !== 1) {
          message.warn('请选择一例单据'); // 请选择数据
        } else {
          onCopyTo(sActiveId);
          props.onOpenNewTab();
        }
      }
    }
  };

  return (
    <Form>
      <Layout>
        <Layout>
          <div id="modalTreeChooseProcess">
            <div style={{ maxHeight: '100%', zIndex: 20 }}>
              <SearchComponent {...props} />
            </div>
            <Content
              className="xly-normal-list materialRequirementPlane"
              style={{ height: realizeHeight > 0 ? `${500 + realizeHeight}px` : 'auto', minHeight: '300px', paddingLeft: '10px' }}
            >
              <StaticEditTable {...tableProps} slaveInfo={tableInfoProps} footer="hidden" setExpandedRowRender="Y" tableBelone="list" />
            </Content>
          </div>
        </Layout>
        {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
        {commonUtils.isEmptyArr(treeProps.treeData) || !commonUtils.isEmpty(props.routing) ? '' : <div className="xly-eject" style={{ position: 'absolute', right: '0px' }}> <a onClick={props.onEject}> <img src={Eject} alt="eject" /></a> </div>}
        {commonUtils.isEmptyArr(treeProps.treeData) || !commonUtils.isEmpty(props.routing) ? '' :
        <div className="xly-filter-tree">
          <StaticEditTree {...treeProps} />
          <div className="xly-tree-close" >
            {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
            <a onClick={props.onEject}> <img src={Close} alt="close" /></a>
          </div>
        </div>
        }
        {sModelsType !== 'search/workSchedule' ?
          <div style={{ display: 'flex', justifyContent: 'space-between' }}>
            <div>
              {
                commonUtils.isNotEmptyArr(props.btnList) && props.btnList.map(btn => (
                  <Button
                    onClick={() => btnClick(btn)}
                    style={{ marginRight: 8 }}
                    type="primary"
                    key={btn.sControlName}
                  >
                    { btn.showName }
                  </Button>
                ))
              }
            </div>
            <div style={{ textAlign: 'right', marginRight: '9px', marginBottom: '9px' }}>
              <Button key="back" style={{ marginRight: '8px' }} onClick={props.onCancel}>{BtnCancel}</Button>
              <Button type="primary" onClick={props.onSelect}>     {BtnSure}</Button>
            </div>
          </div> : ''
        }
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonListTreeEvent(CommonList));
