import React from 'react'
import { message, Checkbox, Row, Radio } from "antd/lib/index";
// import { Checkbox } from 'antd'
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) {
    if (params.record.BACKTIME != undefined && params.record.BACKTIME.length == 13) {
      params.record.BACKTIME = params.record.BACKTIME + ":00:00"
    }

    params.record.TaskID = params.data.TaskID    //TaskID传递消息表ID
    params.record.STATUS = params.customParams;
  },
  onBeforeEdit: ({ isNew, stateData, dispatch, setFieldValueByBatch, setFieldEditable }) => {
    if (isNew) {
      //如果 尾矿库只有一条  默认选择  日期默认 当前日期
      let json = initFilter(stateData.ORG_ID);
      extendRule(json, 'STATE', 1, '20');
      json.Sort = 'CREATE_TIME'
      dispatch({
        type: 'app/getDataByPost',
        url: 'TL/Tailing/OrderPaged',
        payload: json,
        onlyData: false,
        onComplete: (ret) => {
          if (ret.IsSuccessful && ret.Data.length == 1) {
            // stateData.TAILING_ID = ret.Data[0].ID
            // stateData.Nav_Tailing = ret.Data[0]
            // stateData.TAILING_NAME = ret.Data[0].NAME
            const temps = [];
            temps.push({ field: 'TAILING_ID', value: ret.Data[0].ID })
            temps.push({ field: 'Nav_Tailing', value: ret.Data[0] })
            temps.push({ field: 'TAILING_NAME', value: ret.Data[0].NAME })
            setFieldValueByBatch(temps);
          }
        }
      })
    } else if (stateData.BACK_DETAIL_ID != undefined && stateData.BACK_DETAIL_ID != null && stateData.BACK_DETAIL_ID.length > 0) {
      //视为系统触发 不可编辑
      setFieldEditable("Nav_Tailing.NAME", false)
      setFieldEditable("BACKTIME", false)
      setFieldEditable("BACKTIMEEND", false)
      setFieldEditable("Nav_ListUser", false)
      setFieldEditable("NAME", false)
    }
  },
}
