//import { message, notification } from 'antd';
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
    params.record.STATUS = params.customParams;
    onBeforeSaveHandleRecordLog(params, 'OH005', '部门级体检计划前端日志')
  },


  onSubChange: ({ row, pageCode, record, colInfo, dispatch, stateData, saveRowRecord, setDataState, setFieldValueByBatch }) => {
    // if (colInfo != null && colInfo.FIELD_NAME == "Nav_ExamCycle.Nav_ListOccHazard") {
    //   //选择了职业危害类型 匹配体检项目 
    //   var Nav_ListOccHazard = record.Nav_ExamCycle?.Nav_ListOccHazard
    //   if (Nav_ListOccHazard != null && Nav_ListOccHazard.length > 0) {
    //     //有数据 数据库 查找
    //     var Keyword = Nav_ListOccHazard[0].HAZARD_ID
    //     if (Nav_ListOccHazard.length > 1) {
    //       for (let i = 1; i < Nav_ListOccHazard.length; i++) {
    //         Keyword += ',' + Nav_ListOccHazard[i].HAZARD_ID
    //       }
    //     }

    //     var orgId = colInfo.ORG_ID;   //登录后有存储登录信息
    //     let json = initFilter(orgId, Keyword, null, null, 1, record.USER_ID, record.DEPARTMENT_ID, record.DEPARTMENT_ID_WORKSHOP);
    //     dispatch({
    //       type: 'app/getDataByPost',
    //       url: 'OH/OHHealthExamPlan/GetExamCycleByIdentifying',
    //       payload: json,
    //       onlyData: false,
    //       onComplete: (ret) => {

    //         // let temps = [];
    //         // if (ret && ret.IsSuccessful && ret.Data) {
    //         //   let detail = ret.Data.map((item, i) => {
    //         //     item['ROW_NO'] = i + 1;
    //         //     return item;
    //         //   });
    //         //   temps.push({ field: "Nav_ListSafeCheckDetail", value: detail });

    //         //   if (detail.length > 50) {
    //         //     notification.info({
    //         //       message: <a style={{ color: 'red' }}>温馨提示</a>,
    //         //       description: '检查任务超过50条后会影响执行效率，请谨慎操作！',
    //         //       placement: 'bottomLeft',
    //         //     });
    //         //   }

    //         // } else {
    //         //   temps.push({ field: "Nav_ListSafeCheckDetail", value: null });
    //         // }
    //         // setFieldValueByBatch(temps);
    //       }
    //     });
    //   } else {
    //     //清空
    //   }
    // } else 
    if (colInfo != null && colInfo.FIELD_NAME == "Nav_User.NAME") {
      if (!record.CREATER_ID) {
        if (record.USER_ID == null) {
          // for (let i = 0; i < stateData.Nav_Plan.Nav_ListPlanRegister.length; i++) {
          //   if (stateData.Nav_Plan.Nav_ListPlanRegister[i].ID == record.ID) {
          //     stateData.Nav_Plan.Nav_ListPlanRegister[i].Nav_Department = null
          //     stateData.Nav_Plan.Nav_ListPlanRegister[i].Nav_DepartmentWorkshop = null
          //     stateData.Nav_Plan.Nav_ListPlanRegister[i].Nav_SCPost = null
          //     stateData.Nav_Plan.Nav_ListPlanRegister[i].Nav_User = null
          //   }
          // }
        } else {
          var orgId = colInfo.ORG_ID;
          // 获取人员后 去后台判断 再获取数据
          let json = initFilter(orgId, record.USER_ID, null, null, 1, stateData.PLAN_ID, record.ID, stateData.DEPARTMENT_ID);
          dispatch({
            type: 'app/getDataByPost',
            url: 'OH/OHHealthExamPlan/GetCombinPlanRegister',
            payload: json,
            onlyData: false,
            onComplete: (ret) => {
              if (ret && ret.IsSuccessful) {
                record = ret.Data

                // record.Nav_Department.NAME = ret.Data.Nav_Department?.NAME
                // record.Nav_DepartmentWorkshop.NAME = ret.Data.Nav_DepartmentWorkshop?.NAME
                // record.Nav_User.NAME = ret.Data.Nav_User.NAME
                // record.Nav_User.ID_CARD = ret.Data.Nav_User.ID_CARD
                // record.Nav_User.SEX = ret.Data.Nav_User.SEX
                // record.Nav_SCPost.NAME = ret.Data.Nav_SCPost?.NAME
                // record.WORKYEAR = ret.Data.WORKYEAR
                // // record.Nav_ListHazard.Nav_Hazard.NAME = ret.Data.Nav_ListHazard.Nav_Hazard.NAME
                // // record.Nav_ListHazard = ret.Data.Nav_ListHazard
                // record.HEALTH_EXAM_CONTENT = ret.Data.HEALTH_EXAM_CONTENT
                // record.TYPE = ret.Data.TYPE

                // setDataFieldValue(record, 'Nav_Department.NAME', record.Nav_Department?.NAME);
                // setDataFieldValue(record, 'Nav_User.NAME', record.Nav_User.NAME);
                // setDataFieldValue(record, 'Nav_User.ID_CARD', record.Nav_User.ID_CARD);
                // setDataFieldValue(record, 'Nav_SCPost.NAME', record.Nav_SCPost?.NAME);
                // setDataFieldValue(record, 'HEALTH_EXAM_CONTENT', record.HEALTH_EXAM_CONTENT);
                // setDataFieldValue(record, 'Nav_User.SEX', record.Nav_User.SEX);
                // // setDataFieldValue(record, 'Nav_ListHazard', record.Nav_ListHazard);
                // // setDataFieldValue(record, 'Nav_ListHazard.Nav_Hazard.NAME', record.Nav_ListHazard.Nav_Hazard.NAME);
                // setDataFieldValue(record, 'TYPE', record.TYPE);
                // setDataFieldValue(record, 'Nav_DepartmentWorkshop.NAME', record.Nav_DepartmentWorkshop?.NAME);
                // setDataFieldValue(record, 'WORKYEAR', record.WORKYEAR);

                // const temps = [];
                // temps.push({ field: 'USER_ID', value: login.user.ID })
                // setFieldValueByBatch(temps)

                for (let i = 0; i < stateData.Nav_Plan.Nav_ListPlanRegister.length; i++) {
                  if (stateData.Nav_Plan.Nav_ListPlanRegister[i].ID == record.ID) {
                    stateData.Nav_Plan.Nav_ListPlanRegister[i] = record
                  }
                }

                // stateData.Nav_Plan.Nav_ListPlanRegister.map((v, i) => {
                //   if (v.ID == record.ID) {
                //     debugger
                //     v = record
                //     v.DEPARTMENT_ID = record.DEPARTMENT_ID
                //     v.DEPARTMENT_ID_WORKSHOP = record.DEPARTMENT_ID_WORKSHOP
                //     v.SC_POST_ID = record.SC_POST_ID
                //     v.WORKYEAR = record.WORKYEAR
                //     v.Nav_Department.NAME = record.Nav_Department?.NAME
                //     // v.Nav_User.NAME = record.Nav_User.NAME
                //     // v.Nav_User.ID_CARD = record.Nav_User.ID_CARD

                //     // v.Nav_SCPost.NAME = record.Nav_SCPost?.NAME
                //     // v.HEALTH_EXAM_CONTENT = record.HEALTH_EXAM_CONTENT
                //     // v.Nav_User.SEX = record.Nav_User.SEX
                //     // // v.Nav_ListHazard = record.Nav_ListHazard
                //     // // v.Nav_ListHazard.Nav_Hazard.NAME = record.Nav_ListHazard.Nav_Hazard.NAME
                //     v.TYPE = record.TYPE
                //     // v.Nav_DepartmentWorkshop.NAME = record.Nav_DepartmentWorkshop?.NAME
                //     v.WORKYEAR = record.WORKYEAR
                //   }
                // });
              }

              // setDataFieldValue(record, 'OVER_LIMIT', record.OVER_LIMIT);
              // stateData.Nav_Detail.map((v, i) => {
              //   if (v.ID == record.ID) {
              //     v.OVER_LIMIT = record.OVER_LIMIT;
              //   }
              // });


            }
          });
        }
      }
    }
  },

  // handleRenderRowControl(params) {
  //   if (params.record.CREATE_TIME) {
  //     if (params.colConfig.field == 'Nav_User.NAME') {
  //       debugger
  //       return <>
  //         {params.record.Nav_User.NAME}
  //       </>
  //     }
  //     // else if (params.colConfig.field == 'Nav_ListHazard') {
  //     //   return <>
  //     //     {params.record.Nav_CheckProject?.NAME}
  //     //   </>
  //     // }
  //     // else if (params.colConfig.field == 'HEALTH_EXAM_CONTENT') {
  //     //   return <>
  //     //     {params.record.HEALTH_EXAM_CONTENT}
  //     //   </>
  //     // }
  //   } else {
  //     return '';
  //   }
  // }


}
