import { message } from "antd/lib/index";
import { getPropertyData, extendInclude, extendRule, getDataFieldValue, setDataFieldValue, initFilter, guid } from "../../utils/common";
import moment from 'moment';
import config from "../../config.js"
import storage from '../../utils/storage'
import { Button, Row, Col, Form, Input, Select, Upload, Icon, Modal, Spin,Table } from 'antd';
/**
 * @return {string}
 */
// 编辑
export default {
  onBeforeSaveHandleRecord(params) {
    params.record.TaskID = params.data.TaskID    //TaskID传递消息表ID
    params.record.PUBLISH = params.customParams;
    // params.record.FORM_CODE = params.data.reloadKey.substring(0,params.data.reloadKey.indexOf("_"));
  },
  onBeforeEdit(params) {
    const { isNew, dispatch, login, setFieldRequired,setFieldValueByBatch, setFieldEditable, getFieldValue,stateData } = params ? params : {};
    if (isNew) {
      let json = initFilter(login.OrgId);
      dispatch({
        type: 'app/getDataByPost',
        payload: json,
        url: 'PT/PTIndicatorFormulation/GetVersionEdit',
        onComplete: (ret) => {
          if (ret) {
            let temps = [];
            temps.push({ field: 'ID', value: ret.ID })
            temps.push({ field: 'NAME', value: ret.NAME })
            temps.push({ field: 'YEAR', value: ret.YEAR })
            temps.push({ field: 'SET_TIME', value:ret.SET_TIME})// moment(ret.SET_TIME).format('YYYY-MM-DD HH:mm:ss') 
            temps.push({ field: 'USER_ID', value: ret.USER_ID })
            temps.push({ field: 'Nav_User', value: ret.Nav_User})
            temps.push({ field: 'DEPARTMENT_ID', value: ret.DEPARTMENT_ID})
            temps.push({ field: 'Nav_Department', value: ret.Nav_Department})
            // temps.push({ field: 'FORMULATE_ID', value: ret.FORMULATE_ID})
            temps.push({ field: 'Nav_Formulates', value: ret.Nav_Formulates})
            temps.push({ field: 'IS_DEMAND', value: ret.IS_DEMAND})
            temps.push({ field: 'IS_TARGET', value: ret.IS_TARGET})
            temps.push({ field: 'IS_PLAN', value: ret.IS_PLAN})
            temps.push({ field: 'Nav_Files', value: ret.Nav_Files})
            // temps.push({ field: 'Nav_Files.Nav_ImgFile', value: ret.Nav_Files.Nav_ImgFile})
            // temps.push({ field: 'RESOURCES_ID', value: ret.RESOURCES_ID})
            temps.push({ field: 'Nav_PlanResources', value: ret.Nav_PlanResources})
            temps.push({ field: 'Nav_PlanFiles', value: ret.Nav_PlanFiles})
            temps.push({ field: 'Nav_Goals', value: ret.Nav_Goals})
            temps.push({ field: 'REASON', value: ret.REASON})
            temps.push({ field: 'PROFILE', value: ret.PROFILE})
            temps.push({ field: 'VERSION', value: ret.VERSION})
            setFieldValueByBatch(temps);
            if(ret.IS_PLAN === true)
            {
                setFieldRequired('Nav_PlanResources', true);
                setFieldRequired('Nav_PlanFiles', true);
                setFieldEditable('Nav_PlanResources', true);
                setFieldEditable('Nav_PlanFiles', true);
            } else {
              setFieldRequired('Nav_PlanResources', false);
              setFieldRequired('Nav_PlanFiles', false);
              setFieldEditable('Nav_PlanResources', false);
              setFieldEditable('Nav_PlanFiles', false);
            }
          }
        }
      });
    }
  },
  onChange: ({ value, colInfo, getFieldValue, setFieldVisible, setFieldValue, setFieldEditable, setFieldRequired, resetFields }) => {
    if (colInfo.FIELD_NAME == 'IS_PLAN') {
      if (getFieldValue('IS_PLAN') == true) {
        setFieldRequired('Nav_PlanResources', true);
        setFieldRequired('Nav_PlanFiles', true);
        setFieldEditable('Nav_PlanResources', true);
        setFieldEditable('Nav_PlanFiles', true);
      } else {
        setFieldRequired('Nav_PlanResources', false);
        setFieldRequired('Nav_PlanFiles', false);
        setFieldEditable('Nav_PlanResources', false);
        setFieldEditable('Nav_PlanFiles', false);
      }
    }
  },
}
