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

/**
 * @return {string}
 */
//半成品编辑页 FM020
export default {
  onChange: ({value,colInfo,getFieldValue,setFieldValue,setFieldEditable}) => {
    if(colInfo&&colInfo.FIELD_NAME=='IS_PRODUCT_CHECK') {
      if (value) {
        setFieldEditable('PRODUCT_CHECK_TYPE', true);
        setFieldEditable('Nav_WorkStage.NAME', true);
      }
      else {
        setFieldEditable('PRODUCT_CHECK_TYPE', false);
        setFieldEditable('Nav_WorkStage.NAME', false);
      }
    }
  },
  onFetchAutoFilter:({colInfo,params,getFieldValue})=>{
    if(colInfo.FIELD_NAME=='Nav_WorkStage.NAME') {
      extendRule(params, 'TYPE', 1,2);
      extendRule(params, 'ENABLE_STATUS', 1,0);
    }
    else if(colInfo.FIELD_NAME=='Nav_ProductCategory.NAME') {
      extendRule(params, 'ENABLE_STATUS', 1,0);
      extendRule(params, 'PRODUCT_CATEGORY_TYPE', 1,1);
    };
  },
  onBeforeEdit:({isNew,getFieldValue,setFieldValueByBatch,login,setFieldEditable})=>{
    if(isNew){
      const temps=[];
      const isCheck=login.baseConfig?login.baseConfig.IN_MATERIAL_IS_CHECK:false;
      temps.push({field:'IS_PRODUCT_CHECK',value: isCheck});
      if(isCheck){
        temps.push({field:'PRODUCT_CHECK_TYPE',value: (login.baseConfig?login.baseConfig.IN_MATERIAL_CHECK_TYPE:0)});
      }
      else{
        setFieldEditable('PRODUCT_CHECK_TYPE', false);
        setFieldEditable('Nav_WorkStage.NAME', false);
      }
      temps.push({field:'PRODUCT_TYPE',value:1});
      setFieldValueByBatch(temps)
    }
    else if(getFieldValue('IS_PRODUCT_CHECK')==0||!getFieldValue('IS_PRODUCT_CHECK')){
      setFieldEditable('PRODUCT_CHECK_TYPE',false);
      setFieldEditable('Nav_WorkStage.NAME', false);
    }
  },
  onBeforeSave:({data,getFieldValue,setFieldValue})=>{
  },
}
