import { message } from 'antd';
import { getPropertyData, extendInclude, extendRule, getDataFieldValue, setDataFieldValue, initFilter } from "../../utils/common";
import { Button, Icon } from 'antd';
/**
 * @return {string}
 */
// 编辑
export default {
  btnSaveData: ({ record, data, getLoadParam, login,loadData, dispatch, props, saveData }) => {
    let isReturn = true;
    if (record && record.STATUS == 1) {
      if (record.Nav_AnalyzeUsers) {
        record.Nav_AnalyzeUsers.map(d => {
          if (d.USER_ID == login.userId) {
            isReturn = false;
          }
        })
      }
    }
    const confirmRevert = () => {
      dispatch({
        type: 'app/getDataByPost',
        url: 'HM/OperationTaskDistinguishAnalyze/FullUpdate',
        payload: saveData(),
        onComplete: (ret) => {
          if (ret) {
            message.success('提交成功');
            if (data.onCancel) {
              data.onCancel()
            }
            if (data.closeTab) {
              data.closeTab(data.id)
            }
          }
        }
      })
    };

    return {
      content: <Button disabled={isReturn} type="primary" onClick={confirmRevert}><Icon type="save" />保存</Button>
    }
  },
  btnSaveSubmit: ({ record, data, getLoadParam, login, dispatch, props, saveData }) => {
    let isReturn = true;
    if (record && record.STATUS == 1) {
      if (record.Nav_AnalyzeUsers) {
        record.Nav_AnalyzeUsers.map(d => {
          if (d.USER_ID == login.userId && d.DEAL_STATUS == 0 && d.IS_NOTE_TAKER == true) {
            isReturn = false;
          }
        })
      }
    }
    const confirmRevert = () => {
      dispatch({
        type: 'app/getDataByPost',
        url: 'HM/OperationTaskDistinguishAnalyze/SaveAndSubmit',
        payload: saveData(),
        onComplete: (ret) => {
          if (ret) {
            message.success('提交成功');
            if (data.onCancel) {
              data.onCancel()
            }
            if (data.closeTab) {
              data.closeTab(data.id)
            }
          }
        }
      })
    };

    return {
      content: <Button disabled={isReturn} type="primary" onClick={confirmRevert}><Icon type="check" />提交</Button>
    }
  },
  btnAgreed: ({ record, data, getLoadParam, login, dispatch, props, saveData,stateData }) => {
    let isReturn = true;
    if (record && record.STATUS == 2) {
      if (record.Nav_AnalyzeUsers) {
        record.Nav_AnalyzeUsers.map(d => {
          if (d.USER_ID == login.userId && d.DEAL_STATUS == 0 && d.IS_NOTE_TAKER == false) {
            isReturn = false;
          }
        })
      }
    }
    const confirmRevert = () => {
      dispatch({
        type: 'app/getDataByPost',
        url: 'HM/OperationTaskDistinguishAnalyze/Agreed',
        payload: saveData(),
        onComplete: (ret) => {
          if (ret) {
            message.success('已同意');
            if (data.onCancel) {
              data.onCancel()
            }
            if (data.closeTab) {
              data.closeTab(data.id)
            }
          }
        }
      })
    };

    return {
      content: <Button disabled={isReturn} type="primary" onClick={confirmRevert}><Icon type="check" />同意</Button>
    }
  },
  onChange: ({ value, colInfo, getFieldValue, setFieldValue, setFieldEditable }) => {
    if (colInfo.NAME == 'Nav_DistinguishAnalyzeH.NAME' || colInfo.NAME == 'Nav_DistinguishAnalyzeL.NAME' || colInfo.NAME == 'Nav_DistinguishAnalyzeE.NAME' || colInfo.NAME == 'Nav_DistinguishAnalyzeP.NAME' || colInfo.NAME == 'Nav_DistinguishAnalyzeR.NAME') {

    }

  },
  onSubChange: ({ row, pageCode, record, colInfo, dispatch, stateData, setFieldEditable, props }) => {
    if (colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeH.NAME' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeL.NAME' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeE.NAME' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeP.NAME' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeR.NAME') {
      let scoreH = getDataFieldValue(record, 'Nav_DistinguishAnalyzeH.SCORE');
      let scoreL = getDataFieldValue(record, 'Nav_DistinguishAnalyzeL.SCORE');
      let scoreE = getDataFieldValue(record, 'Nav_DistinguishAnalyzeE.SCORE');
      let scoreP = getDataFieldValue(record, 'Nav_DistinguishAnalyzeP.SCORE');
      let scoreR = getDataFieldValue(record, 'Nav_DistinguishAnalyzeR.SCORE');
      let score = scoreH * scoreL * scoreE * scoreP * scoreR;
      setDataFieldValue(record, 'SCORE', score);

      let isMainTask = score >= 15 ? 1 : 0;
      setDataFieldValue(record, 'IS_MAINTASK', isMainTask);
      
      // if (isMainTask == 0)
      //   setFieldEditable("OPERATION_LICENSE", false)
      stateData.Nav_AnalyzeDetails.map((v, i) => {
        if (v.ID == record.ID) {
          v.SCORE = record.SCORE;
          v.IS_MAINTASK = record.IS_MAINTASK;
        }
      });
    }
    if(colInfo.FIELD_NAME == 'OPERATION_LICENSE'){
      let IS_MAINTASK = getDataFieldValue(record, 'IS_MAINTASK');
      if(IS_MAINTASK==0){
        setDataFieldValue(record, 'OPERATION_LICENSE', 0);
      }
    }
  },
  onFetchAutoFilter: ({ colInfo, params, getFieldValue, pageCode }) => {

  },
  onFetchAutoFilterDetail: ({ colInfo, params, getFieldValue, pageCode }) => {

  },
  onBeforeEdit: ({ isNew, getFieldValue, setFieldValueByBatch, setFieldEditable }) => {
  },
  onBeforeSave: ({ data, getFieldValue, setFieldValue }) => {
  },
}
