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.PUBLISH = params.customParams;
    params.record.TaskID = params.data.TaskID;    //TaskID传递消息表ID
  },
  onBeforeEdit(params) {
    const { isNew, data, stateData, setFieldValueByBatch, setFieldValue,setFieldVisible } = params ? params : {};
    if (!isNew) {
      if(stateData && stateData.Nav_CrucialLicensePerson)
      {
        let temps = [];
        let users = stateData.Nav_CrucialLicensePerson.map(t=>{
          if(t.Nav_User && t.Nav_User.Nav_Department)
          {
            t['DepartmentNAME'] = t.Nav_User.Nav_Department.NAME;
          }
          return t;
        })
        temps.push({ field: 'Nav_CrucialLicensePerson', value: users })
        setFieldValueByBatch(temps);
      }
      if(stateData.IS_PUBLISH === 9)
      {
        setFieldVisible("CONTEXT", true);
      }
      else
      {setFieldVisible("CONTEXT", false);}
    }
    else
    {
      setFieldVisible("CONTEXT", false);
    }
  },
  onChange: ({ colInfo, getFieldValue, setFieldValueByBatch, dispatch,login,updateSubTableData }) => {
    if (!(colInfo.FIELD_NAME == 'Nav_OperationStep.NAME'))
    return;

    let code = getFieldValue('OPERATION_STEP_ID')  
    let json = initFilter(login.OrgId,code);
    dispatch({
      type: 'app/getDataByPost',
      url: 'FO/FOCrucialLicenseJob/GetAnalyzeDetail',
      payload: json,
      onlyData: false,
      onComplete: (re) => {
        if (re && re.IsSuccessful && re.Data) {
            let temps = [];
            let detailConfirms=re.Data.Nav_SafeConfirms?.map((item,i)=>{
                item['NUM'] = i+1;
                item['CREATE_TIME']='';
                return item;
             });
             let detailMeasures=re.Data.Nav_SafeMeasures?.map((item,i)=>{
              item['NUM'] = i+1;
              item['CREATE_TIME']='';
              return item;
           });
           let detailDeal=re.Data.Nav_DealMeasures?.map((item,i)=>{
            item['NUM'] = i+1;
            item['CREATE_TIME']='';
            return item;
         });
            temps.push({ field: 'Nav_SafeConfirms', value: detailConfirms })
            temps.push({ field: 'Nav_SafeMeasures', value: detailMeasures })
            temps.push({ field: 'Nav_DealMeasures', value: detailDeal })
            temps.push({ field: 'AUDIT_LEVEL', value: re.Data.AUDIT_LEVEL})
            // temps.push({ field: 'SafeMeasuresStr', value: re.Data.SafeMeasuresStr})
            setFieldValueByBatch(temps);
            //updateSubTableData(params.pageCode,detail,true)
        }
      }
    })
  },
   onSubChange: ({ row, getFieldValue, setFieldValueByBatch, pageCode, record, setDataState, colInfo, dispatch, stateData, saveRowRecord }) => {

    if (colInfo.FIELD_NAME === "CERTIFICATE_TYPE" ) {
      if (record.USER_ID === null || record.USER_ID === undefined) {
        message.error("请先选择人员!")
        return;
      }
      else{
        let certificateType = getDataFieldValue(record, 'CERTIFICATE_TYPE');
        if(certificateType === 0)
        {
          let json = initFilter(stateData.ORG_ID);
        extendRule(json, 'ID', 1, record.USER_ID);
        dispatch({
          type: 'app/getDataByPost',
          url: 'FM/User/Get',
          payload: json,
          onlyData: false,
          onComplete: (ret) => {
            if (ret && ret.IsSuccessful) {
              record["JOB_DOCUMENT"] = ret.Data.ID_CARD;
              saveRowRecord(record)
            } 
          }
        });
        }
        else
        {
          record["JOB_DOCUMENT"] = "";
          saveRowRecord(record)
        }
      } 
    }
  },
  // handleRenderRowControl(params) {
  //   if (params.colConfig.field === 'Nav_ApproveUser.NAME' && !params.record.IS_ALLOW_UPDATE) {
  //     return <>
  //       <a>{params.record.Nav_ApproveUser?.NAME}</a>
  //     </>

  //   } else {
  //     return ""
  //   }
  // }
}
