SplitPaste.js 19 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
/* eslint-disable */
/* eslint-disable function-paren-newline */
import React, { Component } from 'react';
import '@ant-design/compatible/assets/index.css';
import { Row, Col, List, Card, Checkbox, Select, Form, Tree } from 'antd';
import ShowType from '@/components/Common/CommonComponent';
import * as commonUtils from '@/utils/utils';
import splitstyles from '../SplitPaste.less';
import * as commonConfig from '../../../utils/config';
const { TreeNode } = Tree;
import file from '@/assets/file.svg';
import file_single from '@/assets/file_single.svg';
// import * as commonServices from '../../../services/services';

const FormItem = Form.Item;

class SplitPaste extends Component {
  constructor(props) {
    super(props);
    this.activeTree = [];
  }

  componentDidMount() {
    this.props.onSaveState({
      masterData: {...this.props.masterData, sAllParam: undefined,
        sAllPartsName: undefined,
        sFormulaLengthSize: undefined,
        sFormulaWidthSize: undefined,
        sProductClassifyId: undefined,
        sProductClassifyName: undefined,
      },
      sBackProcessClassifyData: undefined
    })
    this.getTreeData();
    // const height = document.getElementsByClassName('split-container')[0].offsetHeight;
    // document.getElementsByClassName('split-tree')[0].style.height = height > 50 ? `${height + 0.5}px` : 200 + 'px';
  }

  componentDidUpdate() {
    // document.getElementsByClassName('split-tree')[0].style.height = 0 + 'px';
    // const height = document.getElementsByClassName('split-container')[0].offsetHeight;
    // document.getElementsByClassName('split-tree')[0].style.height = height > 50 ? `${height + 0.5}px` : 200 + 'px';
  }

  getTreeData = async () => {
    const {
      masterConfig, slaveFilterCondition,
    } = this.props;
    const filterTreeConfigArr = masterConfig.gdsconfigformslave.filter(item => item.bTree);
    if (commonUtils.isNotEmptyArr(filterTreeConfigArr)) {
      const filterTreeConfig = filterTreeConfigArr[0];
      this.handleGetFilterTreeData(filterTreeConfig, slaveFilterCondition, 1);
    }
  }

  handleGetFilterTreeData = async (masterConfig, slaveFilterCondition, page, slaveOrderBy) => {
    const pageNum = commonUtils.isEmpty(page) ? 1 : page;
    await this.props.handleGetTreeDataSet({
      name: 'master',
      configData: masterConfig,
      condition: {
        pageNum,
        pageSize: commonConfig.pageSize,
        bFilter: slaveFilterCondition,
        sFilterOrderBy: slaveOrderBy,
      },
      flag: true,
      clearSelectData: true,
    });
    if(this.props.treeData[0] && this.props.treeData[0].children[0]) {
      this.handleTreeSelect([this.props.treeData[0].children[0].sId],
  {
          node: { treeNode: this.props.treeData[0].children[0] }
        }
      )
    }
  };

  handleTreeSelect = async (e, select) => {
    if (e[0]) {
      this.activeTree = e;
      const selected = select.node.treeNode;
      this.props.onMasterChange('master', 'sProductClassifyName', {
        sAllParam: undefined,
        sAllPartsName: selected.sAllPartsName,
        sFormulaLengthSize: undefined,
        sFormulaWidthSize: undefined,
        sProductClassifyId: selected.sId,
        sProductClassifyName: selected.sName,
      });
    }
  }

  handleToggle = () => {
    this.props.onToggle();
  };

  handleViewClick = (name, sName, record) => {
    this.props.onViewClick(name, sName, record);
    this.props.onSaveState({ fastOrderModalVisible: false });
  };

  renderTreeNodes = (data) => {
    return data.map((item) => {
      if (item.children && item.children.length > 0) {
        return (
          <TreeNode
            title={item.showName}
            key={item.sId}
            treeNode={item}
            isLeaf={item.isLeaf}
          >
            {this.renderTreeNodes(item.children)}
          </TreeNode>
        );
      }
      return (<TreeNode
        title={item.showName}
        key={item.sId}
        treeNode={item}
        switcherIcon={<img src={file_single} width={13} alt="svg" />}
      />);
    });
  };

  render() {
    const {
      masterConfig, enabled, sBackProcessClassifyData, checkProcessClassifyData, sModelsId,
    } = this.props;
    let { masterData } = this.props;
    masterData = masterData === undefined ? {} : masterData;
    const expand = true;
    const { getFieldDecorator } = this.props.form;
    const { sAllPartsName } = masterData;
    let allPartsName = [];
    if (sAllPartsName !== undefined) {
      allPartsName = sAllPartsName.split(',');
    }

    const newConfig = {};
    if (commonUtils.isNotEmptyObject(masterConfig) && masterConfig.gdsconfigformslave.length > 0) {
      const filterConfig = masterConfig.gdsconfigformslave.filter(item => (item.sName.indexOf('dSumPQty') > -1 || item.sName.indexOf('sMaterialsName') > -1 || item.sName.indexOf('iPrintModePo') > -1 || item.sName.indexOf('iPositiveColor') > -1));
      filterConfig.forEach((childNew) => {
        const child = { ...childNew };
        child.bVisible = true;
        if (child.sName.indexOf('dSumPQty') > -1) {
          child.placeholder = 'P数';
        } else if (child.sName.indexOf('sMaterialsName') > -1) {
          child.placeholder = '选择材料';
        } else if (child.sName.indexOf('iPrintModePo') > -1) {
          child.placeholder = '选择单双面';
        } else if (child.sName.indexOf('iPositiveColor') > -1) {
          child.placeholder = '印刷颜色';
        }
        let enabledNew = (enabled && !child.bReadonly && !child.specialControl);
        if (child.iTag === 1) {
          enabledNew = false;
        } else if (child.iTag === 3) {
          enabledNew = true;
        }
        const sMemo = child.sName.toLowerCase().endsWith('memo');
        const formItemLayout = { labelCol: { span: 2 }, wrapperCol: { span: 18 } };
        const showTypeProps = {
          form: this.props.form,
          getSqlDropDownData: this.props.getSqlDropDownData,
          getSqlCondition: this.props.getSqlCondition,
          handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
          getFloatNum: this.props.getFloatNum,
          onChange: this.props.onMasterChange,
          showConfig: child,
          formItemLayout: sMemo ? formItemLayout : {},
          textArea: sMemo,
          enabled: enabledNew,
          dataValue: masterData[child.sName],
          bTable: false,
        };
        newConfig[child.sName] = showTypeProps;
      });
    }



    /* 主表根据产品分类增加参数1,参数2,参数3,参数4,展开尺寸 */
    const modalFilterConfig = masterConfig.gdsconfigformslave.filter(item => (item.sName.indexOf('dProductQty') > -1 || item.sName.indexOf('sProductName') > -1 || item.sName.indexOf('sCustomerName') > -1 || item.sName.indexOf('sProductClassifyName') > -1 || item.sName.indexOf('sProductStyle') > -1));
    const formItemLayout = { labelCol: { span: 2 }, wrapperCol: { span: 18 } };
    const fullFormItemLayout = { labelCol: { span: 0 }, wrapperCol: { span: 24, offset: 0 } };
    const halfFormItemLayout = { labelCol: { span: 0 }, wrapperCol: { span: 24, offset: 0 } };

    return (
      <FormItem className={`${splitstyles.splitPaste} searchMainForm`} style={{ backgroundColor: '#ffffff' }}>
        <Row>
          <Col span={24}>
            <Row
              type="flex"
              style={{
                height: expand ? 'auto' : '100px', overflow: 'hidden', padding: '8px 8px 4px 8px',
              }}
            >
              {
                modalFilterConfig.map((child, index) => {
                  const sMemo = child.sName.toLowerCase().endsWith('memo');
                  const iOrder = sMemo ? 100 : child.iOrder > 100 ? 100 : child.iOrder; /* 排序 */
                  let enabledNew = (enabled && !child.bReadonly && !child.specialControl);
                  if (child.iTag === 1) {
                    enabledNew = false;
                  } else if (child.iTag === 3) {
                    enabledNew = true;
                  }
                  const showTypeProps = {
                    name: 'master',
                    form: this.props.form,
                    formId: sModelsId,
                    record: masterData,
                    getSqlDropDownData: this.props.getSqlDropDownData,
                    getSqlCondition: this.props.getSqlCondition,
                    handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
                    getFloatNum: this.props.getFloatNum,
                    getDateFormat: this.props.getDateFormat,
                    onChange: this.props.onMasterChange,
                    onViewClick: this.handleViewClick,
                    showConfig: child,
                    formItemLayout: sMemo ? formItemLayout : {},
                    textArea: sMemo,
                    enabled: enabledNew,
                    dataValue: masterData[child.sName],
                    bTable: false,
                    itemLabel: child.sName === 'sType' ? 'hide' : null,
                    onFilterDropDownData: this.props.onFilterDropDownData,
                  };
                  return (
                    <Col
                      key={child.sId}
                      span={index ? 5 : 4}
                      order={iOrder}
                    >
                      <ShowType {...showTypeProps} />
                    </Col>
                  );
                })
              }
            </Row>
          </Col>
          <Col span={3} className={`${splitstyles.splitTree} custom-scroll`}>
            <div className={`${splitstyles.treeContainer}`}>
              <div className={`${splitstyles.SplitListTitle}`}>
                产品分类
              </div>
              <Tree
                key={Math.random()}
                className={'hide-file-icon'}
                switcherIcon={<img src={file} alt="svg" />}
                onSelect={this.handleTreeSelect}
                selectedKeys={this.activeTree}
                defaultExpandAll={true}
              >
                {this.renderTreeNodes(this.props.treeData)}
              </Tree>
            </div>
          </Col>
          <Col span={21} className={`${splitstyles.splitContainer} custom-scroll`}>
            {allPartsName.length > 0 && Object.keys(newConfig).length > 4 ?
              <List
                className={splitstyles.list}
                grid={{ column: 1 }}
                dataSource={allPartsName}
                size="small"
                renderItem={(sPartsName, i) => (
                  <Row className={splitstyles.borderBottom} style={{ position: 'relative' }}>
                    <Col span={4} className={splitstyles.SplitListPartsName}>
                      {
                        i === 0 ?
                          <div className={splitstyles.SplitListTitle}>
                            部件信息
                          </div>
                          : null
                      }
                      <div className={splitstyles.rowWrapper}>
                        <Row gutter={[8, 0]}>
                          <Col span={15}>
                            <span className={splitstyles.introSpan}>{sPartsName}</span>
                          </Col>
                          <Col
                            order={1}
                            span={9}
                            style={{ position: 'relative' }}
                          >
                            {
                              newConfig[`dSumPQty${sPartsName}`] && <ShowType {...newConfig[`dSumPQty${sPartsName}`]} itemLabel="hide" formItemLayout={halfFormItemLayout} />
                            }
                          </Col>
                          <Col span={24} order={2}>
                            {
                              newConfig[`sMaterialsName${sPartsName}`] && <ShowType {...newConfig[`sMaterialsName${sPartsName}`]} itemLabel="hide" formItemLayout={fullFormItemLayout} />
                            }
                          </Col>
                        </Row>
                      </div>
                    </Col>
                    <Col span={2} >
                      {
                        i === 0 ?
                          <div className={splitstyles.SplitListTitle}>印刷颜色
                          </div>
                          : null
                      }
                      <div className={splitstyles.rowWrapper}>
                        <Row gutter={[8, 0]}>
                          <Col span={24}>
                            {
                              newConfig[`iPrintModePo${sPartsName}`] && <ShowType {...newConfig[`iPrintModePo${sPartsName}`]} itemLabel="hide" formItemLayout={fullFormItemLayout} />
                            }
                          </Col>
                          <Col span={24}>
                            {
                              newConfig[`iPositiveColor${sPartsName}`] && <ShowType {...newConfig[`iPositiveColor${sPartsName}`]} itemLabel="hide" formItemLayout={fullFormItemLayout} />
                            }
                          </Col>
                        </Row>
                      </div>
                    </Col>
                    <Col span={18}>
                      {
                        i === 0 ?
                          <div className={splitstyles.SplitListTitle}>工序
                          </div>
                          : null
                      }
                      <Row className={splitstyles.rowWrapper}>
                        <Col span={24}>
                          {sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' ?
                            <List
                              grid={{ column: 4 }}
                              dataSource={sBackProcessClassifyData.filter(item => (item.sType !== '3' && (item.sPartsName === sPartsName || item.sPartsName === '')))}
                              size="small"
                              renderItem={item => (
                                <List.Item>
                                  <Card bordered={false} bodyStyle={{ padding: 0 }}>
                                    <Row>
                                      <Col span={10}>
                                        <Checkbox
                                          checked={checkProcessClassifyData !== undefined && checkProcessClassifyData.filter(card => (card.sId === item.sId && card.sPartsName === sPartsName)).length > 0}
                                          onChange={(e) => {
                                            this.props.handleProcessChange(e, item, sPartsName);
                                          }}
                                          title={item}
                                        >
                                          {item.sName}
                                        </Checkbox>
                                      </Col>
                                      <Col span={14}>
                                        <FormItem>
                                          {getFieldDecorator(`${item.sId + sPartsName}`, {
                                          })(
                                            <Select
                                              showSearch
                                              filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                                              onSelect={this.props.handleSelectChangeProcess.bind(this, `${item.sId + sPartsName}:sId,${item.sId + item.sName + sPartsName}:sProcessName,${item.sId + item.sType + sPartsName}:sType`)}
                                            >{this.props.handleA(item.sId)}
                                            </Select>)}
                                        </FormItem>
                                      </Col>
                                    </Row>
                                  </Card>
                                </List.Item>
                              )}
                            />
                            : ''}
                        </Col>
                      </Row>
                    </Col>
                    <div className={splitstyles.SplitListLine} />
                    <div className={splitstyles.SplitListLineSec} />
                  </Row>
                )}
              />
              : ''}
            <Row className={splitstyles.lastRow}>
              <Col
                span={24}
              >
                <Row>
                  {sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' ?
                    <Col
                      span={4}
                      className={splitstyles.borderRight}
                    >
                      <span className={splitstyles.process}>成品工序</span>
                    </Col>
                    : null
                  }
                  <Col span={20}>
                    {sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' ?
                      <List
                        grid={{ column: 4 }}
                        dataSource={sBackProcessClassifyData.filter(item => (item.sType === '3'))}
                        size="small"
                        renderItem={item => (
                          <List.Item>
                            <Card bordered={false} bodyStyle={{ padding: 0 }}>
                              <Row className={splitstyles.rowWrapper}>
                                <Col span={10}>
                                  <Checkbox
                                    checked={checkProcessClassifyData !== undefined && checkProcessClassifyData.filter(card => (card.sId === item.sId)).length > 0}
                                    onChange={(e) => {
                                      this.props.handleProcessChange(e, item, '');
                                    }}
                                    title={item}
                                  >
                                    {item.sName}
                                  </Checkbox>
                                </Col>
                                <Col span={14}>
                                  <FormItem>
                                    {getFieldDecorator(`${item.sId}`, {
                                    })(
                                      <Select
                                        showSearch
                                        filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                                        onSelect={this.props.handleSelectChangeProcess.bind(this, `${item.sId}:sId,${item.sId + item.sName}:sProcessName,${item.sId + item.sType}:sType`)}
                                      >{this.props.handleA(item.sId)}
                                      </Select>)}
                                  </FormItem>
                                </Col>
                              </Row>
                            </Card>
                          </List.Item>
                        )}
                      />
                      : ''}
                  </Col>
                </Row>
              </Col>
            </Row>
          </Col>
        </Row>
      </FormItem>
    );
  }
}

export default SplitPaste;