import React from 'react';
import { connect } from 'dva';
import { Button, Row, Col, Form, Input,Select,Table,InputNumber} from 'antd';
import {   extendRule,  initFilter,   extendInclude,initFilterGroup,extendGroupRule,extendFilterGroup, guid, getDataFieldValue} from "../../../utils/common";
import EditComponent from '../../../baseComponents/EditComponent';
 

class InventoryChangePage extends EditComponent {
  constructor(props) {
    super(props);
    this.state = {
      data: {},
    };
  };

  onGetEntityData(allColumns,navFields){
    const data=this.props.data;
    const {getIds,btnConfig}=data?data:{};
    const ids=getIds?getIds():null;
    super.onGetEntityData(allColumns,navFields);
    if(ids&&(!btnConfig||btnConfig.code==='editInventory')){
        var tempIds=ids.split(',');
        const json=initFilter(this.props.login.OrgId,'','CREATE_TIME',1);
        extendInclude(json,'Nav_Product');
        extendInclude(json,'Nav_Location');
        let group=initFilterGroup(false);
        tempIds.forEach((i,n) => {
            extendGroupRule(group,'ID',1,i);
        });
        extendFilterGroup(json,group);
        this.props.dispatch({
          type: 'app/getDataByPost',
          payload: json,
          url:'WH/Inventory/OrderEntities',
          onComplete: (ret) => {
            if (ret) {
              const data={...this.state.data};
              const tmp=[];
              ret.forEach((n,i)=>{
                tmp.push({
                  ...n,
                  ROW_NO:(i+1),
                  ID:guid(),
                  INVENTORY_CHANGE_ID:data.ID,
                  INVENTORY_ID:n.ID,
                  CREATE_TIME:null,
                  MODIFY_TIME:null,
                  CREATER_ID:null,
                  MODIFIER_ID:null
                });
              });
              data.Nav_Details=tmp; 
              this.setState({
                data: data,
              });
            }
          }
        });

    } 
  }
  
  onRenderRowControl(params){
    const {colConfig,record}=params?params:{};
    if(colConfig&&colConfig.code==='inventoryReadOnly'&&record&&record.INVENTORY_ID){
      return this.getControl({field:colConfig.field,value:getDataFieldValue(record,colConfig.field),controlType:1,
        disabled:true});
    }
    return super.onRenderRowControl(params);
  }

}
 

export default connect(({ login, loading,editPage ,custom }) => ({ login, loading,editPage ,custom }))(Form.create()(InventoryChangePage));
