/* 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_FQC'){
      setFieldVisible('FQC_TYPE',value);
      setFieldVisible('Nav_FQCWorkStage.NAME',value);
      setFieldVisible('FQC_AUTO_INSPEC',value);
      const pqcAutoInspec= getFieldValue('FQC_AUTO_INSPEC');
      setFieldVisible('FQC_INSPEC_QTY_OVER',value&&pqcAutoInspec);
      setFieldVisible('FQC_INSPEC_TYPE',value&&pqcAutoInspec);
      setFieldVisible('FQC_INSPEC_QTY',value&&pqcAutoInspec);
    }
    else if(colInfo.FIELD_NAME=='FQC_AUTO_INSPEC'){
      setFieldVisible('FQC_INSPEC_QTY_OVER',value);
      setFieldVisible('FQC_INSPEC_TYPE',value);
      setFieldVisible('FQC_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);
      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);
    }
  },
  //setFieldVisibleByBatch:批次更新字段可见性   参数：对象列表 field:字段名称  visible:是否显示
  onBeforeEdit:({isNew,stateData,login,getFieldValue,setFieldValueByBatch,setFieldEditable,setFieldVisibleByBatch})=>{
    let isPqc=stateData.IS_FQC?stateData.IS_FQC:login.baseConfig.IS_FQC;
    let pqcAutoInspec=stateData.FQC_AUTO_INSPEC?stateData.FQC_AUTO_INSPEC:login.baseConfig.FQC_AUTO_INSPEC;
    let type=stateData.PROCEDURE_TYPE?stateData.PROCEDURE_TYPE:0;
    const temps=[];
    temps.push({field:'IS_FQC',value:isPqc});
    temps.push({field:'FQC_AUTO_INSPEC',value:pqcAutoInspec});
    const baseConfig=login.baseConfig;
    if(baseConfig&&isNew) {
      isPqc = baseConfig.IS_FQC;
      pqcAutoInspec = baseConfig.FQC_AUTO_INSPEC;
      if (isPqc) {
       // temps.push({field:'IS_FQC',value: baseConfig.IS_FQC});
        temps.push({field:'FQC_TYPE',value: baseConfig.FQC_TYPE});
        temps.push({field:'FQC_WORKSTAGE_ID',value: baseConfig.FQC_WORKSTAGE_ID});
        temps.push({field:'Nav_FQCWorkStage.NAME',value: (baseConfig.Nav_FQCWorkStage ? baseConfig.Nav_FQCWorkStage.NAME : null)});
        if (pqcAutoInspec) {
          temps.push({field:'FQC_INSPEC_QTY',value: baseConfig.FQC_INSPEC_QTY})
          temps.push({field:'FQC_INSPEC_TYPE',value: baseConfig.FQC_INSPEC_TYPE});
          temps.push({field:'FQC_INSPEC_QTY_OVER',value: baseConfig.FQC_INSPEC_QTY_OVER});
        }
      }
      temps.push({field:'IS_QA',value: baseConfig.IS_QA});
    }
    setFieldValueByBatch(temps);
    const arrayList=[];

    arrayList.push({field: 'FQC_TYPE',visible:isPqc});
    arrayList.push({field: 'Nav_FQCWorkStage.NAME',visible:isPqc});
    arrayList.push({field: 'FQC_AUTO_INSPEC',visible:isPqc});

    arrayList.push({field: 'FQC_INSPEC_QTY_OVER',visible:isPqc&&pqcAutoInspec});
    arrayList.push({field: 'FQC_INSPEC_TYPE',visible:isPqc&&pqcAutoInspec});
    arrayList.push({field: 'FQC_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});
    setFieldVisibleByBatch(arrayList);
  },
  onBeforeSave:({data,getFieldValue,setFieldValue})=>{
  },
}
