import { message, Checkbox, Radio } from "antd/lib/index";
import { getPropertyData, extendInclude, extendRule, getDataFieldValue, setDataFieldValue, initFilter, empty, onBeforeSaveHandleRecordLog } from "../../utils/common";
import { connect } from 'dva';
import moment from 'moment';
/**
 * @return {string}
 */
// 编辑  安全科技计划
export default {
  onBeforeSaveHandleRecord(params) {
    params.record.TaskID = params.data.TaskID    //TaskID传递消息表ID
    params.record.STATUS = params.customParams;
    onBeforeSaveHandleRecordLog(params, 'TI008', '前端日志')
  },

  onBeforeEdit: ({ isNew, setFieldValueByBatch, login }) => {
    if (isNew) {
      const temps = [];
      temps.push({ field: 'DEPARTMENT_ID', value: login.user.DEPARTMENT_ID });
      temps.push({ field: 'Nav_Department.NAME', value: login.user.Nav_Department.NAME });
      temps.push({ field: 'USER_ID', value: login.user.ID })
      temps.push({ field: 'Nav_User.NAME', value: login.user.NAME })
      temps.push({ field: 'BEGINTIME', value: (new Date()).Format("yyyy-MM-dd HH:mm:ss") })
      temps.push({ field: 'YEAR', value: (new Date()).Format("yyyy") })
      setFieldValueByBatch(temps);
    }
  },

  onChange: ({ value, colInfo, dispatch, setFieldValueByBatch, record, stateData, data, getFieldValue, setFieldVisible, setFieldValue }) => {
    if (colInfo != null && colInfo.FIELD_NAME == "Nav_Department.NAME") {
      const temps = [];
      temps.push({ field: 'USER_ID', value: null })
      temps.push({ field: 'Nav_User.NAME', value: null })
      setFieldValueByBatch(temps);
    } else if (colInfo != null && colInfo.FIELD_NAME == "Nav_Project.CODE") {
      // 项目编号 加载 项目来源 所属范围  Nav_Project.Nav_Sources  Nav_Project.Nav_Ranges
      var projectID = getFieldValue("PROJECT_ID")
      if (projectID != undefined && projectID != null && projectID.length > 0) {
        let json = initFilter(colInfo.ORG_ID, projectID);
        extendInclude(json, 'Nav_Sources.Nav_Source');
        extendInclude(json, 'Nav_Ranges.Nav_Range');
        extendInclude(json, 'Nav_Manger');
        dispatch({
          type: 'app/getDataByPost',
          url: 'TI/TIProject/GetCheck',
          payload: json,
          onlyData: false,
          onComplete: (ret) => {
            let temps = [];
            var strSource = ""
            var strRange = ""
            if (ret && ret.IsSuccessful && ret.Data) {
              if (ret.Data.Nav_Sources != null && ret.Data.Nav_Sources.length > 0) {
                for (let i = 0; i < ret.Data.Nav_Sources.length; i++) {
                  strSource += (strSource.length > 0 ? "," : "") + ret.Data.Nav_Sources[i].Nav_Source.NAME
                }
              }
              if (ret.Data.Nav_Ranges != null && ret.Data.Nav_Ranges.length > 0) {
                for (let i = 0; i < ret.Data.Nav_Ranges.length; i++) {
                  strRange += (strRange.length > 0 ? "," : "") + ret.Data.Nav_Ranges[i].Nav_Range.NAME
                }
              }
              temps.push({ field: 'PROJECT_ID', value: ret.Data.ID })
              temps.push({ field: 'Nav_Project.NAME', value: ret.Data.NAME })
              temps.push({ field: 'Nav_Project.CODE', value: ret.Data.CODE })
              temps.push({ field: 'Nav_Project.YEAR', value: ret.Data.YEAR })
              temps.push({ field: 'Nav_Project.Nav_Manger.NAME', value: ret.Data.Nav_Manger.NAME })
              temps.push({ field: 'Nav_Project.IS_FOREIGN', value: ret.Data.IS_FOREIGN })
            } else {
              temps.push({ field: 'PROJECT_ID', value: '' })
              temps.push({ field: 'Nav_Project.NAME', value: '' })
              temps.push({ field: 'Nav_Project.CODE', value: '' })
              temps.push({ field: 'Nav_Project.YEAR', value: '' })
              temps.push({ field: 'Nav_Project.Nav_Manger.NAME', value: '' })
              temps.push({ field: 'Nav_Project.IS_FOREIGN', value: '' })
            }
            temps.push({ field: 'Nav_Project.Nav_Sources', value: strSource })
            temps.push({ field: 'Nav_Project.Nav_Ranges', value: strRange })
            setFieldValueByBatch(temps);
          }
        });
      } else {
        const temps = [];
        temps.push({ field: 'PROJECT_ID', value: '' })
        temps.push({ field: 'Nav_Project.NAME', value: '' })
        temps.push({ field: 'Nav_Project.CODE', value: '' })
        temps.push({ field: 'Nav_Project.YEAR', value: '' })
        temps.push({ field: 'Nav_Project.Nav_Manger.NAME', value: '' })
        temps.push({ field: 'Nav_Project.IS_FOREIGN', value: '' })

        temps.push({ field: 'Nav_Project.Nav_Sources', value: "" })
        temps.push({ field: 'Nav_Project.Nav_Ranges', value: "" })
        setFieldValueByBatch(temps);

      }
    }
  },
}
