/* 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 == 'DATA_TYPE') {
      setFieldVisible('Nav_SrcTag.NAME', value == 2 ? false : true);
      var change=getFieldValue('CHANGE');
      if(value==1)//累计变量
    {
      setFieldVisible('LIMIT_MIN', change);
      setFieldVisible('LIMIT_MAX', change);
      setFieldVisible('FORCE_VALIDA', change);
      setFieldVisible('CHANGE_RATE', false);
      setFieldVisible('CHANGE', true);
    }
    else if(value==0)//瞬时变量
    {
      setFieldVisible('LIMIT_MIN', false);
      setFieldVisible('LIMIT_MAX', false);
      setFieldVisible('CHANGE_RATE', change);
      setFieldVisible('FORCE_VALIDA', change);
      setFieldVisible('CHANGE', true);
    }else{
      setFieldVisible('LIMIT_MIN', false);
      setFieldVisible('LIMIT_MAX', false);
      setFieldVisible('CHANGE_RATE', false);
      setFieldVisible('CHANGE', false);
      setFieldVisible('FORCE_VALIDA', false);
    }

    }
    if (colInfo.FIELD_NAME == 'CHANGE') {
      var dataType=getFieldValue('DATA_TYPE');
      if(dataType==1)//累计变量
    {
      setFieldVisible('LIMIT_MIN', value);
      setFieldVisible('LIMIT_MAX', value);
      setFieldVisible('FORCE_VALIDA', value);
      setFieldVisible('CHANGE_RATE', false);
    }
    if(dataType==0)//瞬时变量
    {
      setFieldVisible('LIMIT_MIN', value);
      setFieldVisible('LIMIT_MAX', value);
      setFieldVisible('FORCE_VALIDA', value);
      setFieldVisible('CHANGE_RATE', value);
    }
    }
  },
  onBeforeEdit: ({ isNew, stateData, login, getFieldValue, setFieldValue, setFieldValueByBatch, setFieldEditable, setFieldVisible }) => {
    const val = stateData.CHANGE ? true : false;
    if(stateData.DATA_TYPE==1)//累计变量
    {
      setFieldVisible('LIMIT_MIN', val);
      setFieldVisible('LIMIT_MAX', val);
      setFieldVisible('CHANGE_RATE', false);
      setFieldVisible('CHANGE', true);
      setFieldVisible('FORCE_VALIDA', val);
    }
    else if(stateData.DATA_TYPE==0)//瞬时变量
    {
      setFieldVisible('LIMIT_MIN', false);
      setFieldVisible('LIMIT_MAX', false);
      setFieldVisible('CHANGE_RATE', val);
      setFieldVisible('FORCE_VALIDA', val);
      setFieldVisible('CHANGE', true);
    }else{
      setFieldVisible('LIMIT_MIN', false);
      setFieldVisible('LIMIT_MAX', false);
      setFieldVisible('CHANGE_RATE', false);
      setFieldVisible('CHANGE', false);
      setFieldVisible('FORCE_VALIDA', false);
    }

    setFieldVisible('Nav_SrcTag.NAME', stateData.DATA_TYPE == 2 ? false : true);

    if(!isNew && stateData.DATA_TYPE == 2)
    {
      setFieldEditable('DATA_TYPE', false);
      setFieldEditable('Nav_SrcTag.Nav_DataFrequency.NAME', false);
    }

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