import { message, Checkbox, Radio } from "antd/lib/index";
import { getPropertyData, extendInclude, extendRule, guid, getDataFieldValue, setDataFieldValue, initFilter, empty, onBeforeSaveHandleRecordLog, Format } from "../../utils/common";
import { connect } from 'dva';
import moment from 'moment';
import SC030 from "./SC030";
/**
 * @return {string}
 */
// 编辑  应急响应评估
export default {
  onBeforeSaveHandleRecord(params) {
    params.record.TaskID = params.data.TaskID    //TaskID传递消息表ID
    params.record.STATUS = params.customParams;
    onBeforeSaveHandleRecordLog(params, 'CM023', '应急响应评估')
  },

  onBeforeEdit: ({ isNew, setFieldValueByBatch, setFieldEditable, login, stateData, dispatch, updateSubTableData }) => {
    if (isNew) {
      const temps = [];
      temps.push({ field: 'DEPARTMENT_ID', value: login.user.Nav_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: 'LAUNCH_TIME', value: (new Date()).Format("yyyy-MM-dd") })
      setFieldValueByBatch(temps);

      setFieldEditable("Nav_Department.NAME", false);
      setFieldEditable("Nav_User.NAME", false);
      setFieldEditable("LAUNCH_TIME", false);

      let json = initFilter(login.OrgId);
      dispatch({
        type: 'app/getDataByPost',
        url: 'CM/RspEstimateCondition/OrderPaged',
        payload: json,
        onlyData: false,
        onComplete: (ret) => {
          if (ret && ret.IsSuccessful && ret.Data) {
            const details = [];
            ret.Data.forEach(t => {
              details.push({
                ID: guid(),
                ESTIMATE_ID: stateData.ID,
                CONDITION_ID: t.ID,
                Nav_RspEstimateCondition: {
                  NAME: t.NAME,
                  CODE: t.CODE,
                },
              });
            });
            updateSubTableData({ pageCode: 'ListRspConditions', data: details });
          }
        }
      })


    }
  },
  //没法关联事故事件
  // onChange: ({ stateData, login, setRowFieldVisible, value, colInfo, setFieldVisible, setFieldValue, dispatch, setFieldValueByBatch, getSubTableData, updateSubTableData }) => {
  //   if (colInfo != null && colInfo.FIELD_NAME == "EVENT_NAME") {
  //     //选择事故事件
  //     let json = initFilter(login.OrgId);
  //     extendRule(json, 'EventID', 1, stateData.EVENT_ID);
  //     extendRule(json, 'ID', 1, stateData.ID);
  //     dispatch({
  //       type: 'app/getDataByPost',
  //       url: 'CM/CMRspEstimate/GetEventKinds',
  //       payload: json,
  //       onlyData: false,
  //       onComplete: (ret) => {
  //         if (ret && ret.IsSuccessful && ret.Data) {
  //           stateData.Nav_ListEventKind = ret.Data
  //         }
  //       }
  //     })
  //   }
  // }
}
