/* eslint-disable no-undef */
import { extendInclude, extendRule } from "../../utils/common"
import { Select } from 'antd'
const { Option } = Select

/**
 * @return {string}
 */


export default {
    onBeforeEdit: ({ isNew, getFieldValue, setFieldValueByBatch, setFieldEditable, editConfig, setEditConfig, setMenuName, dispatch }) => {
        let pid = getFieldValue("PARENT_ID")
        if (!pid)
            pid = ""
        const json = {
            Parameter1: pid
        }
        dispatch({
            type: 'app/getDataByPost',
            url: 'BD/BDMeterNode/GetBDProcessPropEnum',
            payload: json,
            onlyData: false,
            onComplete: (re) => {
                if (re && re.IsSuccessful && re.Data) {
                    setMenuName(editConfig, "NODE_PROP", re.Data)
                }
            }
        })
    },
    onChange: ({ colInfo, getFieldValue, setFieldValueByBatch, dispatch }) => {
        if (!(colInfo.FIELD_NAME == 'NODE_PROP'))
          return;
 
        let nodeProp = getFieldValue('NODE_PROP')     
        if (nodeProp == null) {      
          return;
        }
        let id = getFieldValue("ID")
        let pid = getFieldValue("PARENT_ID")
        if (!pid)
           pid = ""
        const json = {
          Parameter1: nodeProp,
          Parameter2:id,
          Parameter3:pid
        };
        dispatch({
          type: 'app/getDataByPost',
          url: 'BD/BDMeterNode/GeneratingCode',
          payload: json,
          onlyData: false,
          onComplete: (re) => {
            if (re && re.IsSuccessful && re.Data) {
                const temps = [];
                temps.push({ field: 'CODE', value: re.Data.Code })
                temps.push({ field: 'NODE_CODE', value: re.Data.NodeCode })
                setFieldValueByBatch(temps);
            }
          }
        })
      },
}