import ConfirmButton from '../../components/common/ConfirmButton';
import { Button, message } from 'antd'
import FormPage from '../../components/FormPage'
import storage from '../../utils/storage'
import config from "../../config.js"
import { extendInclude, extendRule, getDataFieldValue, initFilter, empty, extendOrder, guid, getSubTableData, onBeforeSaveHandleRecordLog } from "../../utils/common";
import Item from 'antd/lib/list/Item';
import styles from '../../components/CustomPages/HI/StepForm.css';
export default {
  onBeforeSaveHandleRecord(params) {
    params.record.TaskID = params.data.TaskID
    // onBeforeSaveHandleRecordLog(params, 'BS069', '安全检查退回')
  },
  onBeforeEdit: ({ isNew, stateData, setFieldEditable, setFieldValue, dispatch, ListCheckRiskArea, setFieldValueByBatch, updateSubTableData, setFieldVisible }) => {
    if (stateData.Nav_ListCheckDetailQuestion[0].Nav_Question != null && stateData.Nav_ListCheckDetailQuestion[0].Nav_Question?.DEMAND == undefined) {
      stateData.Nav_ListCheckDetailQuestion[0].Nav_Question.DEMAND = ''
    }
    if (stateData.QUESTION_LEVEL == 0) {
      stateData.QUESTION_LEVEL = ''
    }

    // const temps = [];
    // var DEMAND = stateData.Nav_ListCheckDetailQuestion[0].Nav_Question?.DEMAND
    // var Level = stateData.QUESTION_LEVEL
    // var Nav_ListCheckDetailQuestion = stateData.Nav_ListCheckDetailQuestion
    // if (DEMAND == undefined) {
    //   DEMAND = ""
    // }
    // if (Level == 0) {
    //   Level = ""
    // }
    // temps.push({ field: 'Nav_ListCheckDetailQuestion.Nav_Question.DEMAND', value: DEMAND })
    // temps.push({ field: 'QUESTION_LEVEL', value: Level })
    // temps.push({ field: 'Nav_ListCheckDetailQuestion', value: Nav_ListCheckDetailQuestion })
    // setFieldValueByBatch(temps);

    // var DEMAND = stateData.Nav_ListCheckDetailQuestion[0].Nav_Question?.DEMAND
    // if (DEMAND == undefined) {
    //   DEMAND = ""
    // }
    // setFieldValue('Nav_ListCheckDetailQuestion.Nav_Question.DEMAND', DEMAND)

  },

  onChange: ({ row, setDataState, pageCode, record, colInfo, dispatch, stateData, setFieldValueByBatch }) => {
    if (colInfo.FIELD_NAME == "Nav_ListCheckDetailQuestion") {
      var listQ = stateData.Nav_ListCheckDetailQuestion
      var DEMAND = ''
      var Level = ''
      // var CHECK_MAIN_ID = ''
      var chooseCount = 0
      var CHECKRESULT = 0 // 无 10 检查问题一致 20 其他 30
      for (let i = 0; i < listQ.length; i++) {
        if (!listQ[i].IS_DELETED) {
          DEMAND = listQ[i].Nav_Question.DEMAND
          Level = listQ[i].Nav_Question.QUESTION_LEVEL
          // CHECK_MAIN_ID = listQ[i].Nav_Question
          chooseCount++

          if (listQ[i].SAFE_CHECK_QUESTION_ID == '55555555-5555-5555-5555-555555555555') {
            CHECKRESULT = 10
          } else {
            CHECKRESULT = 20
          }
        }
      }
      const temps = [];
      if (chooseCount > 1) {
        DEMAND = ''
        Level = ''
        message.error("只能选择一个问题描述!")
        temps.push({ field: 'Nav_ListCheckDetailQuestion.Nav_Question.DEMAND', value: DEMAND })
        temps.push({ field: 'QUESTION_LEVEL', value: Level })
        setFieldValueByBatch(temps);
      } else {
        // temps.push({ field: 'Nav_ListCheckDetailQuestion.Nav_Question.DEMAND', value: DEMAND })
        temps.push({ field: 'QUESTION_LEVEL', value: Level })
        setFieldValueByBatch(temps);
      }

      if (CHECKRESULT == 10) {
        stateData.QUESTION_LEVEL = null
        stateData.DEMANDS = null
      } else if (CHECKRESULT == 20) {
        // 对应行 取第一个 未删除的 检查问题  显示 问题等级
        stateData.DEMANDS = DEMAND

        if (Level != '' && Level > 0) {
          stateData.QUESTION_LEVEL = Level// stateData.Nav_ListSafeCheckDetail[i].QUESTION_LEVEL_SAME
          // stateData.Nav_CheckDetail.CHECK_MAIN_ID = CHECK_MAIN_ID
        }

      } else if (CHECKRESULT == 30) {
        stateData.QUESTION_LEVEL = null
        stateData.DEMANDS = null
      } else if (CHECKRESULT == 0) {
        stateData.QUESTION_LEVEL = null
        stateData.DEMANDS = null
      }
      //保存信息
      stateData.CHECKRESULT = CHECKRESULT

    }
  },
}
