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

  handleRenderRowControl(params) {
    if (params?.stateData.Nav_ListMaintenance != undefined && params.stateData.Nav_ListMaintenance.length > 0) {
      if (params.colConfig.field === 'Nav_Files') {
        if (params.record.Nav_Files.length > 0) {
          return showFiles(params.record.Nav_Files, config.serviceHost)
        } else {
          return <><a></a></>
        }
      } else if (params.colConfig.field === 'Nav_ListUser' && params.colConfig.label == "维保人员") {
        if (params.record.Nav_ListUser.length > 0) {
          var names = ''
          params.record.Nav_ListUser?.map((item, i) => {
            names += ((i > 0 ? "，" : "") + item.Nav_User.NAME)
          })
          return <><a style={{ color: "#000000A6" }}>{names}</a></>

        } else {
          return <><a></a></>
        }
      }
    }
  },

  initInfoCircle: ({ row, pageCode, record, colInfo, resetFields, stateData, saveHeadRecord, saveRowRecord, getSelectedRecords, setState }) => {
    let DetailCheck = getSelectedRecords();
    if (DetailCheck && DetailCheck.length > 1) {
      let ListUserFirst = DetailCheck[0].Nav_ListUser;
      //更新行数据
      for (let i = 1; i < DetailCheck.length; i++) {
        //组装数据
        let updateList = [];
        if (ListUserFirst != undefined && ListUserFirst.length > 0) {
          for (let j = 0; j < ListUserFirst.length; j++) {
            if (!ListUserFirst[j].IS_DELETED) {
              let updateObj = { ...ListUserFirst[j] };
              updateObj["ID"] = guid()
              updateList.push(updateObj);
            }
          }
          let iRow = { ...DetailCheck[i] };
          iRow.Nav_ListUser = updateList;
          saveRowRecord({ record: iRow, editCode: "T_DM_DEVICE_BASE_CHECK2" })

          for (var x = 0; x < stateData.Nav_ListCheckCircle.length; x++) {
            if (iRow.ID == stateData.Nav_ListCheckCircle[x].ID) {
              stateData.Nav_ListCheckCircle[x].Nav_ListUser = updateList;

              stateData.Nav_ListCheckCircle[x].CHECKTIME = DetailCheck[0].CHECKTIME;
              stateData.Nav_ListCheckCircle[x].PLANCHECKFREQUENCY = DetailCheck[0].PLANCHECKFREQUENCY;
              stateData.Nav_ListCheckCircle[x].WEEKDATA = DetailCheck[0].WEEKDATA;
              stateData.Nav_ListCheckCircle[x].DATA = DetailCheck[0].DATA;
            }
          }
        }
        //更新选中人员
        let tmp = "";
        for (var x = 0; x < stateData.Nav_ListCheckCircle.length; x++) {
          let users = stateData.Nav_ListCheckCircle[x].Nav_ListUser
          if (users) {
            for (let i = 0; i < users.length; i++) {
              if (!users[i].IS_DELETED) {
                if (tmp.indexOf(users[i].Nav_User.NAME) == -1) {
                  tmp += (tmp.length > 0 ? "," : "") + users[i].Nav_User.NAME
                }
              }
            }
          }
        }
        stateData.CheckUsers = tmp
        setState({ data: stateData });
      }
    }
  },

  initInfo: ({ row, pageCode, record, colInfo, resetFields, stateData, saveHeadRecord, saveRowRecord, getSelectedRecords, setState }) => {
    let DetailCheck = getSelectedRecords();
    if (DetailCheck && DetailCheck.length > 1) {
      let ListUserFirst = DetailCheck[0].Nav_ListUser;
      //更新行数据
      for (let i = 1; i < DetailCheck.length; i++) {
        //组装数据
        let updateList = [];
        if (ListUserFirst != undefined && ListUserFirst.length > 0) {
          for (let j = 0; j < ListUserFirst.length; j++) {
            if (!ListUserFirst[j].IS_DELETED) {
              let updateObj = { ...ListUserFirst[j] };
              updateObj["ID"] = guid()
              updateList.push(updateObj);
            }
          }
          let iRow = { ...DetailCheck[i] };
          iRow.Nav_ListUser = updateList;
          saveRowRecord({ record: iRow, editCode: "T_DM_DEVICE_BASE_CHECK" })

          for (var x = 0; x < stateData.Nav_ListCheck.length; x++) {
            if (iRow.ID == stateData.Nav_ListCheck[x].ID) {
              stateData.Nav_ListCheck[x].Nav_ListUser = updateList;

              stateData.Nav_ListCheck[x].CHECKTIME = DetailCheck[0].CHECKTIME;
              stateData.Nav_ListCheck[x].PLANCHECKFREQUENCY = DetailCheck[0].PLANCHECKFREQUENCY;
              stateData.Nav_ListCheck[x].WEEKDATA = DetailCheck[0].WEEKDATA;
              stateData.Nav_ListCheck[x].DATA = DetailCheck[0].DATA;
            }
          }
        }
        //更新选中人员
        let tmp = "";
        for (var x = 0; x < stateData.Nav_ListCheck.length; x++) {
          let users = stateData.Nav_ListCheck[x].Nav_ListUser
          if (users) {
            for (let i = 0; i < users.length; i++) {
              if (!users[i].IS_DELETED) {
                if (tmp.indexOf(users[i].Nav_User.NAME) == -1) {
                  tmp += (tmp.length > 0 ? "," : "") + users[i].Nav_User.NAME
                }
              }
            }
          }
        }
        stateData.CheckUsers = tmp
        setState({ data: stateData });
      }
    }
  },

}
