ContextMenuModal.js 4.95 KB
/**
 * Created by mar105 on 2019-02-13.
 */
/* eslint-disable no-undef,import/first,prefer-destructuring,jsx-a11y/alt-text */
import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Row, Col } from 'antd';
import * as commonUtils from '../../utils/utils';
import ShowType from './CommonComponent';/* 通用方法 */
import AntdDraggableModal from '../Common/AntdDraggableModal';


const FormItem = Form.Item;
export default class ContextMenuModal extends Component {
  /**   构造函数   */
  constructor(props) {
    super(props);
    this.state = {
    };
    this.form = {};
    /*   表单对象   */
  }
  handleViewClick = (name, sName, sId) => {
    this.props.onViewClick(name, sName, sId);
  };
  /* 右击弹出窗确定 取表单值 */
 handleContextMenuOk= () => {
   const { masterData, contextMenuConfig } = this.props;
   if (commonUtils.isNotEmptyObject(masterData) && commonUtils.isNotEmptyArr(contextMenuConfig)) {
     const showConfig = contextMenuConfig[0];
     if (commonUtils.isNotEmptyObject(showConfig.sName)) {
       const contextMenuValue = masterData[showConfig.sName]; /* 取弹窗框的值 */
       if (!commonUtils.isEmpty(contextMenuValue)) {
         this.props.onContextMenuOk(contextMenuValue);
       }
     }
   }
 }

  handleModalCancel = (modelVisible) => {
    this.props.onSaveState({
      [modelVisible]: false,
    });
  };

  /**   渲染   */
  render() {
    const {
      contextMenuModalVisible,
      contextMenuTbName,
      contextMenuConfig,
      contextMenuName,
      app,
      form,
      sTabId,
      [`${contextMenuTbName}Data`]: tableData, [`${contextMenuTbName}SelectedRowKeys`]: selectedRowKeys,
    } = this.props;
    let tableDataRow = {};
    if (commonUtils.isNotEmptyArr(tableData)) {
      const tableFilterData = tableData.filter(item => selectedRowKeys.includes(item.sId));
      if (commonUtils.isNotEmptyArr(tableFilterData)) {
        tableDataRow = tableFilterData[0];
      }
    }
    const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
    return (
      <div>
        {
          (pane.notCurrentPane ? false : contextMenuModalVisible) ?
            <AntdDraggableModal
              title={`全部更新:${contextMenuName}`}
              visible={contextMenuModalVisible}
              onOk={this.handleContextMenuOk}
              onCancel={this.handleModalCancel.bind(this, 'contextMenuModalVisible')}
              width={380}
              okButtonProps={{ style: { marginRight: '5px' } }}
              // cancelButtonProps={{ style: { marginRight: '10px' } }}
              bodyStyle={{ paddingLeft: '3px', paddingRight: '3px' }}
            >
              <div className="contextMenuStyle" >
                <FormItem className="searchMainForm">
                  <Row type="flex" style={{ height: 'auto', overflow: 'hidden' }}>
                    { commonUtils.isNotEmptyArr(contextMenuConfig) ?
                      contextMenuConfig.map((child) => {
                        const sMemo = child.sName.toLowerCase().endsWith('memo');
                        let enabledNew = !child.bReadonly;
                        if (child.iTag === 1) {
                          enabledNew = false;
                        } else if (child.iTag === 3) {
                          enabledNew = true;
                        }
                        const showTypeProps = {
                          name: 'slave',
                           form,
                          record: tableDataRow,
                          sId: commonUtils.createSid(),
                          getSqlDropDownData: this.props.getSqlDropDownData,
                          getSqlCondition: this.props.getSqlCondition,
                          handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
                          getFloatNum: this.props.getFloatNum,
                          onChange: this.props.onChange,
                          onViewClick: this.handleViewClick,
                          getDateFormat: this.props.getDateFormat,
                          showConfig: child,
                          textArea: sMemo,
                          enabled: enabledNew,
                          dataValue: commonUtils.isNotEmptyObject(tableDataRow) ? tableDataRow[child.sName] : '',
                          bTable: true,
                          formRoute: this.props.formRoute,
                          formItemLayout: {},
                        };
                        return (
                          <Col key={child.sId} span={24} order={child.iOrder} className="ContextMenuCol" style={{ border: '1px solid #d3d3d3' }}>
                            <ShowType {...showTypeProps} />
                          </Col>
                        );
                      }) : ''
                    }
                  </Row>
                </FormItem>
              </div>
            </AntdDraggableModal>
            : ''
        }

      </div>
    );
  }
}