import { observable, action, toJS } from "mobx";
import * as API from "../apis/WorkflowFlowService";

import { Modal, message } from "antd";
import { WeaTableNew, WeaForm, WeaLogView } from "comsMobx";
import cloneDeep from 'lodash/cloneDeep';
import isFunction from 'lodash/isFunction';

const { TableStore } = WeaTableNew;
const { LogStore } = WeaLogView;
import { WeaLocaleProvider, WeaTools } from "ecCom";
import {
  getSearchFormHeight,
  checkHasOrganization,
  isCallBackFunction,
} from '../util/IntegrationUtil';

const getLabel = WeaLocaleProvider.getLabel;
let Base64 = WeaTools.Base64;

export default class WorkflowFlowStore {

  @observable hasRight = false;
  @observable hasManageDetachableRight = false;
  @observable loading = false;
  @observable interfaceRegisterStore = new TableStore(); //流程接口注册
  @observable searchForm = new WeaForm(); //高级查询的表单
  @observable searchForm2 = new WeaForm(); //高级查询的表单
  @observable interfaceDeploymentStore = new TableStore(); //流程接口部署
  @observable newRegisterDMLForm = new WeaForm();
  @observable newRegisterDMLFormDMLTriggerConditionSetCustom = new WeaForm();
  @observable newRegisterDMLFormDMLValueSetCustom = new WeaForm();
  @observable newRegisterWebserviceForm = new WeaForm();
  @observable newRegisterCustomForm = new WeaForm();
  @observable newRegisterCustomOnlineForm = new WeaForm();

  @observable newDeploymentForm = new WeaForm();//接口部署表单

  @observable logStore = new LogStore();
  @observable logStoreWebservice = new LogStore();
  @observable logStoreCustom = new LogStore();
  @observable logStoreESB = new LogStore();  //ESB系统日志

  @observable logRunListStore = new TableStore(); //运行日志
  @observable searchFormRunList = new WeaForm(); //高级查询的表单
  @observable rightLoading = true;
  @observable flag = false;

  // ESB接口
  @observable newRegisterESBForm = new WeaForm();
  @observable newRegisterESBDetailForm = new WeaForm();
  @observable detailFormInfo = {};
  @observable detailInfo = {};
  @observable mainFormRef = '';
  @observable funForm = new WeaForm();
  @observable autoMappingForm = new WeaForm();


  dmlEditIndex = '';
  esbEditIndex = '';
  customEditIndex = '';
  webserviceEditIndex = '';

  @observable
  status = {
    NodeOperateSetDataSAP: [],
    SeqOperateSetDataSAP: [],
    selectedKey: 0,
    advancedSearchHeight: 120,
    flowConditioninfo: [],
    formConditioninfo: [],
    interfaceRegisterConditionInfo: [],
    interfaceDeploymentConditionInfo: [],
    searchFormRunListCondition: [],

    interfaceRegisterDMLFormFields: [],
    interfaceRegisterDMLFormHiddenFields: {},

    interfaceRegisterWebserviceFormFields: [],
    interfaceRegisterWebserviceFormHiddenFields: {},
    mainFieldMarkList: [],
    detailFieldMarkList: [],

    interfaceRegisterCustomFormFields: [],
    interfaceRegisterCustomFormHiddenFields: {},

    interfaceRegisterCustomOnlineFormFields: [],
    interfaceRegisterCustomOnlineFormHiddenFields: {},

    newDeploymentFormFields: [],
    newDeploymentFormHiddenFields: [],
    showDeploymentDialog: false,
    WeaTableEdit_NodeOperateSet: [],
    WeaTableEdit_NodeOperateSetData: [],
    WeaTableEdit_SeqOperateSet: [],
    WeaTableEdit_SeqOperateSetData: [],

    isAlertPage: false,
    showSearchAd: false,
    showSearchAd2: false,
    showFormDialog: false, //编辑表单设置
    editFormFields: [], //编辑表单内容
    editLabel: {}, //编辑表单内容后提示
    editLoading: false,
    meetingId: "", //编辑需要传的id
    showActionDialog: false, //动作设置弹框
    actionLoading: false,
    actionFormFields: [],
    rightMenus: [], //右键菜单
    rightMenus1: [], //右键菜单
    showCreateBill: false, //卡片生成表单
    cardToFormLoading: false, //表单设置加载
    billLoading: false, //卡片生成表单加载
    rowSelectIds: [], //check选择行id
    showRegisterDMLDialog: false,
    showRegisterWebserviceDialog: false,
    showRegisterCustomDialog: false,
    showRegisterCustomOnlineDialog: false,

    DMLTriggerConditionSet: [], // WeaTableEdit_DMLTriggerConditionSet
    DMLValueSet: [],
    WeaTableEdit_CustomParameterSet: [],
    WeaTableEdit_CustomParameterData: [],
    WeaTableEdit_DMLValueData: [],
    WeaTableEdit_DMLTriggerData: [],

    WeaTableEdit_WebserviceParameterSet: [],
    WebserviceMethodList: [],
    WebserviceMethodParameterDatas: [],

    logDMLVisible: false,
    logWebserviceVisible: false,
    logCustomVisible: false,
    logRunListVisible: false,

    // ESB接口
    esbRightMenus: [],
    esbRequestDatas: [],
    esbRequestParams: [],
    esbActionTableSet: [],
    esbActionTableDatas: [],
    showRegisterESBDialog: false,
    tableTabDatas: [],
    nullskip_1: [],

    // test页面
    dialogType: '',
    baseTabKey: '',
    selectedKey2: 'base',
    testInitDatas: {},
    baseDatas: {}, //请求参数
    baseApiUrl: {}, //请求地址


    showTestVersion: false,
    topinfo: {},
    menuinfo: [],
    collectInfo: {},
    buttoninfo: [],
    moreBtninfo: [],
    testColumns: [],
    testTitle: {},
    errorMessage: '',
    errorMessage2: '',
    currentStep: 0,
    isFromWorkflow: false,
  };

  setLogIndex = (val) => {
    this.logIndex = val;
  }

  setDmlEditIndex = (val) => {
    this.dmlEditIndex = val;
  }

  setEsbEditIndex = (val) => {
    this.esbEditIndex = val;
  }

  setCustomEditIndex = (val) => {
    this.customEditIndex = val;
  }

  setWebServiceEditIndex = (val) => {
    this.webserviceEditIndex = val;
  }

  @action cleanStore = () => {
    this.rightLoading = true;
    this.hasRight = false;
    this.hasManageDetachableRight = false;
    this.detailFormInfo = {};
    this.detailInfo = {};
    this.searchForm = new WeaForm();
    this.searchForm2 = new WeaForm();
    this.flag = false;
    this.dmlEditIndex = '';
    this.esbEditIndex = '';
    this.customEditIndex = '';
    this.webserviceEditIndex = '';
    this.logIndex = '';
    this.setState({
      subcompanyid: "",
      selectedKey: 0,
      advancedSearchHeight: 120,
      interfaceRegisterConditionInfo: [],
      interfaceDeploymentConditionInfo: [],
      searchFormRunListCondition: [],
      interfaceRegisterDMLFormFields: [],
      interfaceRegisterDMLFormHiddenFields: {},

      interfaceRegisterWebserviceFormFields: [],
      interfaceRegisterWebserviceFormHiddenFields: {},
      mainFieldMarkList: [],
      detailFieldMarkList: [],

      interfaceRegisterCustomFormFields: [],
      interfaceRegisterCustomFormHiddenFields: {},

      interfaceRegisterCustomOnlineFormFields: [],
      interfaceRegisterCustomOnlineFormHiddenFields: {},

      newDeploymentFormFields: [],
      newDeploymentFormHiddenFields: [],
      showDeploymentDialog: false,
      WeaTableEdit_NodeOperateSet: [],
      WeaTableEdit_NodeOperateSetData: [],
      WeaTableEdit_SeqOperateSet: [],
      WeaTableEdit_SeqOperateSetData: [],

      isAlertPage: false,
      showSearchAd: false,
      showSearchAd2: false,
      showFormDialog: false, //编辑表单设置
      editFormFields: [], //编辑表单内容
      editLabel: {}, //编辑表单内容后提示
      editLoading: false,
      meetingId: "", //编辑需要传的id
      showActionDialog: false, //动作设置弹框
      actionLoading: false,
      actionFormFields: [],
      rightMenus: [],
      rightMenus1: [],
      billLoading: false,
      cardToFormLoading: false,
      rowSelectIds: [], //check选择行id
      showRegisterDMLDialog: false,
      showRegisterWebserviceDialog: false,
      showRegisterCustomDialog: false,
      showRegisterCustomOnlineDialog: false,
      WeaTableEdit_CustomParameterSet: [],
      WeaTableEdit_CustomParameterData: [],
      WeaTableEdit_DMLValueData: [],
      WeaTableEdit_DMLTriggerData: [],

      WeaTableEdit_WebserviceParameterSet: [],
      WebserviceMethodList: [],
      WebserviceMethodParameterDatas: [],

      logDMLVisible: false,
      logWebserviceVisible: false,
      logCustomVisible: false,
      logRunListVisible: false,


      // ESB接口
      esbRegisterFormCondition: [],
      esbRightMenus: [],
      esbRequestDatas: [],
      esbRequestParams: [],
      esbRequestCells: [],
      esbActionTableSet: [],
      esbActionTableDatas: [],
      showRegisterESBDialog: false,
      tableTabDatas: [],
      detailFormTabDatas: [],
      selectType: [],
      detailTableDatas: [],
      mainTable: [],
      detailTableSet: [],
      esbLoading: true,
      nullskip_1: [],
      tabs: [],
      tabSelectedKey: '',
      selectedRowKeys: [],
      operateSrc: '',
      interfaceRegisterEsbHiddenFields: "",
      eventStatus: "",
      esbidName: "",
      formidName: "",
      buttonLoading: true,
      operateClickIndex: ""
    });
  }

  @action
  doInit = () => {
    // this.loading = true;
    this.cleanStore();
    // this.getInterfaceDeploymentCondition();
    // this.getInterfaceDeploymentRightMenus();
    // this.getInterfaceDeploymentList();
    checkHasOrganization((result) => {
      this.setState({
        hasOrganization: result,
      })
    });
    this.getInterfaceRegisterCondition({}, () => {
      this.getInterfaceRegisterRightMenus();
      this.getInterfaceRegisterList();
    });

    // this.getInterfaceRegisterDMLAddForm();
    // this.getInterfaceRegisterWebserviceAddForm();
    // this.getInterfaceRegisterCustomAddForm();
    // this.getInterfaceRegisterCustomAddFormOnline();
    // this.getInterfaceDeploymentAddForm();

    // this.loading = true;

  };

  @action
  doInitDriver = () => {
    this.cleanStore();
    this.setState({
      selectedKey: '1'
    })
    this.getInterfaceDeploymentCondition();
    this.getInterfaceDeploymentRightMenus();
    this.getInterfaceDeploymentList();
  }

  setState = (params = {}) => {
    let status = { ...this.status };
    Object.keys(params).forEach(key => {
      status[key] = params[key];
    });
    this.status = status;
  };

  /**
   * 表单参数form
   */
  @observable sqlTextForm = {
    condition: [],
    form: new WeaForm(),
    loading: true,
  };

  //初始化sqlTextForm
  @action
  initSqlTestForm = () => {
    this.sqlTextForm = {
      condition: [],
      form: new WeaForm(),
      loading: true,
    };
  };

  /**
   * 是否携带表单参数
   * @returns {boolean}
   */
  hasFormParam (type, testId) {
    let bool = false;

    API.checkHasParam(type, testId).then(result => {
      if (result.status) {
        bool = true;
      }
    });

    return bool;
  }
  /**
   * 初始化testForm
   */
  initTestForm = () => {
    this.setState({
      currentStep: 0,
      showTestVersion: false,
      baseTabKey: '',
      testInitDatas: {},
      errorMessage: '',
      errorMessage2: '',
      baseApiUrl: '/api/integration/workflowaction/test',
    });
  };

  /**
   * 保存表单参数
   */
  saveParams = (formParams) => {
    let params = {
      formParams: Base64.encode(formParams),
    };
    let testId = this.status.baseDatas.testId;
    let type = this.status.baseDatas.type;
    API.saveParam(params, type, testId).then(result => {
      if (result.status) {
        this.getTestFields("preview");
        this.getTestMenu("preview");
        this.setState({
          currentStep: 2,
          baseTabKey: 'preview',
        });
      } else {
        this.setState({
          errorMessage2: res.error
        });
      }
    });
  };

  /**
   * 获取基础信息维护控件
   */
  @action
  getTestFields = (type) => {
    this.setState({
      testColumns: '',
      testTitle: '',
    });

    if (type == 'param') {//获取参数form信息
      this.setState({
        baseApiUrl: '/api/integration/workflowaction/test/' + type,
      });
      API.getFields(this.status.baseApiUrl + '/' + type, this.status.baseDatas).then(res => {
        if (res.status) {
          this.sqlTextForm.form.initFormFields(res.data);
          this.sqlTextForm.condition = res.data;
        } else {
          this.setState({
            errorMessage: res.error,
          });
        }
      })
    } else if (type == "base") {
      this.setState({
        baseApiUrl: '/api/integration/workflowaction/test/' + type,
      });
      API.getFields(this.status.baseApiUrl, this.status.baseDatas).then(res => {
        if (res.status) {
          this.setState({
            testColumns: res.data.columns,
            testTitle: res.data.title,
          });
        }
      });
    } else if (type == 'preview') {//获取参数form信息
      this.setState({
        baseApiUrl: '/api/integration/workflowaction/test/' + type,
      });
      API.getFields(this.status.baseApiUrl + '/' + type, this.status.baseDatas).then(res => {
        if (res.status) {
          this.sqlTextForm.form.initFormFields(res.data);
          this.sqlTextForm.condition = res.data;
        } else {
          this.setState({
            errorMessage: res.error,
            errorMessage2: res.error,
          });
        }
      })
    }
  };

  /**
   * 获取右键菜单
   */
  @action
  getTestMenu = (type) => {
    this.setState({
      baseApiUrl: '/api/integration/workflowaction/test/' + type,
    });
    API.getRightMenu(this.status.baseApiUrl, this.status.baseDatas).then(result => {
      if (result.status) {
        this.setState({
          menuinfo: result.data.rightMenus,
          collectinfo: result.data.collectParams,
          topinfo: result.data.top,
          buttoninfo: result.data.button,
          moreBtninfo: result.data.moreButton,
        })
      }
    })
  };

  /**
   * 获取右键菜单2
   */
  @action
  getTestMenu2 = (type) => {
    this.setState({
      baseApiUrl: '/api/integration/workflowaction/test/' + type,
    });
    API.getRightMenu2(this.status.baseApiUrl, this.status.baseDatas).then(result => {
      if (result.status) {
        this.setState({
          menuinfo: result.data.rightMenus,
          collectinfo: result.data.collectParams,
          topinfo: result.data.top,
          buttoninfo: result.data.button,
          moreBtninfo: result.data.moreButton,
        })
      }
    })
  };


  /**
   * 获取测试信息
   * @param type
   */
  @action
  getTestForm = (type) => {
    let testId = this.status.baseDatas.testId;
    if (type == 'base') {//获取测试结果
      API.getBase(this.status.baseDatas.type, testId).then(result => {
        this.setState({
          testInitDatas: {},
          errorMessage: '',
          errorMessage2: '',
        });
        if (result.status) {
          this.setState({
            testInitDatas: result.data.base
          });
        }
      });
    }

  };

  /**
   * 测试基础配置
   * @param type
   * @param testId
   */
  testConfig = (type, testId) => {
    API.checkHasParam(type, testId).then(result => {
      if (result.status) {
        this.setState({
          showTestVersion: true,
          baseTabKey: "base",
          testInitDatas: {},
          errorMessage: '',
          errorMessage2: '',
          baseApiUrl: '/api/integration/workflowaction/test/base',
          baseDatas: {
            testId: testId,
            type: type,
          }
        });
        this.getTestFields("base");// 地址 /api/integration/workflowaction/test/param/param/getFields
        this.getTestMenu("base");// 地址 /api/integration/workflowaction/test/param/getRightMenu
        this.getTestForm("base");

      } else {
        this.setState({
          showTestVersion: true,
          baseTabKey: "base",
          testInitDatas: {},
          errorMessage: '',
          errorMessage2: '',
          baseApiUrl: '/api/integration/workflowaction/test/base',
          baseDatas: {
            testId: testId,
            type: type,
          }
        });
        this.getTestFields("base");
        this.getTestMenu2("base");
        this.getTestForm("base");
      }
    });
  };

  // ESB
  @action getESBRightMenu = (params = {}) => {
    if (!(params && params.operate === "edit")) {
      params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    }
    API.getESBRightMenu(params).then(result => {
      if (result.status) {
        this.setState({ esbRightMenus: result.data || [] })
      }
    })
  }

  // 为了让datas在展示的时候上下级关系正确展示
  getRequestDatas = (datas = []) => {
    let firstDatas = [], firstId = [];
    datas && datas.forEach(data => {
      if (data.paramKey && data.paramKey.indexOf('.') == -1 && (!firstId.includes(data.paramKey))) {
        firstId.push(data.paramKey);
        firstDatas.push(data);
      }
    })
    let allDatas = [];
    for (let i = 0; i < firstDatas.length; i++) {
      allDatas.push(firstDatas[i]);
      this.getAllDatas(firstDatas[i], datas, allDatas);
    }
    return allDatas;
  }

  getAllDatas = (currentData, datas, allDatas) => {
    let id = currentData.paramKey.split('.');
    datas && datas.forEach(data => {
      let dataId = data.paramKey ? data.paramKey.split('.') : [];
      if (dataId.length == (id.length + 1) && dataId.slice(0, id.length).join('.') === currentData.paramKey) {
        allDatas.push(data);
        this.getAllDatas(data, datas, allDatas);
      }
    })
    return;
  }

  // 关闭时清空一些数据
  @action cleanESBForm = () => {
    this.setState({
      isTop: "0",
      detailTableName: "",
      autoMappingCondition: [],
      interfaceRegisterEsbHiddenFields: "",
      funFormCondition: [],  // 表单建模用到的属性
      expandId: "",
      funTabs: [],
      from: "",
      esbRegisterFormCondition: [],
      esbRegisterDetailFormCondition: [],
      esbRightMenus: [],
      esbRequestDatas: [],
      esbRequestParams: [],
      esbRequestCells: [],
      esbActionTableSet: [],  // 主表赋值的columns
      esbActionTableDatas: [],
      showRegisterESBDialog: false,
      tableTabDatas: [],
      selectType: [],
      detailTableDatas: [],
      detailFormTabDatas: [],
      mainTable: [],
      detailTableSet: [],
      esbLoading: true,
      buttonLoading: true,
      nullskip_1: [],
      tabs: [],  //明细表的key记录
      tabSelectedKey: '',
      selectedRowKeys: [],
    })
    this.funForm = null;
    this.detailFormInfo = null;
  }

  // 建模的入口
  @action
  getESBInfo = (params = {}) => {
    this.cleanESBForm();
    if (['1', '2'].includes(`${params.from}`)) {
      this.setState({
        showRegisterESBDialog: true
      });
      this.getESBRightMenu();
      this.getESBFields(params);
    }
  }

  // 自动映射确认
  @action getAutoMapping = (params = {}, saveCallBack = null) => {
    let func = "";
    if (['1', '2'].includes(`${params.from}`)) {
      func = ["getFormModuleAutoMapping", "getFormModuleFieldAutoMapping"][Number(params.from) - 1];
      delete params.from;
    }
    if (func) {
      API[func](params).then(result => {
        if (result.status) {
          // this.setState({
          //   autoMappingDatas: result.data || []
          // });
          if (saveCallBack && typeof (saveCallBack) === "function") {
            saveCallBack(result.data);
          }
        }
      });
    }
  }

  // 自动映射form表单
  @action getAutoMappingFields = (params = {}) => {
    this.autoMappingForm = new WeaForm();
    let func = "";
    if (['1', '2'].includes(`${params.from}`)) {
      func = "getFormModuleAutoMappingFields";
      delete params.from;
    }
    if (func) {
      API[func](params).then(result => {
        if (result.status) {
          result.data.fields && result.data.fields.forEach((v, index) => {
            if (v && v.items) {
              v.items.forEach((item, idx) => {
                if (item.helpfulTip) {
                  result.data.fields[index].items[idx].helpfulTip = <div dangerouslySetInnerHTML={{ __html: item.helpfulTip }} />;
                }
              })
            }
          })
          this.autoMappingForm.initFormFields(result.data.fields);
          this.setState({
            autoMappingCondition: result.data.fields || []
          })
        }
      });
    }
  }

  // 建模自定义函数
  @action getFunFields = () => {
    this.setState({ buttonLoading: true, esbLoading: true });
    this.funForm = new WeaForm();
    API.getFormModuleFunFields().then(result => {
      if (result.status) {
        this.setState({
          funFormCondition: result.data.condition || []
        })
        this.funForm.initFormFields(result.data.condition);
      }
      this.setState({ buttonLoading: false, esbLoading: false });
    })
  }

  getMainTableDatas = (datas = []) => {
    return datas && datas.map(data => {
      return {
        ...data,
        nullSkip: data.nullSkip == 0 ? '0' : '1'
      }
    })
  }

  // 主表设置必填的验证
  getMainValidator = (flag = "mainForm", tabSelectedKey = "") => {
    const {
      esbActionTableDatas
    } = this.status;
    let dbFieldNames = [];
    if ("mainForm" === flag) {
      dbFieldNames = esbActionTableDatas && esbActionTableDatas.map(v => v.dbFieldName);
    } else if ("detail" === flag) {
      try {
        if (this.detailFormInfo[tabSelectedKey] && this.detailFormInfo[tabSelectedKey].paramDatas) {
          dbFieldNames = this.detailFormInfo[tabSelectedKey].paramDatas.map(v => v.dbFieldName);
        }
      } catch (err) { }
    }
    return {
      rules: {
        dbFieldName: "required|only",
        esbFieldName: "required"
      },
      customRegister: [
        {
          name: "only",
          rules: (value, requirement, attribute) => {
            return dbFieldNames.indexOf(value) === dbFieldNames.lastIndexOf(value);
          },
          errorMessage: getLabel('507589', '表单字段重复')
        }
      ]
    }
  }

  // 建模对接ESB 赋值设置主表的columns获取
  @action getMainFields = (params = {}) => {
    this.setState({ buttonLoading: true, esbLoading: true });
    let callFun = (params.from && (Number(params.from) - 1 > -1)) ? ["getFormModuleMainFields", "getFormModuleFieldMainFields"][Number(params.from) - 1] : "getWorkflowMainFields";
    if (callFun) {
      API[callFun]().then(result => {
        if (result.status) {
          this.setState({
            esbActionTableSet: result.data.esbActionTableSet || [],
            esbActionTableDatas: result.data.esbActionTableSetData.data || [],
            selectedRowKeys: [],
          });
        }
        this.setState({ buttonLoading: false, esbLoading: false });
      })
    }
  }

  @action getESBFields = (params = {}) => {
    this.newRegisterESBForm = new WeaForm();
    this.funForm = new WeaForm();
    this.setState({
      esbLoading: true,
      showAlert: false,
      alertMessage: '',
      buttonLoading: true,
      expandId: '',
      from: params.from != "wf" ? (params.from || "") : "",
      tableTabDatas: [{
        title: getLabel(0, '主表'),
        key: '0',
      }], // 流程接口中有默认的datas，建模中没有
    });
    let func = 'getESBFields';
    if (params.from && params.from != "wf") {
      // 建模对接ESB
      this.setState({
        tableTabDatas: [],
        expandId: params.from === '1' ? params.expandId : params.from === '2' ? params.modeId : '',
        operateSrc: params.actionId
      });
      func = (Number(params.from) - 1 > -1) ? ['getFormModuleField', 'getFormModuleFieldInfo'][Number(params.from) - 1] : '';
    }
    if (func) {
      if (params.operate === "edit") {
      } else {
        if (!params.from) {
          params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
        }
      }
      API[func](params).then((result) => {
        if (result.status) {
          const { operateSrc } = this.status;
          this.newRegisterESBForm.initFormFields(result.data.condition);
          this.setState({
            selectedRowKeys: [],
            esbRegisterFormCondition: result.data.condition || [],
            esbRequestParams: result.data.esbActionRequestSet || [],
            esbRequestDatas: this.getRequestDatas(result.data.esbActionRequestData.data || []),
            esbActionTableSet: [],
            esbActionTableDatas: [],
            nullskip_1: result.data.nullskip_1 || [],
            interfaceRegisterEsbHiddenFields: result.data.workflowInfo ? result.data.workflowInfo.data || '' : '',
          });
          result.data.condition && result.data.condition[0] && result.data.condition[0].items && result.data.condition[0].items.forEach((v) => {
            if (v.domkey[0] === 'esbid') {
              this.setState({
                eventStatus: v.eventStatus || '',
                esbidName: (v.browserConditionParam && v.browserConditionParam.replaceDatas && v.browserConditionParam.replaceDatas[0]) ? v.browserConditionParam.replaceDatas[0].name || '' : '',
              });
            } else if (v.domkey[0] === 'formid') {
              this.setState({
                formidName: (v.browserConditionParam && v.browserConditionParam.replaceDatas && v.browserConditionParam.replaceDatas[0]) ? v.browserConditionParam.replaceDatas[0].name || '' : '',
              });
            }
            if (params.from && v.domkey[0] === 'formName') {
              this.setState({
                formidName: v.value
              })
            }
          });
          if (params.from) {
            result.data.condition && result.data.condition[1] && result.data.condition[1].items && result.data.condition[1].items.forEach((v) => {
              if (v.domkey[0] === 'esbid') {
                this.setState({
                  eventStatus: v.eventStatus || '',
                  esbidName: (v.browserConditionParam && v.browserConditionParam.replaceDatas && v.browserConditionParam.replaceDatas[0]) ? v.browserConditionParam.replaceDatas[0].name || '' : '',
                })
              }
            })
          }
          // 编辑的时候获取额外的参数
          if (operateSrc) {
            // 渲染requestCells
            let mainFormKey = '';
            if (result.data.tableInfo && result.data.tableInfo.data) {
              let tabs = result.data.tableInfo.data.detailTable && result.data.tableInfo.data.detailTable.map(v => v.key);
              // mainFormKey = (result.data.tableInfo.data.mainTable && result.data.tableInfo.data.mainTable[0] && result.data.tableInfo.data.mainTable[0].key) || '0';
              if (result.data.tableInfo.data.tableList && result.data.tableInfo.data.tableList.length) {
                mainFormKey = result.data.tableInfo.data.tableList[0].key;
                if (params.from == '2' && this.newRegisterESBForm.getFormParams().detailIndex != '0') {
                  result.data.tableInfo.data.tableList.forEach((item) => {
                    if (!tabs.includes(item.key)) {
                      tabs.push(item.key);
                    }
                  });
                }
              }
              this.setState({
                tableTabDatas: result.data.tableInfo.data.tableList || [],
                detailFormTabDatas: result.data.tableInfo.data.detailTable || [],
                selectType: result.data.tableInfo.data.selectType || [],
                mainTable: result.data.tableInfo.data.mainTable || [],
                tabs,
                tabSelectedKey: mainFormKey,
              });
            }
            if (result.data.detailDetailTables) {
              let tableListTabs = [],
                detailForm = {};
              if (result.data.tableInfo.data && result.data.tableInfo.data.tableList) {
                if (["1", "2"].includes(params.from)) {
                  result.data.tableInfo.data.tableList.forEach(v => {
                    if ("1" === v.setType) {
                      tableListTabs.push(v.key);
                    }
                  })
                } else {
                  let mainFormKey = (result.data.tableInfo.data.mainTable && result.data.tableInfo.data.mainTable[0] && result.data.tableInfo.data.mainTable[0].key) || '0';
                  result.data.tableInfo.data.tableList.forEach(v => v.key != mainFormKey && tableListTabs.push(v.key));
                }
              }
              for (let i = 0; i < tableListTabs.length; i++) {
                let formKey = tableListTabs[i];
                let detail = (result.data.detailDetailTables.data && result.data.detailDetailTables.data[formKey]) ? result.data.detailDetailTables.data[formKey] : '';
                if (detail) {
                  let esbDetailFieldChange = '',
                    dbFieldNameChange = '',
                    esbFieldNameChange = '';
                  detail.data.condition && detail.data.condition[0] && detail.data.condition[0].items && detail.data.condition[0].items.forEach((v) => {
                    if (v.domkey[0] === 'esbDetailField') {
                      esbDetailFieldChange = v.isChange;
                    } else if (v.domkey[0] === 'dbFieldName') {
                      dbFieldNameChange = v.isChange;
                    } else if (v.domkey[0] === 'esbFieldName') {
                      esbFieldNameChange = v.isChange;
                    }
                  });
                  detailForm[formKey] = {};
                  detailForm[formKey].form = new WeaForm();
                  detailForm[formKey].form.initFormFields(detail.data.condition);
                  detailForm[formKey].condition = detail.data.condition || [];
                  detailForm[formKey].paramConfig = detail.data.esbActionTableSet || [];
                  detailForm[formKey].paramCells = [];
                  detailForm[formKey].paramDatas = this.getMainTableDatas(detail.data.esbActionTableSetData.data);
                  detailForm[formKey].nullskip_1 = detail.data.nullskip_1 || [];
                  detailForm[formKey].esbDetailFieldChange = esbDetailFieldChange;
                  detailForm[formKey].dbFieldNameChange = dbFieldNameChange;
                  detailForm[formKey].esbFieldNameChange = esbFieldNameChange;
                  try {
                    detailForm[formKey].superParamKey = detail.data.condition[0].items.find(v => v.domkey[0] === 'esbDetailField').browserConditionParam.replaceDatas[0].id || '';
                  } catch (err) {
                    detailForm[formKey].superParamKey = '';
                  }
                }
              }
              this.detailFormInfo = detailForm;
            }
            if (result.data.function && result.data.function.data && result.data.function.data.condition) {
              try {
                this.funForm.initFormFields(result.data.function.data.condition);
                this.setState({
                  funFormCondition: result.data.function.data.condition || [],
                });
              } catch (err) { }
            }
            if (result.data.mainTables && result.data.mainTables.data) {
              this.setState({
                esbActionTableSet: result.data.mainTables.data.esbActionTableSet || [],
                esbActionTableDatas: (result.data.mainTables.data.esbActionTableSetData && result.data.mainTables.data.esbActionTableSetData.data) ? this.getMainTableDatas(result.data.mainTables.data.esbActionTableSetData.data) || [] : [],
              });
            }
          }
        }
        this.setState({ esbLoading: false, buttonLoading: false });
        if (['1'].includes(`${params.from}`)) {
          // 建模对接ESB
          let key = params.from == '1' ? 'expandId' : params.from === '2' ? 'modeId' : '';
          this.getSelectData({ actionId: params.actionId, [key]: params[key], from: params.from });
        }
      });
    }
  }

  // 获取请求数据
  @action getESBRequestDatas = (params, func) => {
    this.setState({ esbLoading: true, buttonLoading: true });
    let callBack = "getESBRequestDatas";
    if (params && params.from && Number(params.from) && (Number(params.from) - 1) > -1) {
      callBack = ["getFormModuleRequestDatas", "getFormModuleFieldRequestDatas"][Number(params.from) - 1];
      delete params.from;
    }
    if (callBack) {
      API[callBack](params).then(result => {
        if (result.status) {
          result.data && result.data.forEach((v, index) => {
            result.data[index] = {
              ...v,
              id: '',
            }
          })
          this.setState({ esbRequestDatas: result.data || [] });
          typeof (func) === "function" && func();
        }
        this.setState({ esbLoading: false, buttonLoading: false });
      })
    }
  }

  @action getSelectData = (params = {}, func = null) => {
    this.setState({ esbLoading: true, buttonLoading: true });
    let fun = "getSelectData";
    if (params.from) {
      fun = (Number(params.from) - 1 > -1) ? ["getFormModuleSelectData", "getFormModuleFieldSelectData"][Number(params.from) - 1] : "";
    }
    API[fun](params).then(result => {
      if (result.status) {
        let tabs = result.data.detailTable && result.data.detailTable.map(v => v.key),
          tabSelectedKey = "";
        if (result.data.tableList && result.data.tableList.length) {
          tabSelectedKey = result.data.tableList[0].key;
          if ("2" == params.from && this.newRegisterESBForm.getFormParams().detailIndex != '0') {
            result.data.tableList.forEach(item => {
              if (!tabs.includes(item.key)) {
                tabs.push(item.key);
              }
            })
          }
        }
        this.setState({
          tableTabDatas: result.data.tableList || [],
          mainTable: result.data.mainTable || [],
          detailFormTabDatas: result.data.detailTable || [],
          funTabs: result.data.funSet || [],
          selectType: result.data.selectType || [],
          tabs,
          tabSelectedKey,
        })
        if (func && typeof (func) === "function") {
          func();
        }
      }
      this.setState({ esbLoading: false, buttonLoading: false });
    })
  }

  @action getESBDetailFields = (formKey, from = "") => {
    this.setState({ esbLoading: true, esbDetailFormFlag: false, buttonLoading: true });
    let func = "getESBDetailFields";
    if (from) {
      func = (from && (Number(from) - 1 > -1)) ? ["getFormModuleDetailFields", "getFormModuleFieldDetailFields"][Number(from) - 1] : "";
    }
    if (func) {
      API[func]().then(result => {
        if (result.status) {
          let detailForm = { ...this.detailFormInfo };
          detailForm[formKey] = {};
          detailForm[formKey].form = new WeaForm();
          detailForm[formKey].form.initFormFields(result.data.condition);
          detailForm[formKey].condition = result.data.condition || [];
          detailForm[formKey].paramConfig = result.data.esbActionTableSet || [];
          detailForm[formKey].paramCells = [];
          detailForm[formKey].paramDatas = [];
          detailForm[formKey].nullskip_1 = result.data.nullskip_1 || [];
          detailForm[formKey].superParamKey = "";
          this.detailFormInfo = detailForm;
        }
        this.setState({ esbLoading: false, esbDetailFormFlag: true, buttonLoading: false });
      })
    }
  }

  // 设置跳过空值， 默认值可编辑cells
  @action getTableEditable = (datas, flag) => {
    const {
      nullskip_1,
      tabSelectedKey
    } = this.status;
    let nullskip =
      flag === "mainForm" ? toJS(nullskip_1)
        : flag === "detail" ? toJS(this.detailFormInfo)[tabSelectedKey] ? toJS(this.detailFormInfo)[tabSelectedKey].nullskip_1 : toJS(nullskip_1)
          : [];
    let cells = [];
    datas && datas.forEach(v => {
      if (v.nullSkip == '1') {
        cells.push({
          rowKey: v.rowKey,
          ...nullskip
        })
      }
    });
    return cells;
  }

  @action saveAction = (params, saveCallBack = null, from = "") => {
    this.setState({ buttonLoading: true });
    let functionName = "saveAction";
    if (['1', '2'].includes(`${from}`)) {
      functionName = ["getFormModuleSave", "getFormModuleFieldSave"][Number(from) - 1];
    }
    API[functionName](params).then(result => {
      if (result.status) {
        saveCallBack && typeof (saveCallBack) === "function" && saveCallBack();
      }
      this.setState({ buttonLoading: false });
    })
  }

  @action delectAction = (params) => {
    API.delectAction(params).then(result => {
      if (result.status) {
        message.success(result.error);
        this.getInterfaceRegisterList();
      }
    })
  }

  @action checkEsbService = (params = {}, func) => {
    API.checkEsbService(params).then(result => {
      if (result.status) {
        typeof (func) === "function" && func();
      } else {
        message.error(result.error);
      }
    })
  }

  //流程接口部署高级搜索
  getInterfaceDeploymentCondition = (params = {}, callBack = null) => {
    params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    this.searchForm2 = new WeaForm();
    API.getInterfaceDeploymentCondition(params).then(result => {
      this.searchForm2.initFormFields(result.condition);
      let advancedSearchHeight = getSearchFormHeight(result.condition);
      this.setState({
        advancedSearchHeight,
        interfaceDeploymentConditionInfo: result.condition || [],
      });
      if (isCallBackFunction(callBack)) {
        callBack();
      }
    });
  };

  //流程接口注册高级搜索
  getInterfaceRegisterCondition = (params = {}, callBack = null) => {
    params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    this.searchForm = new WeaForm();
    API.getInterfaceRegisterCondition(params).then(result => {
      this.status = {
        ...this.status,
        interfaceRegisterConditionInfo: result.condition
      };
      if (result.condition) {
        this.searchForm.initFormFields(result.condition);
        let advancedSearchHeight = getSearchFormHeight(result.condition);
        this.setState({ advancedSearchHeight });
      }
      if (isCallBackFunction(callBack)) {
        callBack();
      }
    });
  };

  // 流程接口注册右键菜单
  getInterfaceRegisterRightMenus = (params = {}) => {
    params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    API.getRightMenus(0, params).then(result => {
      this.status = { ...this.status, rightMenus: result.rightMenus };
    });
  };
  // 流程接口部署右键菜单
  getInterfaceDeploymentRightMenus = (params = {}) => {
    params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    API.getRightMenus(1, params).then(result => {
      this.status = { ...this.status, rightMenus1: result.rightMenus };
    });
  };

  //接口注册列表
  getInterfaceRegisterList = () => {
    let params = (this.searchForm && this.searchForm.getFormParams()) || {};
    params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    API.getInterfaceRegisterList(params).then(result => {
      if (result.ret && result.ret === "noIntegrationdetachable") {
        this.hasManageDetachableRight = false;
      } else {
        this.hasManageDetachableRight = true;
      }
      if (result.ret && result.ret == "noright") {
        this.hasRight = false;
      } else {
        this.hasRight = true;
      }
      this.rightLoading = false;
      if (result.sessionkey) {
        this.interfaceRegisterStore.getDatas(result.sessionkey, 1);
      } else {
        this.status = { ...this.status, isAlertPage: true };
      }
    });
  };
  //接口部署列表
  getInterfaceDeploymentList = () => {
    let params = (this.searchForm2 && this.searchForm2.getFormParams()) || {};
    params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    API.getInterfaceDeploymentList(params).then(result => {
      if (result.ret && result.ret == "noright") {
        this.hasRight = false;
      } else {
        this.hasRight = true;
      }
      this.rightLoading = false;
      if (result.sessionkey) {
        this.interfaceDeploymentStore.getDatas(result.sessionkey, 1);
      } else {
        this.status = { ...this.status, isAlertPage: true };
      }
    });
  };

  getInterfaceRegisterRunLogList = (ps = {}) => {
    let params = (this.searchFormRunList && this.searchFormRunList.getFormParams()) || {};
    params = Object.assign({}, params, ps);
    API.getInterfaceRegisterRunLogList(params).then(result => {
      if (result.sessionkey) {
        this.logRunListStore.getDatas(result.sessionkey, 1);
      } else {
        this.status = { ...this.status, isAlertPage: true };
      }
    });
  };

  getInterfaceRegisterRunLogCondition = (saveCallBack = null) => {
    this.searchFormRunList = new WeaForm();
    API.getInterfaceRegisterRunLogCondition().then(result => {
      this.status = {
        ...this.status,
        searchFormRunListCondition: result.condition
      };
      if (result.condition) {
        this.searchFormRunList.initFormFields(result.condition);
        let advancedSearchHeight = getSearchFormHeight(result.condition);
        this.setState({ advancedSearchHeight });
        if (saveCallBack && typeof (saveCallBack) === "function") {
          saveCallBack();
        }
      }
    });
  };

  //接口注册DML表单
  getInterfaceRegisterDMLAddForm = (params, func) => {
    this.newRegisterDMLForm = new WeaForm();
    this.newRegisterDMLFormDMLTriggerConditionSetCustom = new WeaForm();
    this.newRegisterDMLFormDMLValueSetCustom = new WeaForm();
    this.flag = false;
    this.setState({ buttonLoading: true });
    if (!(params && params.actionid)) {
      params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    }
    API.getInterfaceRegisterDMLAddForm(params).then(result => {
      if (result.status) {
        if (result.WeaTableEdit_DMLTriggerSet && result.WeaTableEdit_DMLTriggerSet.Custom) {
          result.WeaTableEdit_DMLTriggerSet.Custom[0].items[0].maxRows = 4;
          this.newRegisterDMLFormDMLTriggerConditionSetCustom.initFormFields(
            result.WeaTableEdit_DMLTriggerSet.Custom
          );
        }
        if (result.WeaTableEdit_DMLValueSet && result.WeaTableEdit_DMLValueSet.Custom) {
          result.WeaTableEdit_DMLValueSet.Custom[0].items[1].maxRows = 4;
          this.newRegisterDMLFormDMLValueSetCustom.initFormFields(
            result.WeaTableEdit_DMLValueSet.Custom
          );
        }

        let hiddenFields = result.hiddenFields || {};
        if (params && params.from && params.from == 'wf') {
          hiddenFields = Object.assign({}, hiddenFields, this.status.interfaceRegisterDMLFormHiddenFields || {});
        }
        // "表单名称"字段有初始值，导致表单验证无法正确正确验证该字段
        let initFormidField = result.condition[0].items[1].browserConditionParam.replaceDatas[0];
        initFormidField.id === "0" && (initFormidField.id = "");
        this.newRegisterDMLForm.initFormFields(cloneDeep(result.condition));
        const { datasourceid, tempdmltablename } = this.newRegisterDMLForm.getFormParams();
        if ((!datasourceid) && tempdmltablename) {
          if (result.condition[1] && result.condition[1].items) {
            let index = result.condition[1].items.findIndex(data => data.domkey[0] === "dmltablename");
            if (index != -1) {
              result.condition[1].items[index].viewAttr = 1;
              result.condition[1].items[index].hasBorder = true;
            }
          }
        }
        this.status = {
          ...this.status,
          interfaceRegisterDMLFormFields: result.condition,
          interfaceRegisterDMLFormHiddenFields: hiddenFields,
          DMLTriggerConditionSet: result.WeaTableEdit_DMLTriggerSet,
          DMLValueSet: result.WeaTableEdit_DMLValueSet,
          WeaTableEdit_DMLValueData: result.WeaTableEdit_DMLValueData,
          WeaTableEdit_DMLTriggerData: result.WeaTableEdit_DMLTriggerData,
          menus: result.rightMenus || [],
        };
        typeof (func) === 'function' && func();
      }
      this.flag = true;
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.flag = true;
      this.setState({ buttonLoading: false });
    })
  };

  // 注册DML接口增删改提交动作处理
  getInterfaceRegisterDMLOperation = (params, callback, type) => {
    this.setState({ buttonLoading: true, isFromWorkflow: false, });
    API.getInterfaceRegisterDMLOperation(params).then(result => {
      if (params.ajaxMethod && params.ajaxMethod == "getmaintablename") {
        //更新下拉选项
        try {
          const { interfaceRegisterDMLFormFields } = toJS(this.status);
          const datas = [...result.dmlsourceinfo_options];
          interfaceRegisterDMLFormFields[0].items[4].options = datas;
          this.setState({ interfaceRegisterDMLFormFields: interfaceRegisterDMLFormFields });
          this.newRegisterDMLForm.updateFields({
            maintablename: result.maintablename,
            dmlsourceinfo: datas[0].key || ""
          });
          this.liandongDMLSourceId(this.newRegisterDMLForm);
        } catch (err) { }
      } else if (params.ajaxMethod && params.ajaxMethod == "getDMLTransRulesList") {
        isFunction(callback) && callback(result.dmlTransRulesList);
      } else {
        if (result.status == '1' && params.operate == 'delete') {
          message.success(getLabel(20461, '删除成功'));
          this.getInterfaceRegisterList();
          this.setState({ showRegisterDMLDialog: false, rowSelectIds: [] });
        } else if (result.status === '1' && type == "BTN_SAVE") {
          message.success(getLabel('22619', '保存成功'));
          this.getInterfaceRegisterList();
          this.setState({ showRegisterDMLDialog: false, rowSelectIds: [] });
        } else if (result.status === '1' && type == "BTN_TEST" && params && params.actionid) {
          //message.success("BTN_TEST");
          this.setState({ showRegisterDMLDialog: false, rowSelectIds: [] });
          let testId = params.actionid;
          this.testConfig("dml", testId);
        }

      }
      this.setState({ buttonLoading: false });
      isFunction(callback) && callback();
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };

  liandongDMLSourceId = (form) => {
    const { DMLValueSet, DMLTriggerConditionSet, interfaceRegisterDMLFormHiddenFields, WeaTableEdit_DMLValueData, WeaTableEdit_DMLTriggerData } = toJS(this.status);
    let formid = form.getFormParams().formid;
    let isBill = 0;
    if (formid < 0) {
      isBill = 1;
    }
    let params = Object.assign({}, interfaceRegisterDMLFormHiddenFields, this.newRegisterDMLForm.getFormParams(), this.newRegisterDMLFormDMLTriggerConditionSetCustom.getFormParams(), this.newRegisterDMLFormDMLValueSetCustom.getFormParams());
    params.dtinfo_WeaTableEdit_DMLValueData = JSON.stringify(WeaTableEdit_DMLValueData);
    params.dtinfo_WeaTableEdit_DMLTriggerData = JSON.stringify(WeaTableEdit_DMLTriggerData);
    params.operate = 'changetable';
    params.actionid = this.dmlEditIndex;
    params.isbill = isBill;
    this.getInterfaceRegisterDMLAddForm(params);

    let showdetail = "0";
    let tableid = "-1";
    let dmlsourceinfo = form.getFormParams().dmlsourceinfo;
    if (dmlsourceinfo != null && dmlsourceinfo.indexOf("detail_") == 0) {
      showdetail = "1";
      let sourceinfo = dmlsourceinfo.split("_");
      if (sourceinfo.length == 3) {
        tableid = sourceinfo[1];
      }
    }
    DMLValueSet.ColumnsConfig[2].com[0].browserConditionParam.dataParams.showdetail = showdetail;
    DMLValueSet.ColumnsConfig[2].com[0].browserConditionParam.dataParams.tableid = tableid;
    DMLTriggerConditionSet.ColumnsConfig[2].com[0].browserConditionParam.dataParams.showdetail = showdetail;
    DMLTriggerConditionSet.ColumnsConfig[2].com[0].browserConditionParam.dataParams.tableid = tableid;
    this.setState({ DMLValueSet, DMLTriggerConditionSet });
  }


  //接口注册自定义表单
  getInterfaceRegisterCustomAddForm = (params) => {
    this.newRegisterCustomForm = new WeaForm();
    this.setState({ buttonLoading: true });
    if (!(params && params.actionid)) {
      params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    }
    API.getInterfaceRegisterCustomAddForm(params).then(result => {
      let isOnline = -1;
      if (result.fieldValues && result.fieldValues.classname) {
        isOnline = result.fieldValues.classname.indexOf('weaver.interfaces.workflow.action.javacode');
      }
      if (isOnline >= 0) {
        this.setState({ showRegisterCustomDialog: false, showRegisterCustomOnlineDialog: true });
        this.getInterfaceRegisterCustomAddFormOnline(params);
      } else {
        let hiddenFields = result.hiddenFields || {};
        if (params && params.from && params.from == 'wf') {
          hiddenFields = Object.assign({}, this.status.interfaceRegisterCustomFormHiddenFields || {}, hiddenFields);
        }
        this.newRegisterCustomForm.initFormFields(result.condition);
        this.status = {
          ...this.status,
          interfaceRegisterCustomFormFields: result.condition,
          interfaceRegisterCustomFormHiddenFields: hiddenFields,
          WeaTableEdit_CustomParameterSet: result.WeaTableEdit_CustomParameterSet,
          WeaTableEdit_CustomParameterData: result.WeaTableEdit_CustomParameterData,
          menus: result.rightMenus || [],
        };
      }
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };

  //接口注册自定义表单
  getInterfaceRegisterCustomAddFormOnline = (params) => {
    this.setState({ buttonLoading: true });
    this.newRegisterCustomOnlineForm = new WeaForm();
    if (!(params && params.actionid)) {
      params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    }
    API.getInterfaceRegisterCustomAddFormOnline(params).then(result => {
      this.newRegisterCustomOnlineForm.initFormFields(result.condition);
      let hiddenFields = result.hiddenFields || {};
      if (params && params.from && params.from == 'wf') {
        hiddenFields = Object.assign({}, this.status.interfaceRegisterCustomOnlineFormHiddenFields || {}, hiddenFields);
      }
      this.status = {
        ...this.status,
        interfaceRegisterCustomOnlineFormFields: result.condition,
        interfaceRegisterCustomOnlineFormHiddenFields: hiddenFields,
        menus: result.rightMenus || [],
      };
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };

  getInterfaceRegisterCustomOperation = (params, callback) => {
    this.setState({ buttonLoading: true });
    API.getInterfaceRegisterCustomOperation(params).then(result => {
      if (params.submitstate && params.submitstate == 'test') {
        if (result.errmsgTip) {
          if (result.isError) {
            message.error(result.errmsgTip);
          } else {
            message.success(result.errmsgTip);
          }
        }
      } else {
        if (params.method != 'deletesingle' && result.status == 1) {
          if (result.ret) {
            message.success(getLabel('22619', '保存成功'));
            this.getInterfaceRegisterList();
            this.setState({ showRegisterCustomDialog: false, showRegisterCustomOnlineDialog: false, rowSelectIds: [] });
          } else {
            message.error(result.errorMsg);
          }

        } else if (params.method == 'deletesingle' && result.status == 1) {
          message.success(getLabel('20461', '删除成功'));
          this.getInterfaceRegisterList();
        }
      }
      isFunction(callback) && callback();
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };



  //接口注册Webservice表单
  getInterfaceRegisterWebserviceAddForm = (params) => {
    this.newRegisterWebserviceForm = new WeaForm();
    this.setState({ buttonLoading: true });
    if (!(params && params.actionid)) {
      params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    }
    API.getInterfaceRegisterWebserviceAddForm(params).then(result => {
      let hiddenFields = result.hiddenFields || {};
      if (params && params.from && params.from == 'wf') {
        hiddenFields = Object.assign({}, hiddenFields, this.status.interfaceRegisterWebserviceFormHiddenFields || {});
      }
      result.condition && result.condition[1] && result.condition[1].items && (result.condition[1].items.find(field => field.domkey[0] == 'retstr').maxRows = 4);
      result.condition && result.condition[2] && result.condition[2].items && (result.condition[2].items.find(field => field.domkey[0] == 'xmltext').maxRows = 4);
      this.status = {
        ...this.status,
        interfaceRegisterWebserviceFormFields: result.condition,
        interfaceRegisterWebserviceFormHiddenFields: hiddenFields,
        WeaTableEdit_WebserviceParameterSet: result.WeaTableEdit_WebserviceParameterSet,
        WebserviceMethodParameterDatas: result.WebserviceMethodParameterDatas,
        mainFieldMarkList: result.mainFieldMarkList,
        detailFieldMarkList: result.detailFieldMarkList,
        menus: result.rightMenus || [],
      };
      this.newRegisterWebserviceForm.initFormFields(result.condition);
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };
  getInterfaceRegisterWebserviceOperation = (params, callback, type) => {
    this.setState({ buttonLoading: true, isFromWorkflow: false });
    API.getInterfaceRegisterWebserviceOperation(params).then(result => {
      if (params.operator == 'getMainFieldMarkListAndDetailFieldMarkList') {
        //获取mark
        this.status = {
          ...this.status,
          mainFieldMarkList: result.mainFieldMarkList,
          detailFieldMarkList: result.detailFieldMarkList,
        };
      } else if (params.submitstate == 'test') {
        this.setWebServiceEditIndex(result.relatedId);
        if (result.errmsgTip) {
          message.success(result.errmsgTip);
        }
      } else {
        if (params.operator == "save" && result.status == '1' && type == "BTN_SAVE") {
          message.success(getLabel('22619', '保存成功'));
          this.getInterfaceRegisterList();
          this.setState({ showRegisterWebserviceDialog: false, rowSelectIds: [] });
          if (result.errmsgTip) {
            message.success(result.errmsgTip);
          }
        } else if (params.operator == 'delete' && result.status == '1') {
          message.success(getLabel(20461, '删除成功'));
          this.getInterfaceRegisterList();
          this.setState({ showRegisterWebserviceDialog: false, rowSelectIds: [] });
          if (result.errmsgTip) {
            message.success(result.errmsgTip);
          }
        } else if (params.operator == "save" && result.status == '1' && type == "BTN_TEST" && params && params.actionid) {
          this.setState({ showRegisterWebserviceDialog: false, rowSelectIds: [] });
          //message.success("测试");
          let testId = params.actionid;
          this.testConfig("ws", testId);
        }

      }
      isFunction(callback) && callback();
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };

  //接口部署表单
  getInterfaceDeploymentAddForm = (params = {}) => {
    this.status.NodeOperateSetDataSAP = [];
    this.status.SeqOperateSetDataSAP = [];
    this.newDeploymentForm = new WeaForm();
    this.setState({ buttonLoading: true });
    if (params.workflowid) {
    } else {
      params = Object.assign({}, params, { subcompanyid: this.status.subcompanyid });
    }
    API.getInterfaceDeploymentAddForm(params).then(result => {
      this.newDeploymentForm.initFormFields(result.condition);
      if (result.WeaTableEdit_NodeOperateSetData.length > 0) {
        result.WeaTableEdit_NodeOperateSetData.map(item => {
          if (item.tempinterfacetype == '4') {
            this.status.NodeOperateSetDataSAP.push(
              {
                tempactionid: item.tempactionid,
                interfaceid: {
                  com: [
                    {
                      type: 'TEXT',
                      disabled: true,
                    }
                  ]
                }
              }
            )
          }
        })
      }
      if (result.WeaTableEdit_SeqOperateSetData.length > 0) {
        result.WeaTableEdit_SeqOperateSetData.map(item => {
          if (item.tempinterfacetype == '4') {
            this.status.SeqOperateSetDataSAP.push(
              {
                tempactionid: item.tempactionid,
                interfaceid: {
                  com: [
                    {
                      type: 'TEXT',
                      disabled: true,
                    }
                  ]
                }
              }
            )
          }
        })
      }
      this.status = {
        ...this.status,
        newDeploymentFormFields: result.condition,
        newDeploymentFormHiddenFields: result.hiddenFields,
        WeaTableEdit_NodeOperateSet: result.WeaTableEdit_NodeOperateSet,
        WeaTableEdit_NodeOperateSetData: result.WeaTableEdit_NodeOperateSetData,
        WeaTableEdit_SeqOperateSet: result.WeaTableEdit_SeqOperateSet,
        WeaTableEdit_SeqOperateSetData: result.WeaTableEdit_SeqOperateSetData,
        menus: result.rightMenus || [],
      };
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };
  //接口部署提交动作
  getInterfaceDeploymentOperation = (params) => {
    this.setState({ buttonLoading: true });
    API.getInterfaceDeploymentOperation(params).then(result => {
      if (params.operate && params.operate == "getWorkflowNodeListAndSequenceList") {
        let list = result.workflowNodeListAndSequenceList;
        let formid = result.formid;
        this.status.WeaTableEdit_NodeOperateSet[4].com[0].options = list.nodeList;
        this.status.WeaTableEdit_SeqOperateSet[3].com[0].options = list.sequenceList;

        this.status.WeaTableEdit_NodeOperateSet[5].com[0].browserConditionParam.dataParams = { formid: formid };
        this.status.WeaTableEdit_SeqOperateSet[4].com[0].browserConditionParam.dataParams = { formid: formid };

        // this.setState({WebserviceMethodList: });
      } else {
        this.getInterfaceDeploymentList();
        this.setState({ showDeploymentDialog: false, rowSelectIds: [] });
        if (result.errmsgTip) {
          message.success(result.errmsgTip);
        }
      }
      this.setState({ buttonLoading: false });
    }).catch(err => {
      this.setState({ buttonLoading: false });
    })
  };


  /**
   * 取webserive方法和参数
   * @param params
   */
  getDataShowOperation = (params) => {
    API.getDataShowOperation(params).then(result => {
      if (params.operator && params.operator == "getregisteinfo") {
        const { interfaceRegisterWebserviceFormFields } = toJS(this.status);
        result.WebserviceMethodList = result.WebserviceMethodList ? result.WebserviceMethodList : [{ "": "" }];
        interfaceRegisterWebserviceFormFields[0].items[3].options = result.WebserviceMethodList;

        this.setState({ interfaceRegisterWebserviceFormFields: interfaceRegisterWebserviceFormFields });

        this.setState({ WebserviceMethodList: result.WebserviceMethodList });
        this.newRegisterWebserviceForm.updateFields({
          wsoperation: interfaceRegisterWebserviceFormFields[0].items[3].options[0]
        })
      } else if (params.operator && params.operator == "getmethodinfo") {
        this.setState({ WebserviceMethodParameterDatas: result.WebserviceMethodParameterDatas });
      }
    });
  };


  //确认
  confirmModal = (content, func, val) => {
    //确认信息， 方法， 方法参数
    Modal.confirm({
      title: `${getLabel(131329, '信息确认')}`,
      content: content,
      okText: `${getLabel(16631, '确定')}`,
      cancelText: `${getLabel(201, '取消')}`,
      onOk: () => func(val),
    })
  };

  /**
   *流程模块传过来的参数
   * @param params
   */
  fromWorkflowParams = (params) => {

    //有actionid的不需要workflowid
    let actionid = params.actionid || "";
    if (actionid && actionid.length > 0) {
      params.workflowid = "";
      params.nodeid = "";
    }
    if (params && params.type) {
      if (params.type === 'custom') {
        this.newRegisterCustomForm = new WeaForm();
        this.newRegisterCustomOnlineForm = new WeaForm();
        this.getInterfaceRegisterCustomAddForm({ actionid: params.actionid || '', from: 'wf' });
        let params3 = Object.assign({}, this.status.interfaceRegisterCustomFormHiddenFields || {}, params);
        this.setCustomEditIndex(params.actionid || '');
        this.setState({ showRegisterCustomDialog: true, interfaceRegisterCustomFormHiddenFields: params3 });
      } else if (params.type === 'customOnline') {
        this.newRegisterCustomOnlineForm = new WeaForm();
        let params4 = Object.assign({}, this.status.interfaceRegisterCustomOnlineFormHiddenFields || {}, params);
        this.getInterfaceRegisterCustomAddFormOnline({ actionid: params.actionid || '', from: 'wf' });
        this.setCustomEditIndex(params.actionid || '');
        this.setState({ showRegisterCustomOnlineDialog: true, interfaceRegisterCustomOnlineFormHiddenFields: params4 });
      } else if (params.type === 'dml') {
        this.newRegisterDMLForm = new WeaForm();
        this.newRegisterDMLFormDMLTriggerConditionSetCustom = new WeaForm();
        this.newRegisterDMLFormDMLValueSetCustom = new WeaForm();
        let params1 = Object.assign({}, this.status.interfaceRegisterDMLFormHiddenFields || {}, params);
        this.setState({ interfaceRegisterDMLFormHiddenFields: params1 });
        this.getInterfaceRegisterDMLAddForm({ from: 'wf', workflowid: params.workflowid || "", actionid: params.actionid || '' }, () => {
          this.setState({ showRegisterDMLDialog: true, isFromWorkflow: true, });
        });
        this.setDmlEditIndex(params.actionid || '');
      } else if (params.type === 'webService') {
        this.newRegisterWebserviceForm = new WeaForm();
        let params2 = Object.assign({}, this.status.interfaceRegisterWebserviceFormHiddenFields || {}, params);
        this.getInterfaceRegisterWebserviceAddForm({ from: 'wf', workflowid: params.workflowid || "", actionid: params.actionid || '', operate: params.operate || '' });
        this.setWebServiceEditIndex(params.actionid || '');
        this.setState({ showRegisterWebserviceDialog: true, interfaceRegisterWebserviceFormHiddenFields: params2, isFromWorkflow: true, });
      } else if (params.type === "esb") {
        this.setState({
          showRegisterESBDialog: true,
          operateSrc: params.actionid || "",
          selectedRowKeys: [],
          tabs: [],
          esbRegisterFormCondition: [],
          esbRightMenus: [],
          esbRequestDatas: [],
          esbRequestParams: [],
          esbRequestCells: [],
          esbActionTableSet: [],
          esbActionTableDatas: [],
          tableTabDatas: [],
          detailFormTabDatas: [],
          selectType: [],
          detailTableDatas: [],
          mainTable: [],
          detailTableSet: [],
          esbLoading: true,
          nullskip_1: [],
          tabSelectedKey: '',
        });
        this.getESBRightMenu();
        this.getESBFields({
          ...params,
          actionName: params.actionid || '',
          from: "wf",
        });
      }
    }
  }

}
