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

/**
 * @return {string}
 */

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


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

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

      dispatch({
        type: 'app/genSystemCode',
        payload: json,
        onComplete: (ret) => {
          if (ret) {
            const temps=[];
            temps.push({field:'IN_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);
          }
        }
      });

      let filter = initFilter(login.OrgId,'','NAME',0);
      extendRule(filter,"TYPE",1,1);
      dispatch({
        type: 'app/getDataByPost',
        payload: filter,
        url:'FM/Warehouse/OrderPaged',
        onComplete: (ret) => {
          if (ret&&ret.length>0) {
            const temps=[];
            temps.push({field:'Nav_Warehouse.NAME',value:ret[0].NAME});
            temps.push({field:'WAREHOUSE_ID',value:ret[0].ID});
            setFieldValueByBatch(temps);
          }
        }
      });
    }
  },
  onBeforeSave:({data,getFieldValue,setFieldValue})=>{
  },
}
