import { message, Checkbox, Radio } from "antd/lib/index";
import { getPropertyData, extendInclude, extendRule, getDataFieldValue, setDataFieldValue, initFilter, empty, onBeforeSaveHandleRecordLog, Format } 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, 'OH022', '职业危害因素监测规则前端日志')

  },
  onBeforeEdit: ({ isNew, stateData, setFieldVisible, setFieldValue, login }) => {
    setFieldVisible("THRESHOLD_DUST", false);
    setFieldVisible("THRESHOLD_NOISE", false);
    setFieldVisible("THRESHOLD_RADIATION_05", false);
    setFieldVisible("THRESHOLD_RADIATION_10", false);
    setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
    setFieldVisible("THRESHOLD_WARTER_LOW", false);
    setFieldVisible("THRESHOLD_WARTER_HIGH", false);

    setFieldVisible("WEEKDATA", false);
    setFieldVisible("MONTH", false);
    setFieldVisible("DAY", false);

    if (!isNew) {
      const temps = [];
      switch (stateData.Nav_Type.MONITOR_TYPE) {
        case 10:
          setFieldVisible("THRESHOLD_DUST", true);
          setFieldVisible("THRESHOLD_NOISE", false);
          setFieldVisible("THRESHOLD_RADIATION_05", false);
          setFieldVisible("THRESHOLD_RADIATION_10", false);
          setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
          setFieldVisible("THRESHOLD_WARTER_LOW", false);
          setFieldVisible("THRESHOLD_WARTER_HIGH", false);
          break;
        case 20:
          setFieldVisible("THRESHOLD_DUST", false);
          setFieldVisible("THRESHOLD_NOISE", true);
          setFieldVisible("THRESHOLD_RADIATION_05", false);
          setFieldVisible("THRESHOLD_RADIATION_10", false);
          setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
          setFieldVisible("THRESHOLD_WARTER_LOW", false);
          setFieldVisible("THRESHOLD_WARTER_HIGH", false);
          break;
        case 30:
          setFieldVisible("THRESHOLD_DUST", false);
          setFieldVisible("THRESHOLD_NOISE", false);
          setFieldVisible("THRESHOLD_RADIATION_05", true);
          setFieldVisible("THRESHOLD_RADIATION_10", true);
          setFieldVisible("THRESHOLD_RADIATION_AROUND", true);
          setFieldVisible("THRESHOLD_WARTER_LOW", false);
          setFieldVisible("THRESHOLD_WARTER_HIGH", false);
          break;
        case 40:
          setFieldVisible("THRESHOLD_DUST", false);
          setFieldVisible("THRESHOLD_NOISE", false);
          setFieldVisible("THRESHOLD_RADIATION_05", false);
          setFieldVisible("THRESHOLD_RADIATION_10", false);
          setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
          setFieldVisible("THRESHOLD_WARTER_LOW", true);
          setFieldVisible("THRESHOLD_WARTER_HIGH", true);
          break;
        default:
          setFieldVisible("THRESHOLD_DUST", false);
          setFieldVisible("THRESHOLD_NOISE", false);
          setFieldVisible("THRESHOLD_RADIATION_05", false);
          setFieldVisible("THRESHOLD_RADIATION_10", false);
          setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
          setFieldVisible("THRESHOLD_WARTER_LOW", false);
          setFieldVisible("THRESHOLD_WARTER_HIGH", false);
          break;
      }
    }
  },

  onChange: ({ stateData, value, colInfo, setFieldVisible, setFieldValue, dispatch, setFieldValueByBatch, getSubTableData, updateSubTableData }) => {
    if (colInfo != null) {
      /// 生产扬尘浓度监测 10   工作场所噪声监测 20   放射源放射性监测 30   水质监测记录表单 40 
      if (colInfo.FIELD_NAME == "Nav_Type.NAME") {

        const temps = [];
        switch (stateData.Nav_Type.MONITOR_TYPE) {
          case 10:
            setFieldVisible("THRESHOLD_DUST", true);
            setFieldVisible("THRESHOLD_NOISE", false);
            setFieldVisible("THRESHOLD_RADIATION_05", false);
            setFieldVisible("THRESHOLD_RADIATION_10", false);
            setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
            setFieldVisible("THRESHOLD_WARTER_LOW", false);
            setFieldVisible("THRESHOLD_WARTER_HIGH", false);

            temps.push({ field: 'THRESHOLD_NOISE', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_05', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_10', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_AROUND', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_LOW', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_HIGH', value: null })
            setFieldValueByBatch(temps);

            break;
          case 20:
            setFieldVisible("THRESHOLD_DUST", false);
            setFieldVisible("THRESHOLD_NOISE", true);
            setFieldVisible("THRESHOLD_RADIATION_05", false);
            setFieldVisible("THRESHOLD_RADIATION_10", false);
            setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
            setFieldVisible("THRESHOLD_WARTER_LOW", false);
            setFieldVisible("THRESHOLD_WARTER_HIGH", false);

            temps.push({ field: 'THRESHOLD_DUST', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_05', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_10', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_AROUND', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_LOW', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_HIGH', value: null })
            setFieldValueByBatch(temps);

            break;
          case 30:
            setFieldVisible("THRESHOLD_DUST", false);
            setFieldVisible("THRESHOLD_NOISE", false);
            setFieldVisible("THRESHOLD_RADIATION_05", true);
            setFieldVisible("THRESHOLD_RADIATION_10", true);
            setFieldVisible("THRESHOLD_RADIATION_AROUND", true);
            setFieldVisible("THRESHOLD_WARTER_LOW", false);
            setFieldVisible("THRESHOLD_WARTER_HIGH", false);

            temps.push({ field: 'THRESHOLD_DUST', value: null })
            temps.push({ field: 'THRESHOLD_NOISE', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_LOW', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_HIGH', value: null })
            setFieldValueByBatch(temps);

            break;
          case 40:
            setFieldVisible("THRESHOLD_DUST", false);
            setFieldVisible("THRESHOLD_NOISE", false);
            setFieldVisible("THRESHOLD_RADIATION_05", false);
            setFieldVisible("THRESHOLD_RADIATION_10", false);
            setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
            setFieldVisible("THRESHOLD_WARTER_LOW", true);
            setFieldVisible("THRESHOLD_WARTER_HIGH", true);

            temps.push({ field: 'THRESHOLD_DUST', value: null })
            temps.push({ field: 'THRESHOLD_NOISE', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_05', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_10', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_AROUND', value: null })
            setFieldValueByBatch(temps);

            break;
          default:

            setFieldVisible("THRESHOLD_DUST", false);
            setFieldVisible("THRESHOLD_NOISE", false);
            setFieldVisible("THRESHOLD_RADIATION_05", false);
            setFieldVisible("THRESHOLD_RADIATION_10", false);
            setFieldVisible("THRESHOLD_RADIATION_AROUND", false);
            setFieldVisible("THRESHOLD_WARTER_LOW", false);
            setFieldVisible("THRESHOLD_WARTER_HIGH", false);

            temps.push({ field: 'THRESHOLD_DUST', value: null })
            temps.push({ field: 'THRESHOLD_NOISE', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_05', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_10', value: null })
            temps.push({ field: 'THRESHOLD_RADIATION_AROUND', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_LOW', value: null })
            temps.push({ field: 'THRESHOLD_WARTER_HIGH', value: null })
            setFieldValueByBatch(temps);
            break;
        }
      } else if (colInfo.FIELD_NAME == "MONITOR_INTERVAL") {
        // OHHazardMonitorIntervalEnum
        /// 每天 10, 每周  20, 每月  30, 每季(每季度第一月)  40, 每半年  50,  每年  60,

        const temps = [];
        switch (value) {
          case 10:
            setFieldVisible("WEEKDATA", false);
            setFieldVisible("MONTH", false);
            setFieldVisible("DAY", false);

            temps.push({ field: 'WEEKDATA', value: null })
            temps.push({ field: 'DAY', value: null })
            temps.push({ field: 'MONTH', value: null })
            setFieldValueByBatch(temps);

            break;
          case 20:
            setFieldVisible("DAY", false);
            setFieldVisible("MONTH", false);
            setFieldVisible("WEEKDATA", true);

            temps.push({ field: 'DAY', value: null })
            temps.push({ field: 'MONTH', value: null })
            setFieldValueByBatch(temps);

            break;
          case 30:
            setFieldVisible("DAY", true);
            setFieldVisible("WEEKDATA", false);
            setFieldVisible("MONTH", false);


            temps.push({ field: 'WEEKDATA', value: null })
            temps.push({ field: 'MONTH', value: null })
            setFieldValueByBatch(temps);

            break;
          case 40:
          case 50:
          case 60:

            setFieldVisible("DAY", true);
            setFieldVisible("MONTH", true);
            setFieldVisible("WEEKDATA", false);

            setFieldValue("WEEKDATA", null);
            break;
          default:
            setFieldVisible("DAY", false);
            setFieldVisible("MONTH", false);
            setFieldVisible("WEEKDATA", false);

            temps.push({ field: 'WEEKDATA', value: null })
            temps.push({ field: 'DAY', value: null })
            temps.push({ field: 'MONTH', value: null })
            setFieldValueByBatch(temps);
            break;
        }
      }
    }


    // if (colInfo.FIELD_NAME == "Nav_ListCheckProjectCategory" || colInfo.FIELD_NAME == "Nav_ListCheckRiskArea" || colInfo.FIELD_NAME == "Nav_ListCheckProject") {
    //   //填充数据  OrderPagedCheckMain
    //   var orgId = colInfo.ORG_ID;   //登录后有存储登录信息
    //   let json = initFilter(orgId);
    //   let CHECK_TYPE_ID = getFieldValue("CHECK_TYPE_ID")
    //   let CHECK_TYPE_LEVEL_ID = getFieldValue("CHECK_TYPE_LEVEL_ID")

    //   extendRule(json, 'Parameter2', 1, CHECK_TYPE_ID);
    //   extendRule(json, 'Parameter3', 1, getFieldValue("CHECKOBJECT"));
    //   extendRule(json, 'Parameter4', 1, CHECK_TYPE_LEVEL_ID);

    //   let listArea = getFieldValue("Nav_ListCheckRiskArea")
    //   let areaIDs = ""
    //   if (listArea != undefined && listArea.length > 0) {
    //     for (let i = 0; i < listArea.length; i++) {
    //       if (listArea[i].IS_DELETED == undefined || listArea[i].IS_DELETED == null || listArea[i].IS_DELETED == false)
    //         areaIDs += (areaIDs.length > 0 ? "," : "") + listArea[i].RISK_AREA_ID
    //     }
    //   }
    //   extendRule(json, 'Parameter5', 1, areaIDs);

    //   let listProject = getFieldValue("Nav_ListCheckProject")
    //   let ProjectIDs = ""
    //   if (listProject != undefined && listProject.length > 0) {
    //     for (let i = 0; i < listProject.length; i++) {
    //       if (listProject[i].IS_DELETED == undefined || listProject[i].IS_DELETED == null || listProject[i].IS_DELETED == false)
    //         ProjectIDs += (ProjectIDs.length > 0 ? "," : "") + listProject[i].CHECK_PROJECT_ID
    //     }
    //   }
    //   extendRule(json, 'Parameter6', 1, ProjectIDs);
    //   let valCategory = getFieldValue('Nav_ListCheckProjectCategory');
    //   let ProjectCategoryIDs = ""
    //   if (valCategory != undefined && valCategory.length > 0) {
    //     for (let i = 0; i < valCategory.length; i++) {
    //       if (valCategory[i].IS_DELETED == undefined || valCategory[i].IS_DELETED == null || valCategory[i].IS_DELETED == false)
    //         ProjectCategoryIDs += (ProjectCategoryIDs.length > 0 ? "," : "") + valCategory[i].CHECK_PROJECT_CATEGORY_ID
    //     }
    //   }
    //   extendRule(json, 'Parameter1', 1, ProjectCategoryIDs);
    //   extendRule(json, 'Keyword', 1, getFieldValue("ID"));
    //   if (areaIDs.length > 0 && ProjectIDs.length > 0 && ProjectCategoryIDs.length > 0 && CHECK_TYPE_ID != undefined && CHECK_TYPE_ID.length > 0 && CHECK_TYPE_LEVEL_ID != undefined && CHECK_TYPE_LEVEL_ID.length > 0) {
    //     dispatch({
    //       type: 'app/getDataByPost',
    //       url: 'BS/BSSafeCheck/OrderPagedSafeCheckDetail',
    //       payload: json,
    //       onlyData: false,
    //       onComplete: (ret) => {
    //         let temps = [];
    //         if (ret && ret.IsSuccessful && ret.Data) {
    //           let detail = ret.Data.map((item, i) => {
    //             item['ROW_NO'] = i + 1;
    //             return item;
    //           });
    //           temps.push({ field: "Nav_ListSafeCheckDetail", value: detail });

    //           if (detail.length > 50) {
    //             notification.info({
    //               message: <a style={{ color: 'red' }}>温馨提示</a>,
    //               description: '检查任务超过50条后会影响执行效率，请谨慎操作！',
    //               placement: 'bottomLeft',
    //             });
    //           }

    //         } else {
    //           temps.push({ field: "Nav_ListSafeCheckDetail", value: null });
    //         }
    //         setFieldValueByBatch(temps);
    //       }
    //     });
    //   } else {
    //     if (stateData == undefined || (stateData != undefined && stateData.CREACTTYPE != undefined && stateData.CREACTTYPE != 30)) {
    //       let temps = [];
    //       temps.push({ field: "Nav_ListSafeCheckDetail", value: null });
    //       setFieldValueByBatch(temps);
    //     }
    //   }
    // } else {
    //   if (colInfo != null && (colInfo.FIELD_NAME == "Nav_CheckTypeLevel.Nav_Enums.NAME" || colInfo.FIELD_NAME == "Nav_CheckType.NAME")) {
    //     // getFieldValue, setFieldValue
    //     var typeName = getFieldValue("Nav_CheckType.NAME")
    //     if (typeName == null || typeName == '') {
    //       const temps = [];
    //       temps.push({ field: 'Nav_CheckTypeLevel.Nav_Enums.NAME', value: null })
    //       temps.push({ field: 'NAME', value: '' })
    //       setFieldValueByBatch(temps);
    //     } else {
    //       var levelName = getFieldValue("Nav_CheckTypeLevel.Nav_Enums.NAME")
    //       setFieldValue("NAME", (levelName == null ? "" : levelName) + (typeName == null ? "" : typeName))
    //     }
    //   }
    // }
  },

}
