import ConfirmButton from '../../components/common/ConfirmButton';
import { message } from "antd/lib/index";
import React from 'react';
import FormPage from '../../components/FormPage';
import { onBeforeSaveHandleRecordLog} from "../../utils/common";

export default {
  onBeforeSaveHandleRecord(params) {
    onBeforeSaveHandleRecordLog(params,'FO012','FO012_BeforeSave')
  },
  btnSaveNotice: ({ record, data, getLoadParam, login, dispatch, props, saveData,validateFieldsAndScroll }) => {
    validateFieldsAndScroll((errors, values) => {
      if (errors) return;
    record.TaskID = data.TaskID
    dispatch({
      type: 'app/getDataByPost',
      url: 'FO/FOChangeShiftRecord/SaveAndNotice',
      payload: record,
      onComplete: (ret) => {
        if (ret) {
          message.success('通知成功');
          if (data.onCancel) {
            data.onCancel()
          }
          if (data.closeTab) {
            data.closeTab(data.id)
          }
        }
      }
    })
  })
  },
  onBeforeEdit: ({ isNew, stateData, setFieldEditable }) => {
    if (stateData.SHIFT_STATUS >= 1) {
      setFieldEditable('CHANGE_SHIFT_TIME', false);
      setFieldEditable('ADDRESS', false);
      setFieldEditable('LAST_CLASS_RECORD_STATUS', false);
      setFieldEditable('LAST_CLASS_RECORD_QUESTION', false);
      setFieldEditable('LAST_CLASS_FINISH_STATUS', false);
      setFieldEditable('LAST_CLASS_FINISH_QUESTION', false);
    }
  },
  onChange: ({ value, colInfo, getFieldValue, setFieldVisible, setFieldValue, setFieldEditable, setFieldRequired }) => {
    if (colInfo.FIELD_NAME == 'LAST_CLASS_RECORD_STATUS') {
      if (getFieldValue('LAST_CLASS_RECORD_STATUS') == 1) {
        setFieldRequired('LAST_CLASS_RECORD_QUESTION', true);
        setFieldRequired('LAST_CLASS_FINISH_QUESTION', true);
      } else {
        setFieldRequired('LAST_CLASS_RECORD_QUESTION', false);
        setFieldRequired('LAST_CLASS_FINISH_QUESTION', false);
      }
    }
  }
};
