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

/**
 * @return {string}
 */

export default {
  onChange: ({value,colInfo,getFieldValue,setFieldVisible,setFieldValue,setFieldEditable}) => {
    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);
      extendRule(params, 'ENABLE_STATUS', 1,0);
    }
  },
  onBeforeEdit:({isNew,stateData,login,getFieldValue,setFieldValue,setFieldValueByBatch,setFieldEditable,setFieldVisible})=>{
    let isPqc=stateData.IS_PQC?stateData.IS_PQC:login.baseConfig.IS_PQC;
    let pqcAutoInspec=stateData.PQC_AUTO_INSPEC?stateData.PQC_AUTO_INSPEC:login.baseConfig.PQC_AUTO_INSPEC;
    let type=stateData.PROCEDURE_TYPE?stateData.PROCEDURE_TYPE:0;
    let proType=stateData.PRO_TYPE?stateData.PRO_TYPE:2;//工序类别： 计划工序 = 0,报工工序 = 1,计划且报工 = 2
    const temps=[];
    temps.push({field:'IS_PQC',value:isPqc});
    temps.push({field:'PQC_AUTO_INSPEC',value:pqcAutoInspec});
    temps.push({field:'PRO_TYPE',value:proType});
    if(isNew){
      temps.push({field:'BATCH_BULK',value:true});
      temps.push({field:'UNIT',value:1});
      temps.push({field:'CONVERT_RATIO',value:1});
      temps.push({field:'PROCEDURE_TYPE',value:0});

      const baseConfig=login.baseConfig;
      if(baseConfig){
        isPqc=baseConfig.IS_PQC;
        pqcAutoInspec=baseConfig.PQC_AUTO_INSPEC;
        if(isPqc){
          temps.push({field:'PQC_TYPE',value:baseConfig.PQC_TYPE});
          temps.push({field:'PQC_WORKSTAGE_ID',value:baseConfig.PQC_WORKSTAGE_ID});
          temps.push({field:'Nav_PQCWorkStage.NAME',value:(baseConfig.Nav_PQCWorkStage?baseConfig.Nav_PQCWorkStage.NAME:null)});
          if(pqcAutoInspec){
            temps.push({field:'PQC_INSPEC_QTY',value:baseConfig.PQC_INSPEC_QTY})
            temps.push({field:'PQC_INSPEC_TYPE',value:baseConfig.PQC_INSPEC_TYPE});
            temps.push({field:'PQC_INSPEC_QTY_OVER',value:baseConfig.PQC_INSPEC_QTY_OVER});
          }
        }
      }
      setFieldValueByBatch(temps);
    }
    setFieldVisible('PQC_TYPE',isPqc);
    setFieldVisible('Nav_PQCWorkStage.NAME',isPqc);
    setFieldVisible('PQC_AUTO_INSPEC',isPqc);

    setFieldVisible('PQC_INSPEC_QTY',isPqc&&pqcAutoInspec);
    setFieldVisible('PQC_INSPEC_TYPE',isPqc&&pqcAutoInspec);
    setFieldVisible('PQC_INSPEC_QTY_OVER',isPqc&&pqcAutoInspec);

    setFieldVisible('ORDER_FIELD',type==1);
    setFieldVisible('PRO_TYPE',type==0);
    setFieldVisible('UNIT',type==0);
    setFieldVisible('TIME_UNIT',type==0);
    setFieldVisible('CONVERT_RATIO',type==0);
    setFieldVisible('STANDARD_TIME',type==0);
    setFieldVisible('IS_PQC',type==0);
    setFieldVisible('BOOK_BAD',type==0&&proType!=0);
  },
  onBeforeSave:({data,getFieldValue,setFieldValue})=>{
  },
}
