import { message, Checkbox, Radio } from "antd/lib/index";
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) {
    params.record.TaskID = params.data.TaskID    //TaskID传递消息表ID
    //如果是保存 
    // 如果现在状态 是 待填写 职业病  状态不变
    if (params.customParams == 0 && params.record.STATUS == 10 && params.record.RESULT_ENUM == 15) {
      // params.record.STATUS = params.customParams;//状态不变 后台处理数据
    } else {
      params.record.STATUS = params.customParams;
    }
    onBeforeSaveHandleRecordLog(params, 'OH010', '体检通知前端日志')
  },
  onBeforeEdit: ({ isNew, stateData, setFieldVisible, setFieldEditable, login }) => {
    //如果是 待填写职业病  STATUS 10   RESULT_ENUM 15
    //那么 页面属性不可编辑
    if (!isNew&&stateData.STATUS!=0&&stateData.STATUS!=10) {
      if (stateData.Nav_NoticeRegister?.Nav_User) {
        setFieldEditable("Nav_NoticeRegister.Nav_ExamBatch.BATCH", false);
        setFieldEditable("Nav_NoticeRegister.Nav_User.NAME", false);
        setFieldEditable("RESULT_ENUM", false);
        setFieldEditable("DESCRIPTION", false);
        setFieldEditable("SUGGESTION", false);
      }
    }
  },

  onSubChange: ({ row, setDataState, pageCode, record, colInfo, dispatch, stateData, props }) => {
    //如果修改原有库 直接填写对应ID 
    // debugger
    // if (record.ISMAINCHANGE == undefined || record.ISMAINCHANGE == null || !record.ISMAINCHANGE) {
    //   var MainId = record.CHECK_MAIN_ID
    //   if (MainId != null && MainId != undefined && MainId.length > 0) {
    //     stateData.Nav_ListSafeCheckDetail[record.ROW_NO - 1].ISMAINCHANGE = true
    //   }
    // }

    if (colInfo.FIELD_NAME == "Nav_ExamBatch.BATCH") {
      //更新选中人员
      let tmp = "";
      var DEPARTMENT_ID_WORKSHOP = record.DEPARTMENT_ID_WORKSHOP
      var DEPARTMENT_ID = record.DEPARTMENT_ID
      var banchRecord = record.Nav_ExamBatch
      //有车间 车间所有的一起同步
      // DEPARTMENT_ID_WORKSHOP
      //没有车间有部门 所有的一起同步 
      // DEPARTMENT_ID
      if (DEPARTMENT_ID_WORKSHOP || DEPARTMENT_ID) {
        for (var x = 0; x < stateData.Nav_ListNoticeRegister.length; x++) {
          let regist = stateData.Nav_ListNoticeRegister[x]
          // let banch = regist.Nav_ExamBatch
          if (!regist.Nav_ExamBatch) {
            if (DEPARTMENT_ID_WORKSHOP && DEPARTMENT_ID_WORKSHOP.length > 0) {
              if (regist.DEPARTMENT_ID_WORKSHOP && regist.DEPARTMENT_ID_WORKSHOP == DEPARTMENT_ID_WORKSHOP) {
                regist.Nav_ExamBatch = banchRecord
                regist.EXAM_BATCH_ID = banchRecord.ID
              }

            } else if (DEPARTMENT_ID && DEPARTMENT_ID.length > 0) {
              if (regist.DEPARTMENT_ID && regist.DEPARTMENT_ID == DEPARTMENT_ID && regist.DEPARTMENT_ID_WORKSHOP == null) {
                regist.Nav_ExamBatch = banchRecord
                regist.EXAM_BATCH_ID = banchRecord.ID
              }
            }
          }


          // if (banch) {
          //   for (let i = 0; i < banch.length; i++) {
          //     if (!banch[i].IS_DELETED) {
          //       if (tmp.indexOf(banch[i].Nav_User.NAME) == -1) {
          //         tmp += (tmp.length > 0 ? "," : "") + banch[i].Nav_User.NAME
          //       }
          //     }
          //   }
          // }
        }
      }
      stateData.CheckUsers = tmp
      setDataState({ ...stateData });

    }
  },


  // handleRenderRowControl(params) {
  //   if (params.record.CREATE_TIME) {
  //     if (params.colConfig.field == 'Nav_Department.NAME') {
  //       return <>
  //         {params.record.Nav_Department?.NAME}
  //       </>
  //     }
  //     else if (params.colConfig.field == 'Nav_DepartmentWorkshop.NAME') {
  //       return <>
  //         {params.record.Nav_DepartmentWorkshop?.NAME}
  //       </>
  //     }
  //     else if (params.colConfig.field == 'Nav_User.NAME') {
  //       return <>
  //         {params.record.Nav_User.NAME}
  //       </>
  //     }
  //     // else if (params.colConfig.field == 'Nav_User.ID_CARD') {
  //     //   return <>
  //     //     {params.record.Nav_User.ID_CARD}
  //     //   </>
  //     // }
  //     // else if (params.colConfig.field == 'Nav_User.SEX') {
  //     //   return <>
  //     //     {params.record.Nav_User.SEX}
  //     //   </>
  //     // }
  //     // else if (params.colConfig.field == 'Nav_SCPost.NAME') {
  //     //   return <>
  //     //     {params.record.Nav_SCPost?.NAME}
  //     //   </>
  //     // }
  //     // else if (params.colConfig.field == 'WORKYEAR') {
  //     //   return <>
  //     //     {params.record.WORKYEAR}
  //     //   </>
  //     // }
  //     else if (params.colConfig.field == 'Nav_ExamCycle.HEALTH_EXAM_CONTENT') {
  //       return <>
  //         {params.record.Nav_ExamCycle.HEALTH_EXAM_CONTENT}
  //       </>
  //     }
  //     else if (params.colConfig.field == 'TYPE') {
  //       return <>
  //         {params.record.TYPE}
  //       </>
  //     }
  //     // else if (params.colConfig.field == 'CHECKCONTENT') {
  //     //   return <>
  //     //     {params.record.CHECKCONTENT}
  //     //   </>
  //     // }
  //   } else {
  //     return '';
  //   }
  // }



}
