oeeChooseEmployee.js 8.73 KB
/* eslint-disable */
import React, { Component } from "react";
import { Layout, Spin, Button, message } from "antd";
import { Form } from "@ant-design/compatible";
import "@ant-design/compatible/assets/index.css";
import CommonListEvent from "../../components/Common/CommonListEvent"; /* 继承销售模块业务功能 */
import * as commonFunc from "../../components/Common/commonFunc"; /* 通用单据方法 */ /* 通用单据方法 */
import StaticEditTable from "../../components/Common/CommonTable"; /* 可编辑表格 */
// import styles from '../../index.less';
import OeeStyle from "../common/oee.less";
import CommonBase from "../../components/Common/CommonBase"; /* 获取配置及数据 */
import * as commonBusiness from "../../components/Common/commonBusiness"; /* 单据业务功能 */
import SearchComponent from "../../components/Common/SearchComponent"; /* 搜索组件 */
// import * as commonConfig from '../../utils/config';
import * as 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";

const { Content } = Layout;

class CommonList extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  // ----------------------------数据修改回带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 = () => {
    const {
      slaveSelectedData,
      sParentId,
      masterData,
      app,
      fromEmployeeData
    } = this.props;
    // let slaveSelectedDataNew = [];
    if (
      commonUtils.isNotEmptyArr(slaveSelectedData) &&
      commonUtils.isNotEmptyStr(sParentId)
    ) {
      /* 如果选择员工已存在 则进行提示 */
      let flag = false;
      if (commonUtils.isNotEmptyArr(fromEmployeeData)) {
        for (const item of slaveSelectedData) {
          const iIndex = fromEmployeeData.findIndex(
            emp => emp.sEmployeeId === item.sId
          );
          if (iIndex > -1) {
            flag = true;
            break;
          }
        }
      }
      if (flag) {
        message.error("员工已存在,请重新选择!");
        return;
      }
      // eslint-disable-next-line array-callback-return
      slaveSelectedData.map(item => {
        item.sEmployeeId = item.sId;
        item.handleType = "add";
        item.sParentId = app.sTeamNameSId;
        item.dProportion =
          commonUtils.isNotEmptyNumber(item.dProportion) &&
          item.dProportion !== 0
            ? item.dProportion
            : 1;
        item.sId = commonUtils.createSid();
        item.sSlaveId = masterData.sId;
        item.dHourWage = item.dHourWage; /* 人员小时工资 */
      });
      // slaveSelectedDataNew = slaveSelectedData;
    }
    this.props.onReciveSelectData(slaveSelectedData);
  };
  /**   关闭   */
  handleCancelModal = () => {
    this.props.onReciveSelectData("closeDoor");
  };
  // ----------------------------数据修改回带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}
              onEject={this.handleEject.bind(this)}
              onSelectTree={this.handleTreeSelect}
            />
          </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: config.pageSize,
    showQuickJumper: true,
    hideOnSinglePage: true
  };
  const tableProps = {
    ...commonBusiness.getTableTypes("slave", props),
    tableProps: {
      rowKey: "sSlaveId",
      pagination: false && pagination,
      onChange: props.onTitleChange,
      AutoTableHeight: "62vh"
    }
  };

  let configNew = tableProps.config;
  if (tableProps.config && props.bHandover) {
    configNew = JSON.parse(JSON.stringify(tableProps.config));
    configNew.gdsconfigformslave.forEach(item => {
      if (item.sName === "sEmployeeName") {
        item.showName = "模具名称";
      } else if (item.showName === "序号") {
        item.bVisible = false;
      } else if (item.showName === "制单人") {
        item.bVisible = false;
      }
    });
    tableProps.data = tableProps.data
      ? tableProps.data
          .filter(
            (_, index) => index < (props.bHandover === "startwork" ? 100 : 10)
          )
          .map((item, index) => ({
            ...item,
            sEmployeeName: `模具${index + 1}`
          }))
      : tableProps.data;
  }

  const headerColumn = configNew
    ? commonFunc.getHeaderConfig(configNew)
    : tableProps.headerColumn;

  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
  };

  return (
    <Form>
      <Layout>
        <Layout>
          <div
            id="oeeModalChooseProcess"
            className={OeeStyle.modalChooseProcess}
          >
            {!props.bHandover && (
              <div className={OeeStyle.content}>
                <SearchComponent {...props} />
              </div>
            )}
            <Content className="xly-normal-list">
              <StaticEditTable
                {...tableProps}
                config={configNew}
                headerColumn={headerColumn}
                footer="hidden"
                tableBelone="list"
                showConfig={props.showConfig}
                noVlist
              />
            </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: "-30px" }}
          >
            {" "}
            <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>
        )}
        <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(CommonList));