import { message } from "antd/lib/index";
import { getPropertyData, extendInclude, extendRule, getDataFieldValue, setDataFieldValue, initFilter, empty, onBeforeSaveHandleRecordLog } from "../../utils/common";
import { connect } from 'dva';
/**
 * @return {string}
 */
// 编辑  制定任务
export default {

  onBeforeSaveHandleRecord(params) {
    params.record.TaskID = params.data.TaskID    //TaskID传递消息表ID
    params.record.STATUS = params.customParams;
    if (!params.record.CONTENT && params.record.Nav_ListMeetingContent != null && params.record.Nav_ListMeetingContent.length > 0) {
      params.record.CONTENT32 = "," + params.record.Nav_ListMeetingContent.map(item => { if (item.IS_DELETED) { return '' } else { return item.Nav_ContentName.NAME } }).join(',') + ","
    } else {
      params.record.CONTENT32 = params.record.CONTENT
    }
    onBeforeSaveHandleRecordLog(params, 'SC032', '前端日志')
  },
  onBeforeEdit: ({ isNew, dispatch, stateData, setFieldVisible, setFieldValue, setFieldValueByBatch, setFieldEditable, login }) => {
    setFieldVisible("Nav_ListPReView", false);

    if (stateData != null && stateData.IS_SEND) {
      //数据记录要发送短信
    } else {
      let jsonSend = initFilter(stateData.ORG_ID);
      extendRule(jsonSend, 'IS_SENDMSG', 1, 1);
      dispatch({
        type: 'app/getDataByPost',
        url: 'SC/MtConfig/Entities',
        payload: jsonSend,
        onlyData: false,
        onComplete: (ret) => {
          if (!ret.IsSuccessful || ret.Data.length < 1) {
            //直接判断 省得 跳着显示判断
            setFieldVisible("IS_SEND", false);
          }
        }
      });
    }

    // 如果是跑批需要召开的会议 会议类型不能修改
    if (stateData.CREACTTYPE == 10) {
      setFieldEditable('MEETINGTYPE', false)
      if (stateData.STATUS == 0 && (stateData.Nav_ListPAll == undefined || stateData.Nav_ListPAll == null || stateData.Nav_ListPAll.length == 0)) {
        //加载参会人员信息
        // this.getPAll(stateData.MEETINGTYPE, stateData.ORG_ID, stateData.ID, setFieldVisible, setFieldValue, dispatch, setFieldValueByBatch)
        // export function getPAll(meetingType, orgId, meetingId, setFieldVisible, setFieldValue, dispatch, setFieldValueByBatch) {
        // if (stateData.MEETINGTYPE == 40 || stateData.MEETINGTYPE == 50) {
        if (stateData.MEETINGTYPE != null && stateData.MEETINGTYPE > 0) {
          setFieldVisible("Nav_ListPReView", false);
          setFieldValue("Nav_ListPReView", null); //评审人员不可见
          let json = initFilter(stateData.ORG_ID, stateData.ID, null, null, null, stateData.MEETINGTYPE);
          dispatch({
            type: 'app/getDataByPost',
            url: 'SC/SCMTMeeting/GetPAll',
            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_ListPAll", value: detail });
              } else {
                temps.push({ field: "Nav_ListPAll", value: null });
              }
              setFieldValueByBatch(temps);
            }
          });
        }
      }
    }
    if (isNew) {
      // setFieldValue("DEPARTMENT_ID", login.user.DEPARTMENT_ID)
      // setFieldValue("Nav_Department.NAME", login.user.Nav_Department.NAME)
      // setFieldValue("USER_ID_ORIGINATOR", login.user.ID)
      // setFieldValue("Nav_User_Originator.NAME", login.user.NAME)

      const temps = [];
      temps.push({ field: 'DEPARTMENT_ID', value: login.user.DEPARTMENT_ID });
      temps.push({ field: 'Nav_Department.NAME', value: login.user.Nav_Department?.NAME });
      temps.push({ field: 'USER_ID_ORIGINATOR', value: login.user.ID })
      temps.push({ field: 'Nav_User_Originator.NAME', value: login.user.NAME })
      setFieldValueByBatch(temps);
    }
    //控制 可见性
    if (stateData.MEETINGTYPE == 30) {
      setFieldVisible("Nav_ListPReView", true);
    }

    //判断是否 配置 可以发送短信
  },

  // STATUS
  onChange: ({ value, colInfo, dispatch, setFieldValueByBatch, record, stateData, data, getFieldValue, setFieldVisible, setFieldValue }) => {
    if (colInfo != null && colInfo.FIELD_NAME == "MEETINGTYPE") {
      //会议类型 修改 人员自动 判断加载
      // 安委会时，安委会成员默认全选，可删除，可添加其他人员
      // 基层安全会按部门/车间/班组点选或模糊查询，默认部门所有人员向下包含
      /// 普通会议 10  文件审核会议 20     文件评审会 30
      /// 安委会 40     基层安全会 50

      setFieldValue("Nav_ListMeetingContent", null);
      if (value == 40 || value == 50) {
        setFieldVisible("Nav_ListPReView", false);
        setFieldValue("Nav_ListPReView", null); //评审人员不可见
        //加载人员信息
        // this.getPAll(value, colInfo.ORG_ID, getFieldValue("ID"), setFieldVisible, setFieldValue, dispatch, setFieldValueByBatch)

        //  export function getPAll(meetingType, orgId, meetingId, setFieldVisible, setFieldValue, dispatch, setFieldValueByBatch) {
        if (value == 40 || value == 50) {
          setFieldVisible("Nav_ListPReView", false);
          setFieldValue("Nav_ListPReView", null); //评审人员不可见
          let json = initFilter(colInfo.ORG_ID, getFieldValue("ID"), null, null, null, value);
          dispatch({
            type: 'app/getDataByPost',
            url: 'SC/SCMTMeeting/GetPAll',
            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_ListPAll", value: detail });
              } else {
                temps.push({ field: "Nav_ListPAll", value: null });
              }
              setFieldValueByBatch(temps);
            }
          });
        }




      } else {
        //参会人员 处理
        let temps = [];
        temps.push({ field: "Nav_ListPAll", value: null });
        setFieldValueByBatch(temps);

        if (value == 30) {
          // 文件评审会 
          setFieldVisible("Nav_ListPReView", true);
        } else {
          setFieldVisible("Nav_ListPReView", false);
          setFieldValue("Nav_ListPReView", null); //评审人员不可见
        }
      }
    } else if (colInfo != null && colInfo.FIELD_NAME == "Nav_ListMeetingContent") {
      // //会议内容修改
      // //加载 会议意见
      // let listContent = getFieldValue("Nav_ListMeetingContent")
      // let contentNameIDs = ""
      // if (listContent != undefined && listContent.length > 0) {
      //   for (let i = 0; i < listContent.length; i++) {
      //     if (listContent[i].IS_DELETED == undefined || listContent[i].IS_DELETED == null || listContent[i].IS_DELETED == false)
      //       contentNameIDs += (contentNameIDs.length > 0 ? "," : "") + listContent[i].CONTENTNAME_ID
      //   }
      // }

      // var orgId = colInfo.ORG_ID;
      // let json = initFilter(orgId, contentNameIDs, null, null, null, getFieldValue("ID"));

      // dispatch({
      //   type: 'app/getDataByPost',
      //   url: 'SC/SCMTMeeting/GetListContent',
      //   payload: json,
      //   onlyData: false,
      //   onComplete: (ret) => {
      //     debugger
      //     // 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_ListPAll", value: detail });
      //     // } else {
      //     //   temps.push({ field: "Nav_ListPAll", value: null });
      //     // }
      //     // setFieldValueByBatch(temps);
      //     // Nav_ListMeetingContent
      //   }
      // });

    }
  },
}

// // 公共方法
// export function getPAll(meetingType, orgId, meetingId, setFieldVisible, setFieldValue, dispatch, setFieldValueByBatch) {
//   if (meetingType == 40 || meetingType == 50) {
//     setFieldVisible("Nav_ListPReView", false);
//     setFieldValue("Nav_ListPReView", null); //评审人员不可见
//     let json = initFilter(orgId, meetingId, null, null, null, meetingType);
//     dispatch({
//       type: 'app/getDataByPost',
//       url: 'SC/SCMTMeeting/GetPAll',
//       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_ListPAll", value: detail });
//         } else {
//           temps.push({ field: "Nav_ListPAll", value: null });
//         }
//         setFieldValueByBatch(temps);
//       }
//     });
//   }
// }
