/**
 * @Date:   2019-05-20T16:45:00+08:00
 * @Last modified time: 2019-06-26T18:40:44+08:00
 */

import { connect } from 'umi';
import CommobileListComponent from '../../../mobile/common/CommobileList';
import * as commonUtils from '../../../utils/utils';

function commobileList({
  dispatch, app, content, location, sModelsId, sModelsType,
}) {
  /* 只有state与sModelsId同时为空时 返回空白页,设备是固定模块id */
  if (location && location.state === null && commonUtils.isEmptyObject(sModelsId)) {
    return (<div />);
  }
  let param = {};
  if (location && location.pathname !== '/indexMobile') {
    if (location.state.sParam) {
      param = commonUtils.convertStrToObj(location.state.sParam);
    } else {
      param = commonUtils.convertStrToObj(location.state);
    }
  }
  const commonListProps = {
    app,
    content,
    sModelsId: commonUtils.isNotEmptyObject(sModelsId) && location.pathname === '/indexMobile' ? sModelsId : param.sModelsId,
    sModelsType: commonUtils.isNotEmptyObject(sModelsType) ? sModelsType : param.sModelsType,
    formRoute: '/commobileList',
    dispatch,
  };
  if (commonUtils.isNotEmptyArr(param.returnFilterCondition)) { /* 未清到单据 单据回刷到列表所带条件 */
    commonListProps.returnFilterCondition = param.returnFilterCondition;
    commonListProps.returnFilterName = param.copyTo.listFilterName;
  }
  return (
    <CommobileListComponent {...commonListProps} style={{ height: '100%' }} />
  );
}

export default connect(({ routing, app, content }) =>
  ({ routing, app, content }))(commobileList);
