import { message } from "antd/lib/index";
import { getPropertyData, extendInclude, extendRule, getDataFieldValue, setDataFieldValue, initFilter, guid } from "../../utils/common";
import moment from 'moment';
/**
 * @return {string}
 */
// 编辑
export default {
  onBeforeSaveHandleRecord(params) {
    params.record.TaskID = params.data.TaskID    //TaskID传递消息表ID
    params.record.PUBLISH = params.customParams;
  },
  onBeforeEdit(params) {
    const { isNew, setFieldVisible,stateData } = params ? params : {};
    if (isNew) {
      setFieldVisible("CONTEXT", false);
    }
    else
    {
      if(stateData.IS_PUBLISH === 9)
      {
        setFieldVisible("CONTEXT", true);
      }
      else
      {setFieldVisible("CONTEXT", false);}
    }
  },
  onChange: ({ colInfo, getFieldValue, setFieldValueByBatch, dispatch,updateSubTableData }) => {
    if (!(colInfo.FIELD_NAME == 'Nav_JobtaskIdentify.CODE'))
    return;

    let code = getFieldValue('Nav_JobtaskIdentify.CODE')  
    let json = initFilter(null,code);
    dispatch({
      type: 'app/getDataByPost',
      url: 'HM/HMOperationTaskDistinguishAnalyze/GetAnalyzeDetail',
      payload: json,
      onlyData: false,
      onComplete: (re) => {
        if (re && re.IsSuccessful && re.Data) {
            let temps = [];
            let detail=re.Data.Nav_AnalyzeDetails.map((item,i)=>{
                item['ROW_NO'] = i+1;
                return item;
             });
            temps.push({ field: 'Nav_AnalyzeDetails', value: detail })
            setFieldValueByBatch(temps);
            //updateSubTableData(params.pageCode,detail,true)
        }
      }
    })
  },

  onSubChange: ({ row, pageCode, record, colInfo, dispatch, stateData, setFieldEditable,setFieldValueByBatch, props }) => {
    if (colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeH.SCORE' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeL.SCORE' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeE.SCORE' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeP.SCORE' || colInfo.FIELD_NAME == 'Nav_DistinguishAnalyzeR.SCORE') {
      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');
      scoreH===null?0:scoreH;
      scoreL===null?0:scoreL;
      scoreE===null?0:scoreE;
      scoreP===null?0:scoreP;
      scoreR===null?0:scoreR;
      let score = scoreH * scoreL * scoreE * scoreP * scoreR;
      setDataFieldValue(record, 'SCORE', score);

      let isMainTask = score >= 15 ? 1 : 0;
      setDataFieldValue(record, 'IS_MAINTASK', isMainTask);
      stateData.Nav_AnalyzeDetails.map((v, i) => {
        if (v.ID == record.ID) {
          v.SCORE = record.SCORE;
          v.IS_MAINTASK = record.IS_MAINTASK;
        }
      });
      setFieldValueByBatch(stateData.Nav_AnalyzeDetails);
    }
    if(colInfo.FIELD_NAME == 'OPERATION_LICENSE'){
      let IS_MAINTASK = getDataFieldValue(record, 'IS_MAINTASK');
      if(IS_MAINTASK==0){
        setDataFieldValue(record, 'OPERATION_LICENSE', 0);
      }
    }
  },
  handleRenderRowControl(params) {
    if (params.colConfig.field === 'Nav_ApproveUser.NAME' && !params.record.IS_ALLOW_UPDATE) {
      return <>
        <a>{params.record.Nav_ApproveUser?.NAME}</a>
      </>

    } else {
      return ""
    }
  }
}
