/* eslint-disable no-undef */
import {extendInclude, extendRule, initFilter} from "../../utils/common";

/**
 * @return {string}
 */
//工艺线路明细
export default {
  onChange: ({value,colInfo,getFieldValue,setFieldValue,setFieldEditable,setFieldVisible}) => {
    if(colInfo.FIELD_NAME=='IS_PQC'){
      setFieldVisible('PQC_TYPE',value);
      setFieldVisible('Nav_PQCWorkStage.NAME',value);
      setFieldVisible('PQC_AUTO_INSPEC',value);
      const pqcAutoInspec= getFieldValue('PQC_AUTO_INSPEC');
      setFieldVisible('PQC_INSPEC_QTY_OVER',value&&pqcAutoInspec);
      setFieldVisible('PQC_INSPEC_TYPE',value&&pqcAutoInspec);
      setFieldVisible('PQC_INSPEC_QTY',value&&pqcAutoInspec);
    }
    else if(colInfo.FIELD_NAME=='PQC_AUTO_INSPEC'){
      setFieldVisible('PQC_INSPEC_QTY_OVER',value);
      setFieldVisible('PQC_INSPEC_TYPE',value);
      setFieldVisible('PQC_INSPEC_QTY',value);
    }
    else if(colInfo.FIELD_NAME=='PROCEDURE_TYPE'){
      setFieldVisible('ORDER_FIELD',value==1);
      setFieldVisible('PRO_TYPE',value==0);
      setFieldVisible('UNIT',value==0);
      setFieldVisible('TIME_UNIT',value==0);
      setFieldVisible('CONVERT_RATIO',value==0);
      setFieldVisible('STANDARD_TIME',value==0);
      setFieldVisible('IS_PQC',value==0);
      var proType= getFieldValue('PRO_TYPE');
      setFieldVisible('BOOK_BAD',value==0&&proType);
    }
    else if(colInfo.FIELD_NAME=='PRO_TYPE'){
      setFieldVisible('BOOK_BAD',value!=0);
    }
  },
  onFetchAutoFilter:({colInfo,params,getFieldValue})=>{
    if(colInfo.FIELD_NAME=='Nav_PQCWorkStage.NAME') {
          extendRule(params, 'TYPE', 1,2)
        }

  },
  onBeforeEdit:({isNew,stateData,getFieldValue,data,setFieldValueByBatch,dispatch,login,setFieldEditable,setFieldVisibleByBatch})=>{
    if(isNew){
      const temps=[];
      temps.push({field:'UNIT',value:1});
      temps.push({field:'CONVERT_RATIO',value:1});
      temps.push({field:'TYPE',value:0});
      temps.push({field:'PRO_TYPE',value:2});
      temps.push({field:'PROCESS_ID',value:data.processId});
      const json = initFilter(login.ORG_ID, '', 'NUM', 1);
      extendRule(json,'PROCESS_ID',1,data.processId);
      dispatch({
        type: 'FMProcess/getMaxNum',
        payload: json,
        onComplete: (ret) => {
          temps.push({field:'NUM',value:ret});
          setFieldValueByBatch(temps);
        }
      });
    }

    let isPqc=stateData.IS_PQC?stateData.IS_PQC:false;
    let pqcAutoInspec=stateData.PQC_AUTO_INSPEC?stateData.PQC_AUTO_INSPEC:false;
    let type=stateData.PROCEDURE_TYPE?stateData.PROCEDURE_TYPE:0;
    let proType=stateData.PRO_TYPE?stateData.PRO_TYPE:0;
    const arrayList=[];
    arrayList.push({field: 'PQC_TYPE',visible:isPqc});
    arrayList.push({field:'Nav_PQCWorkStage.NAME',visible:isPqc});
    arrayList.push({field:'PQC_AUTO_INSPEC',visible:isPqc});

    arrayList.push({field:'PQC_INSPEC_QTY_OVER',visible:isPqc&&pqcAutoInspec});
    arrayList.push({field:'PQC_INSPEC_TYPE',visible:isPqc&&pqcAutoInspec});
    arrayList.push({field:'PQC_INSPEC_QTY',visible:isPqc&&pqcAutoInspec});

    arrayList.push({field:'ORDER_FIELD',visible:type==1});
    arrayList.push({field: 'PRO_TYPE',visible:type==0});
    arrayList.push({field: 'UNIT',visible:type==0});
    arrayList.push({field: 'TIME_UNIT',visible:type==0});
    arrayList.push({field: 'CONVERT_RATIO',visible:type==0});
    arrayList.push({field: 'STANDARD_TIME',visible:type==0});
    arrayList.push({field: 'IS_PQC',visible:type==0});
    arrayList.push({field: 'BOOK_BAD',visible:type==0&&proType!=0});

    setFieldVisibleByBatch(arrayList);
  },
  onBeforeSave:({data,getFieldValue,setFieldValue})=>{

    //temps.push({field:'PROCESS_ID',value:data.processId});
    //console.log(data.processId);
  },

}
