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

/**
 * @return {string}
 */

export default {
  onChange: ({value,colInfo,getFieldValue,setFieldValue,setFieldEditable}) => {


  },
  onFetchAutoFilter:({colInfo,params,getFieldValue})=>{

    if(colInfo.FIELD_NAME=='Nav_Client.NAME') {

      extendRule(params, 'ENABLE_STATUS', 1,0);
    }
  },

  onFetchAutoFilterDetail:({colInfo,params,record})=>{

    if(colInfo.FIELD_NAME=='PRODUCT_OTHER_CODE') {
      if(record) {
        params['Keyword'] = record.PRODUCT_ID;
      }
    }
  },
  onBeforeEdit:({isNew,dispatch,login,getFieldValue,setFieldValueByBatch,setFieldEditable})=>{

    if(isNew){
      const json=initFilter(login.OrgId);
      json.Count=1;
      json.CodeType=5000

      dispatch({
        type: 'app/genSystemCode',
        payload: json,
        onComplete: (ret) => {

          if (ret) {
            const temps=[];
            temps.push({field:'CODE',value:ret});
            setFieldValueByBatch(temps);
          }
        }
      })
    }

  },
  onBeforeSave:({data,getFieldValue,setFieldValue,stateData})=>{
    if(stateData&&stateData.Nav_Details){
      stateData.Nav_Details.forEach((n,i)=>{
        if(n.PRODUCT_OTHER_CODE_2){
          n.PRODUCT_OTHER_CODE=n.PRODUCT_OTHER_CODE_2;
        }
      });
    }
  },
  onAfterAddSubRow:({record,stateData})=>{
    if(stateData&&stateData.length){
      stateData.forEach((n,i)=>{
        if(n.PLAN_DELIVERY_TMIE&&!record.PLAN_DELIVERY_TMIE){
          record.PLAN_DELIVERY_TMIE=n.PLAN_DELIVERY_TMIE;
        }
      });
    }
  },
}
