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;

    // STR_RATIO

    onBeforeSaveHandleRecordLog(params, 'OH028', '监测结果统计与分析汇总前端日志')
  },

  onBeforeEdit: ({ isNew, stateData, dispatch, login, app, setFieldValue }) => {
    //(stateData.RATIO == null || stateData.RATIO == 0) && 
    if (stateData.Nav_ListMonitorResult != null && stateData.Nav_ListMonitorResult.length > 0) {
      var radio = 0;
      let countHas = 0;
      for (let i = 0; i < stateData.Nav_ListMonitorResult.length; i++) {
        if (stateData.Nav_ListMonitorResult[i].TREND != null && stateData.Nav_ListMonitorResult[i].TREND.length > 0) {
          countHas++
        }
      }
      if (countHas == 0) {
        // setFieldValue("RATIO", '');
        setFieldValue("STR_RATIO", '');
      } else {
        radio = (100.0 * countHas / stateData.Nav_ListMonitorResult.length).toFixed(1)
        // setFieldValue("RATIO", radio);
        setFieldValue("STR_RATIO", radio + '%');
      }
    }
  },
  onSubChange: ({ row, pageCode, record, colInfo, dispatch, stateData, setFieldValue, setDataState, setFieldValueByBatch }) => {
    if (colInfo != null && colInfo.FIELD_NAME == "TREND") {
      if (stateData.Nav_ListMonitorResult != null && stateData.Nav_ListMonitorResult.length > 0) {
        var radio = 0;
        let countHas = 0;
        for (let i = 0; i < stateData.Nav_ListMonitorResult.length; i++) {
          if (stateData.Nav_ListMonitorResult[i].TREND != null && stateData.Nav_ListMonitorResult[i].TREND.length > 0) {
            countHas++
          }
        }
        if (countHas == 0) {
          // stateData.RATIO = ''
          stateData.STR_RATIO = ''
          stateData.RATIO = 0
        } else {
          radio = (100.0 * countHas / stateData.Nav_ListMonitorResult.length).toFixed(1)
          // stateData.RATIO = radio
          stateData.STR_RATIO = radio + '%'
          stateData.RATIO = radio / 100.0
        }
      }
    }
  }
}
