/* eslint-disable no-undef */
import {extendInclude, extendRule, initFilter} from "../../utils/common";
import moment from 'moment';
import {message} from "antd/lib/index";

/**
 * @return {string}
 */

export default {
  onChange: ({value,colInfo,login,dispatch,getFieldValue,setFieldValueByBatch,setFieldEditable}) => {

    if(colInfo.FIELD_NAME=='Nav_PdtOrder.PDT_CODE')
    {
      const pdtId= getFieldValue('PDT_ID');
      if(pdtId) {
        const json = initFilter(login.OrgId, pdtId, '', 0, 1);
        dispatch({
          type: 'WHLocation/getMaxLocationId',
          payload: json,
          onComplete: (ret) => {
            if (ret) {
              const temps=[];
              temps.push({field:'LOCATION_ID',value: ret.ID});
              temps.push({field:'Nav_Location.NAME',value: ret.NAME});
              setFieldValueByBatch(temps);
            }
          }
        })
      }
    }
  },
  onFetchAutoFilter:({colInfo,params,getFieldValue})=>{
    if(colInfo.FIELD_NAME=='Nav_PdtOrder.PDT_CODE')
    {
      console.log("null");
    }

  },
  onBeforeEdit:({isNew,getFieldValue,login,dispatch,setFieldValueByBatch,setFieldEditable})=>{
    if(isNew) {
      const json = initFilter(login.OrgId);
      json.Count = 1;
      json.CodeType = 3505

      dispatch({
        type: 'app/genSystemCode',
        payload: json,
        onComplete: (ret) => {
          if (ret) {
            const temps=[];
            temps.push({field:'CODE', value:ret});
            temps.push({field:'Nav_User.NAME',  value:login.user.NAME});
            temps.push({field:'USER_ID', value:login.userId});
            temps.push({field:'DATE_TIME', value:moment(new Date()).format('YYYY-MM-DD HH:mm:ss')});
            setFieldValueByBatch(temps);
          }
        }
      })
    }
  },
  onBeforeSave:({data,getFieldValue,setFieldValue})=>{
  },
}
