KnifeMouldInfo.js 5.06 KB
/* 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, Tabs, Spin, Avatar, message } from 'antd-v4';
import styles from '../../index.less';
import Toolbar from '../Common/ToolBar/ToolBarNew';
import * as commonFunc from '../Common/commonFunc';
import CommonBase from '../Common/CommonBase';
import CommonElementEvent from '../Common/CommonElementEvent';
import StaticEditTable from '../Common/CommonTable';/* 可编辑表格 */
import CommonView from '../Common/CommonView';
import * as commonBusiness from '../Common/commonBusiness';/* 单据业务功能 */

const { Header, Content } = Layout;
const { TabPane } = Tabs;
class KnifeMouldInfoComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
    this.form = {}; /*   表单对象   */
  }
  onTabChange = (key) => {
    this.props.onSaveState({ activeKey: key });
  };
  /**   上传后执行函数    */
  handleBeforeUpload = () => {
    // const isLt10M = file.size / 1024 / 1024 < 10;
    // if (!isLt10M) {
    //   message.error(commonFunc.showMessage(this.props.app.commonConst, 'picMax'));/* 图片大小需小于10MB! */
    // }
  };
  /**   上传后执行函数    */
  handleUploadChange = (info, name) => {
    const { file } = info;
    if (file.response && file.response.code === 1) {
      const sPicturePath = file.response.dataset.rows[0].savePathStr;
      const uploadInfo = {
        sPicturePath,
        sFileName: file.name,
      };
      const tableDataRow = this.props.onDataRowAdd(name, true);
      const { [`${name}Column`]: tableColumn, masterData, [`${name}Data`]: tableData } = this.props;
      tableColumn.forEach((slaveChild) => {
        const ckey = slaveChild.dataIndex;
        if (ckey === 'sProductNo' || ckey === 'sProductName') {
          tableDataRow[ckey] = masterData[ckey] !== undefined ? masterData[ckey] : '';
        } else if (ckey === 'iOrder') {
          tableDataRow[ckey] = '';
        } else if (file.response && file.response.code === 1) {
          if (uploadInfo[ckey] !== undefined) {
            tableDataRow[ckey] = uploadInfo[ckey];
          }
        }
      });
      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData });
    } else if (file.response && file.response.code === -1) {
      message.error(file.response.msg);
    }
  };
  render() {
    const { pageLoading } = this.props;
    return (
      <div>
        <Spin spinning={pageLoading}>
          <div>
            <KnifeMouldComponent
              {...this.props}
              {...this.state}
              onTabChange={this.onTabChange}
              onUploadChange={this.handleUploadChange}
              onBeforeUpload={this.handleBeforeUpload}
            />
          </div>
        </Spin>
      </div>
    );
  }
}
const KnifeMouldComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const {
    form, onReturnForm, AutoTableHeight, app,
  } = props;
  /*   回带表单   */
  onReturnForm(form);
  const tabKnifemouldproduct = commonFunc.showMessage(app.commonConst, 'tabKnifemouldproduct');/* 刀模信息 */
  const tabPicFile = commonFunc.showMessage(app.commonConst, 'tabPicFile');/* 图片上传 */
  return (
    <Form>
      <Layout>
        <Header className={styles.header}>
          <Toolbar {...props} />
        </Header>
        <Layout className={styles.clayout}>
          <Content className={styles.content}>
            <div className="bill-search-group" >
              <CommonView {...props} />
            </div>
            <div id="slaveTabs" className={styles.bShow} >
              <div>
                <Avatar src={props.imgSrc} />
              </div>
              <Tabs
                onChange={props.onTabChange}
                activeKey={props.activeKey === undefined ? '2' : props.activeKey}
                className={`${styles.slaveTabs} basicInfo`}
                tabBarStyle={{ margin: '0 10px' }}
              >
                <TabPane tab={tabKnifemouldproduct} key={2} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 92px)` }}>
                  <div className="TabPaneStyle">
                    <StaticEditTable {...commonBusiness.getTableTypes('eleknifemouldproduct', props)} footer="hidden" setOpterationColumn="Y" />
                  </div>
                </TabPane>
                <TabPane tab={tabPicFile} key={3} className="xly-bill-list" style={{ height: `calc( ${AutoTableHeight} - 92px)` }}>
                  <div className="TabPaneStyle">
                    <StaticEditTable {...commonBusiness.getTableTypes('eleknifemouldfile', props)} footer="hidden" setOpterationColumn="Y" />
                  </div>
                </TabPane>
              </Tabs>
            </div>
          </Content>
        </Layout>
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonElementEvent(KnifeMouldInfoComponent));