import React from "react";
import { inject, observer } from "mobx-react";
import { Button, message } from "antd";
import { toJS } from "mobx";
import { WeaLogView, WeaTableNew } from "comsMobx";
import { WeaDialog, WeaLocaleProvider, WeaRightMenu, WeaTab, WeaNewScroll, WeaPopoverHrm } from "ecCom";
import * as IntegrationUtil from "../../util/IntegrationUtil";
import OfsInfoEditWorkflowTypeDialog from "./OfsInfoEditWorkflowTypeDialog";
import isEmpty from 'lodash/isEmpty';
import WorkflowViewFormDialog from "./WorkflowViewFormDialog";
import OfsInfoBaseInfoContent from './OfsInfoBaseInfoContent';

const getLabel = WeaLocaleProvider.getLabel;
const WeaLogViewComp = WeaLogView.Component;
const { WeaTable } = WeaTableNew;

@inject("todoCenterStore")
@observer
export default class OfsInfoEditDetailDialog extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedKey: 0,
      targetId: '',
      logOfWorkflowDatasVisible: false,
      operateIndex: false,
      belongTypeTargetId: '',
      topTab: [
        {
          color: "#000000",
          groupid: "flowAll",
          showcount: true,
          title: `${getLabel(82751, "基础设置")}`,
          viewcondition_dt: 0
        }
        , {
          color: "#000000",
          groupid: "flowAll",
          showcount: true,
          title: `${getLabel(16579, "流程类型")}`,
          viewcondition_dt: 1
        }
        , {
          color: "#000000",
          groupid: "flowAll",
          showcount: true,
          title: `${getLabel(126871, "流程数据")}`,
          viewcondition_dt: 2
        }
        , {
          color: "#000000",
          groupid: "flowAll",
          showcount: true,
          title: `${getLabel(31695, "集成日志")}`,
          viewcondition_dt: 3
        }
      ],
    };
  }

  render () {
    const {
      todoCenterStore
    } = this.props, {
      tableStore_ofsInfoWorkflowType,
      tableStore_ofsInfoWorkflow,
      tableStore_ofsInfoLog,
      logStore_ofsInfo_workflowType,
      logStore2,
      status,
    } = todoCenterStore, {
      showSearchAd2,
      ofsInfoEditDetailDialogVisible,
      logOfsInfoWorklfowTypeVisible
    } = status, {
      topTab = [],
      selectedKey = 0,
      targetId,
      belongTypeTargetId,
      logOfWorkflowDatasVisible,
    } = this.state;

    return <WeaDialog
      ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@xhck9q`}
      title={getLabel('26473,31694', '编辑异构系统')}
      onCancel={this.closeEditDialog}
      visible={ofsInfoEditDetailDialogVisible}
      style={{ width: 1200, height: 600 }}
      hasScroll
      moduleName="integration"
      buttons={this.getDialogFooterButton()}
      moreBtn={this.getDialogFooterMoreBtn()}
    >
      <WeaRightMenu
        ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@n8ui1e`}
        datas={this.getRightMenu()}
        collectParams={[]}
      >
        <WeaTab
          ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@v5i7ey`}
          datas={topTab}
          keyParam="viewcondition_dt" //主键
          selectedKey={selectedKey}
          searchType={this.getSearchType()}
          advanceHeight={this.getAdvancedSearchHeight()}
          searchsBaseValue={this.getSearchBaseValue()}
          buttons={this.getTabButton()}
          showSearchAd={showSearchAd2}
          searchsAd={this.getAdvancedSearch()}
          buttonsAd={this.getTabButtonsAd()}
          setShowSearchAd={this.setShowSearchAd}
          hideSearchAd={this.hideSearchAd}
          onChange={this.handleTabChange}
          onSearch={this.handleSearchFun}
          onSearchChange={this.onSearchChange}
        // autoCalculateWidth={true}
        // leftStyle={{ paddingRight: 350 }}
        />
        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@dpi4s8`} height={550}>
          {
            selectedKey == 0
              ? <OfsInfoBaseInfoContent ecId={`${this && this.props && this.props.ecId || ''}_OfsInfoBaseInfoContent@zhzura`} />
              :
              <WeaTable
                rowKey={this.getRowKeyHandel}
                ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@rv5roz`}
                key={selectedKey}
                comsWeaTableStore={selectedKey == "1" ? tableStore_ofsInfoWorkflowType : selectedKey == "2" ? tableStore_ofsInfoWorkflow : tableStore_ofsInfoLog}
                hasOrder={true}
                // needScroll={true}
                onOperatesClick={this.onOperatesClick}
                rowSelection={this.getRowSelection(Number(selectedKey) - 1)}
                getColumns={this.getColumnsInfo}
              />
          }
        </WeaNewScroll>
        <OfsInfoEditWorkflowTypeDialog ecId={`${this && this.props && this.props.ecId || ''}_OfsInfoEditWorkflowTypeDialog@s3ojnc`} onRef={this.onRef} />
        {
          ofsInfoEditDetailDialogVisible
            ? <WorkflowViewFormDialog ecId={`${this && this.props && this.props.ecId || ''}_WorkflowViewFormDialog@jsknty`} />
            : null
        }
        <WeaLogViewComp
          ecId={`${this && this.props && this.props.ecId || ''}_WeaLogViewComp@02o68e`}
          visible={logOfsInfoWorklfowTypeVisible}
          onCancel={this.closeLogDialog1}
          logStore={logStore_ofsInfo_workflowType}
          logType="15"
          logSmallType={"93"}
          targetId={targetId}
          params={{ belongTypeTargetId }}
        />
        <WeaLogViewComp
          ecId={`${this && this.props && this.props.ecId || ''}_WeaLogViewComp@itqv9o`}
          visible={logOfWorkflowDatasVisible}
          onCancel={this.closeLogDialog2}
          logStore={logStore2}
          logType="15"
          logSmallType="90"
          targetId=''
          params={{ belongTypeTargetId }}
        />
      </WeaRightMenu>
    </WeaDialog>
  }
  getRowKeyHandel = (record) => {//设置流程数据行数据的唯一key值
    const { selectedKey } = this.state
    if (selectedKey == 2) {
      return `${record.randomFieldId}_${record.isremark}`
    } else {
      return record.randomField0
    }
  }
  onRef = (ref) => {
    this.child = ref
  }
  // 高级搜索
  setShowSearchAd = (bool) => this.props.todoCenterStore.setState({ showSearchAd2: bool });
  hideSearchAd = () => this.props.todoCenterStore.setState({ showSearchAd2: false });

  // 获取高级搜索的高度
  getAdvancedSearchHeight = () => {
    const {
      todoCenterStore,
    } = this.props, {
      condition_ofsInfoWorkflowType = [],
      condition_ofsInfoWorkflow = [],
      condition_ofsInfoLog = [],
    } = toJS(todoCenterStore.status), {
      selectedKey,
    } = this.state;
    let condition = [];

    if (selectedKey == 1) {
      condition = condition_ofsInfoWorkflowType;
    } else if (selectedKey == 2) {
      condition = condition_ofsInfoWorkflow;
    } else if (selectedKey == 3) {
      condition = condition_ofsInfoLog;
    }

    return IntegrationUtil.getSearchFormHeight(condition);
  }
  // 获取高级搜索类型
  getSearchType = () => {
    const { selectedKey } = this.state;

    if (selectedKey == 0) {
      return [];
    } else if (selectedKey == 3) {
      return ['advanced'];
    } else {
      return ['base', 'advanced'];
    }
  }

  getSearchBaseValue = () => {
    const {
      todoCenterStore
    } = this.props, {
      searchForm_ofsInfoWorkflowType,
      searchForm_ofsInfoWorkflow,
    } = todoCenterStore, {
      selectedKey = 0,
    } = this.state;

    return selectedKey == 1 ? searchForm_ofsInfoWorkflowType.getFormParams().workflowname : searchForm_ofsInfoWorkflow.getFormParams().requestname;
  }
  // 搜素内容的联动
  onSearchChange = value => {
    const {
      todoCenterStore
    } = this.props, {
      searchForm_ofsInfoWorkflowType,
      searchForm_ofsInfoWorkflow,
    } = todoCenterStore;

    if (this.state.selectedKey == 1) {
      searchForm_ofsInfoWorkflowType.updateFields({
        workflowname: value
      })
    } else if (this.state.selectedKey == 2) {
      searchForm_ofsInfoWorkflow.updateFields({
        requestname: value
      })
    }
  }

  // 高级搜索的searchAds
  getAdvancedSearch = () => {
    const { todoCenterStore } = this.props;
    const { searchForm_ofsInfoWorkflowType, searchForm_ofsInfoWorkflow, searchForm_ofsInfoLog, status, operateRecordIndex } = todoCenterStore;
    const { condition_ofsInfoWorkflowType, condition_ofsInfoWorkflow, condition_ofsInfoLog } = toJS(status);
    let form = searchForm_ofsInfoWorkflowType;
    let condition = condition_ofsInfoWorkflowType;

    if (this.state.selectedKey == 1) {
      form = searchForm_ofsInfoWorkflowType;
      condition = condition_ofsInfoWorkflowType;
    } else if (this.state.selectedKey == 2) {
      form = searchForm_ofsInfoWorkflow;
      condition = [...condition_ofsInfoWorkflow];
      condition.forEach((data, index) => {
        data && data.items && data.items.forEach((item, idx) => {
          if (item.domkey[0] === "workflowid") {
            condition[index].items[idx].browserConditionParam.dataParams = { sysid: operateRecordIndex };
          }
        })
      })
    } else if (this.state.selectedKey == 3) {
      form = searchForm_ofsInfoLog;
      condition = condition_ofsInfoLog;
    }
    return IntegrationUtil.getAdvancedItem(
      form,
      condition,
      this.handleSearchFun,
      false,
      this && this.props && this.props.ecId || '',
      "integrationTodoCenterEditDetail"
    );
  };

  handleSearchFun = () => {
    const {
      todoCenterStore
    } = this.props, {
      ofsInfoAddFormHiddenFields = {},
    } = todoCenterStore.status;
    let params = { sysid: ofsInfoAddFormHiddenFields.id };

    if (this.state.selectedKey == 1) {
      todoCenterStore.getOfsInfoWorkflowTypeList(params);
    } else if (this.state.selectedKey == 2) {
      todoCenterStore.getOfsInfoWorkflowList(params);
    } else if (this.state.selectedKey == 3) {
      todoCenterStore.getOfsInfoLogList(params);
    }
    todoCenterStore.setState({ showSearchAd2: false });
  }
  // 高级搜索的buttonsAd
  getTabButtonsAd = () => {
    const { todoCenterStore } = this.props;
    return IntegrationUtil.getSearchBtns(
      this.handleSearchFun,
      () => {
        if (this.state.selectedKey == 1) {
          todoCenterStore.searchForm_ofsInfoWorkflowType.reset();
        } else if (this.state.selectedKey == 2) {
          // todoCenterStore.searchForm_ofsInfoWorkflow.reset();
          this.reset();
        } else if (this.state.selectedKey == 3) {
          todoCenterStore.searchForm_ofsInfoLog.reset();
        }
      },
      () => todoCenterStore.setState({ showSearchAd2: false }),
      this && this.props && this.props.ecId || '',
      "integrationTodoCenterEditDetail"
    )
  }

  reset = () => {
    const {
      todoCenterStore
    } = this.props, {
      ofsInfoAddFormHiddenFields = {},
    } = todoCenterStore.status;
    let params = { sysid: ofsInfoAddFormHiddenFields.id };
    if (this.state.selectedKey == 1) {
      todoCenterStore.getOfsInfoWorkflowTypeCondition();
    } else if (this.state.selectedKey == 2) {
      todoCenterStore.getOfsInfoWorkflowCondition(params);
    } else if (this.state.selectedKey == 3) {
      todoCenterStore.getOfsInfoLogCondition();
    }
  }

  // tab页切换
  handleTabChange = v => {
    const {
      todoCenterStore
    } = this.props, {
      ofsInfoAddFormHiddenFields = {},
    } = todoCenterStore.status;
    let params = { sysid: ofsInfoAddFormHiddenFields.id };

    if (v == 1) {
      todoCenterStore.searchForm_ofsInfoWorkflowType.reset();
      todoCenterStore.getOfsInfoAddForm(params, () => {
        todoCenterStore.getOfsInfoWorkflowTypeCondition();
        todoCenterStore.getOfsInfoWorkflowTypeList(params);
        todoCenterStore.getOfsInfoWorkflowTypeRightMenu(params);
      });
    } else if (v == 2) {
      todoCenterStore.getOfsInfoAddForm(params, () => {
        todoCenterStore.searchForm_ofsInfoWorkflow.reset();
        todoCenterStore.getOfsInfoWorkflowCondition(params);
        todoCenterStore.getOfsInfoWorkflowList(params);
        todoCenterStore.getWorkflowRightMenu(params);
      });
    } else if (v == 3) {
      todoCenterStore.searchForm_ofsInfoLog.reset();
      todoCenterStore.getOfsInfoLogCondition();
      todoCenterStore.getOfsInfoLogList(params);
    } else if (v == 0) {
      todoCenterStore.getOfsInfoAddForm(params);
    }

    this.setState({ selectedKey: v });
  }

  // 获取编辑页面底部弹窗
  getDialogFooterButton = () => {
    if (this.state.selectedKey == "0") {
      return [
        <Button
          ecId={`${this && this.props && this.props.ecId || ''}_Button@jv61vv@integrationTodoCenterEditDetailButtonSave`}
          type="primary"
          onClick={() => this.onRightMenuClick('BTN_SAVE')}
        >{getLabel(86, '保存')}</Button>
      ];
    }
    return [];
  }

  // 获取弹窗底部更多按钮
  getDialogFooterMoreBtn = () => {
    if (this.state.selectedKey == 0) {
      return {
        datas: this.getRightMenu(),
        collectParams: []
      }
    };

    return {
      datas: [],
      collectParams: []
    };
  }

  closeEditDialog = () => {
    this.props.todoCenterStore.setState({ ofsInfoEditDetailDialogVisible: false });
    this.setState({ selectedKey: 0, onlyview: 0 });
  }

  closeLogDialog1 = () => {
    this.props.todoCenterStore.setState({ logOfsInfoWorklfowTypeVisible: false })
  }

  closeLogDialog2 = () => {
    this.setState({ logOfWorkflowDatasVisible: false });
  }

  getTabButton = () => {
    const {
      todoCenterStore
    } = this.props, {
      ofsInfoAddForm,
      status
    } = todoCenterStore, {
      rightMenus_ofsInfoWorkflowType = [],
      rowSelectIds_ofsInfoWorkflowType,
      rowSelectIds_ofsInfoWorkflow,
      rightMenus = [],
    } = toJS(status);

    let btnArr = [];
    if (this.state.selectedKey == 1) {
      if (ofsInfoAddForm.getFormParams().editwftype != 1) {
        return btnArr;
      }
      for (let j = 0, len = rightMenus_ofsInfoWorkflowType.length; j < len; j++) {
        if (j == 2) {
          break
        }
        let m = rightMenus_ofsInfoWorkflowType[j];
        let btn = <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@rn2hgu`} type="primary" disabled={m.menuIcon === 'icon-coms-delete' && rowSelectIds_ofsInfoWorkflowType.length === 0} onClick={() => {
          { this.onRightMenuClick(m.type); }
        }}>{`${m.menuName}`}</Button>;
        btnArr.push(btn);
      }
    } else if (this.state.selectedKey == 2) {
      if (ofsInfoAddForm.getFormParams().receivewfdata != 1) {
        let datas = rightMenus.slice(1, rightMenus.length - 1);
        return datas && datas.map(data =>
          <Button
            type="primary"
            disabled={data.type === "rb_2" && rowSelectIds_ofsInfoWorkflow.length === 0}
            onClick={() => this.onRightMenuClick(data.type)}
          >{data.menuName}</Button>
        );
      }
      let datas = rightMenus.slice(0, rightMenus.length - 1);
      return datas && datas.map(data =>
        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@sqevf7@integrationTodoCenterEditDetailButton${data.type}`}
          type="primary"
          disabled={data.type === "rb_2" && rowSelectIds_ofsInfoWorkflow.length === 0}
          onClick={() => this.onRightMenuClick(data.type)}
        >{data.menuName}</Button>
      );
    }
    return btnArr;
  };

  onOperatesClick = (record, index, operate) => {
    const { todoCenterStore } = this.props;
    // const { changeButton, workflowid, Btn, onlyview } = toJS(todoCenterStore.status)
    let sysid = todoCenterStore.status.ofsInfoAddFormHiddenFields.id;
    // const workflowid = record.randomField0;
    todoCenterStore.setState({ workflowid: record.randomField0 })
    if (this.state.selectedKey == 1) {
      if (operate.index == "0") {
        //编辑
        // todoCenterStore.setState({ Btn: [], changeButton: [], onlyview: 0 })
        todoCenterStore.setState({ Btn: [], onlyview: 0 })
        let params = { sysid: sysid, id: record.randomField0, onlyview: todoCenterStore.ofsInfoAddForm.getFormParams().editwftype == 0 ? "1" : "0" };
        todoCenterStore.setState({ operateIndex: record.randomField0 });
        todoCenterStore.getOfsInfoWorkflowTypeEditForm(params);
        todoCenterStore.setState({ ofsInfoEditWorkflowTypeDialogVisible: true });
      }
      if (operate.index == "1") {
        //删除
        todoCenterStore.confirmModal(`${getLabel(15097, '确定要删除吗？')}`, todoCenterStore.getOfsInfoWorkflowTypeOperation, { operation: 'delete', id: record.randomField0, sysid: sysid });
      }
      if (operate.index == "2") {
        //查看
        todoCenterStore.setState({ Btn: [], onlyview: 1 })
        todoCenterStore.setState({ changeButton: [] })
        let params = { sysid: sysid, id: record.randomField0, onlyview: 1 };
        todoCenterStore.setState({ operateIndex: record.randomField0 });
        todoCenterStore.getOfsInfoWorkflowTypeEditForm(params);
        todoCenterStore.setState({ ofsInfoEditWorkflowTypeDialogVisible: true });
      }
      if (operate.index == "3") {
        //日志
        todoCenterStore.setState({ logOfsInfoWorklfowTypeVisible: true });
        this.setState({ targetId: record.randomField0 });
      }
    } else if (this.state.selectedKey == 2) {
      if (operate.index == "0") {
        //查看
        // todoCenterStore.setState({ Btn: [], onlyview: 1 })
        todoCenterStore.getWorkflowViewForm({ id: record.randomField0, isremark: record.isremark });
      } else if (operate.index == "1") {
        todoCenterStore.confirmModal(`${getLabel(15097, '确定要删除吗？')}`, todoCenterStore.getWorkflowOperation, { operation: 'delete', id: `${record.randomField0}_${record.isremark}`, sysid });
      } else if (operate.index == '2') {
        let id = record.randomField0;
        let isremark = record.isremark;
        todoCenterStore.getWorkflowViewFormEdit({ id, sysid, isremark });
        todoCenterStore.setState({ WorkflowViewFormDialogVisible: true, onlyRead: false, operateIndex: id });
      }
    }

  };

  getRowSelection = (flag = 0) => {
    let key = ["rowSelectIds_ofsInfoWorkflowType", "rowSelectIds_ofsInfoWorkflow", "rowSelectIds_ofsInfoLog"][Number(flag)];

    return {
      onChange: selectedRowKeys => this.props.todoCenterStore.setState({ [key]: selectedRowKeys })
    };
  }

  /**
  * 短信提醒
  */
  handleMessageTemplate = () => {
    const {
      todoCenterStore
    } = this.props, {
      ofsInfoAddForm
    } = todoCenterStore;
    todoCenterStore.getSmstemplate(false, { syscode: ofsInfoAddForm.getFormParams().syscode });
    todoCenterStore.setState({ smsTemplateVisible: true });
  }

  getBtns = () => {
    const { todoCenterStore } = this.props;
    const { Notab, changeButton } = toJS(todoCenterStore.status)
    let btns = [];
    btns = [
      <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@7h2zzr@integrationTodoCenterEditDetailButtonSave`} type='primary' onClick={() => todoCenterStore.onRightMenuClick('BTN_SAVE')}>{getLabel(86, '保存')}</Button>
    ];
    todoCenterStore.setState({ changeButton: [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@b9rmgn@integrationTodoCenterEditDetailButtonSaveAndInto`} type='primary' onClick={() => todoCenterStore.onRightMenuClick('BTN_SAVE_INFO')}>{getLabel(529013, '保存并进入创建人范围设置')}</Button>] })
  }

  getColumnsInfo = (column) => {
    const {
      todoCenterStore
    } = this.props, {
      status,
      ofsInfoAddForm,
    } = todoCenterStore, {
      ofsInfoAddFormHiddenFields,
      changeButton,
      workflowid
    } = toJS(status);
    let sysid = ofsInfoAddFormHiddenFields.id;
    if (!isEmpty(column)) {
      if (this.state.selectedKey == 1) {
        for (let i = 0; i < column.length; i++) {
          if (column[i].dbField === 'workflowname') {
            column[i].render = (text, record, index) => {
              return <a onClick={() => {
                todoCenterStore.setState({ workflowid: record.randomField0 })
                let params = { sysid: sysid, id: record.randomField0, onlyview: ofsInfoAddForm.getFormParams().editwftype == 0 ? "1" : "0" };
                todoCenterStore.getOfsInfoWorkflowTypeEditForm(params);
                todoCenterStore.setState({ ofsInfoEditWorkflowTypeDialogVisible: true, operateIndex: record.randomField0, changeButton: [], Notab: false, Btn: [] });
              }}>{record.workflowname}</a>
            }
          }
        }
      } else if (this.state.selectedKey == 2) {
        for (let i = 0; i < column.length; i++) {
          if (column[i].dbField == 'requestname') {
            column[i].render = (text, record, index) => {
              return <a onClick={() => {
                todoCenterStore.getWorkflowViewForm({ id: record.randomField0, isremark: record.isremark, syscode: record.syscode, receiver: record.receiver, flowid: record.flowid });
              }}>{record.requestname}</a>
            }
          } else if (column[i].dbField == 'Creatorid') {
            column[i].render = (text, record, index) => {
              return (<div style={{ display: 'inline' }}><WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@0r4o6o`} /><div dangerouslySetInnerHTML={{ __html: record.Creatoridspan }}></div></div>)
            }
          } else if (column[i].dbField == 'userid') {
            column[i].render = (text, record, index) => {
              return (<div style={{ display: 'inline' }}><WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@tgmd85`} /><div dangerouslySetInnerHTML={{ __html: record.useridspan }}></div></div>)
            }
          }
        }
      } else if (this.state.selectedKey == 3) {
        for (let i = 0; i < column.length; i++) {
          if (column[i].dbField == 'userid') {
            column[i].render = (text, record, index) => {
              return (<div style={{ display: 'inline' }}><WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@j83dkx`} /><div dangerouslySetInnerHTML={{ __html: record.useridspan }}></div></div>)
            }
          } else if (column[i].dbField == 'requestname') {
            column[i].render = (text, record, index) => {
              if (record.operResult == 1 && record.dataType == "WfData") {
                return <a onClick={() => todoCenterStore.getWorkflowViewForm({ id: record.wfdataid, syscode: record.syscode, receiver: record.receiver, flowid: record.flowid }, record.requestname)}>{record.requestname}</a>;
              } else {
                return record.requestname;
              }
            }
          }
        }
      }
    }
  }

  getRightMenu = () => {
    const {
      todoCenterStore
    } = this.props, {
      rightMenus_ofsInfoWorkflowType,
      rowSelectIds_ofsInfoWorkflowType,
      rowSelectIds_ofsInfoWorkflow,
      rightMenus,
    } = toJS(todoCenterStore.status);
    let btnArr = [];
    if (this.state.selectedKey == 0) {
      btnArr = [
        {
          key: 'BTN_SAVE',
          icon: <i className='icon-coms-Preservation' />,
          content: `${getLabel(86, '保存')}`,
          onClick: () => {
            this.onRightMenuClick('BTN_SAVE')
          }
        }
      ];
    } else if (this.state.selectedKey == 1) {
      btnArr = [];
      if (todoCenterStore.ofsInfoAddForm.getFormParams().editwftype == 1) {
        rightMenus_ofsInfoWorkflowType && rightMenus_ofsInfoWorkflowType.map(m => {
          var btn = {
            key: m.type,
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
            onClick: () => this.onRightMenuClick(m.type),
            disabled: (m.menuIcon === 'icon-coms-delete' && rowSelectIds_ofsInfoWorkflowType.length === 0)
          };
          btnArr.push(btn);
        });
      }
    } else if (this.state.selectedKey == 2) {
      if (todoCenterStore.ofsInfoAddForm.getFormParams().receivewfdata == 1) {
        rightMenus && rightMenus.map(m => {
          var btn = {
            key: m.type,
            icon: <i className={m.menuIcon} />,
            content: m.menuName,
            onClick: () => this.onRightMenuClick(m.type),
            disabled: (m.menuIcon === 'icon-coms-delete' && rowSelectIds_ofsInfoWorkflow.length === 0)
          };
          btnArr.push(btn);
        });
      } else {
        let datas=rightMenus.slice(1,rightMenus.length);
        datas&&datas.map((m,index) => {
           var btn= {
             key: m.type,
             icon: <i className={m.menuIcon} />,
             content: m.menuName,
             onClick: () => this.onRightMenuClick(m.type),
             disabled:(m.menuIcon==='icon-coms-delete' && rowSelectIds_ofsInfoWorkflow.length === 0)
           } ;
           btnArr.push(btn);
         });
      }
    }
    if (this.state.selectedKey != '0') {
      btnArr.push({
        key: "BTN_COLUMN",
        icon: <i className="icon-coms-Custom" />,
        content: `${getLabel(32535, "显示列定制")}`,
        onClick: () => this.onRightMenuClick("BTN_COLUMN")
      })
    }

    return btnArr;
  }

  onRightMenuClick = (type) => {
    const { todoCenterStore } = this.props;
    const { ofsInfoAddForm, status, getWorkflowViewFormEdit, saveAndIntoDetail } = todoCenterStore;
    const { rowSelectIds_ofsInfoWorkflowType, rowSelectIds_ofsInfoWorkflow, networkIPData, ofsInfoAddFormHiddenFields, Notab } = toJS(status);
    const formParams = ofsInfoAddForm.getFormParams();
    
    if (['BTN_SAVE', 'BTN_TEST'].includes(type)) {
      // QC1248320、QC1248316 必填项提示的优化
      window.e9HideFormFieldKeys = [];
      if('1' != formParams.iscustom || '1' != formParams.isuse) {
        // 如果 【自定义提醒】 关闭 或者 【启用提醒】 关闭，则 【自定义提醒接口实现类】 非必填
        window.e9HideFormFieldKeys.push('customclass');
      }
      if('1' != formParams.ismonitor) {
        // 如果 【监控】 未开启，则 【被提醒人员】 非必填
        window.e9HideFormFieldKeys.push('reminder');
      }

      IntegrationUtil.onCheck(ofsInfoAddForm, function () {
        let checkParams2 = {
          tableName: 'ofs_sysinfo',
          fieldName: 'sysshortname',
          fieldValue: formParams.sysshortname.replace(/^(\s*)|(\s*)$/g, ''),
          idName: 'sysid',
          idValue: todoCenterStore.status.ofsInfoAddFormHiddenFields.id
        };
        IntegrationUtil.checkUnique(checkParams2, ofsInfoAddForm, "sysshortname", "5", "", () => {
          let checkParams3 = {
            tableName: 'ofs_sysinfo',
            fieldName: 'sysfullname',
            fieldValue: formParams.sysfullname.replace(/^(\s*)|(\s*)$/g, ''),
            idName: 'sysid',
            idValue: todoCenterStore.status.ofsInfoAddFormHiddenFields.id
          };
          IntegrationUtil.checkUnique(checkParams3, ofsInfoAddForm, "sysfullname", "6", "", () => {
            //合并hiddenfield参数
            let id = todoCenterStore.status.ofsInfoAddFormHiddenFields.id;
            let params = Object.assign({}, { id, operation: "edit" }, formParams);
            let httpRegExp = /^http(s){0,1}:\/\/[^\s]*/;
            if (params.pcprefixurl != '') {
              if (!httpRegExp.test(params.pcprefixurl)) {
                message.warning(getLabel('532054', 'PC地址不合法'));
                ofsInfoAddForm.showError('pcprefixurl', getLabel('390458', "前缀需要以http://或https://开头"));
                return;
              }
            }
            if (params.pcouterfixurl != '') {
              if (!httpRegExp.test(params.pcouterfixurl)) {
                message.warning(getLabel('532054', 'PC地址不合法'));
                ofsInfoAddForm.showError('pcouterfixurl', getLabel('390458', "前缀需要以http://或https://开头"));
                return;
              }
            }
            if (params.securityip != '') {
              let vilidflag = 0;
              let regipv4 = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]|(\*))\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]|(\*))\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]|(\*))\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]|(\*))$/;
              function isIPv6 (str) {
                // return str.match(/:/g).length <= 7 && /::/.test(str) ? /^([\da-f]{1,4}(:|::)){1,6}[\da-f]{1,4}$/i.test(str) : /^([\da-f]{1,4}:){7}[\da-f]{1,4}$/i.test(str);
                return str.match(/:/g).length <= 7 && /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/i.test(str);
              }
              let valdata = params.securityip.split(',')
              for (let i = 0; i < valdata.length; i++) {
                if (/\:/ig.test(valdata[i])) {
                  if (isIPv6(valdata[i]) == false) {
                    vilidflag = 1;
                    break;
                  } else {
                    vilidflag = 0;
                  }
                } else {
                  if (regipv4.test(valdata[i]) == true) {
                    vilidflag = 0;
                  } else {
                    vilidflag = 1; break;
                  }
                }
              }

              if (vilidflag == 1) {
                ofsInfoAddForm.showError('securityip', getLabel('531149', "ip格式不合法"));
                message.warning(getLabel('532055', '接口安全ip不合法'));
                return;
              }
            }
            if (params.appprefixurl != '') {
              if (!httpRegExp.test(params.appprefixurl)) {
                ofsInfoAddForm.showError('appprefixurl', getLabel('390458', "前缀需要以http://或https://开头"));
                return;
              }
            }
            params.dtinfo_networkIPData = JSON.stringify(networkIPData);
            if (type === "BTN_SAVE") {
              todoCenterStore.getOfsInfoOperation(params, () => {
                todoCenterStore.setState({ ofsInfoEditDetailDialogVisible: false });
              });
            }
          })
        })
      });
    } else if (type == 'BTN_COLUMN') {
      switch (Number(this.state.selectedKey)) {
        case 1:
          todoCenterStore.tableStore_ofsInfoWorkflowType.setColSetVisible(true);
          todoCenterStore.tableStore_ofsInfoWorkflowType.tableColSet(true);
          break;
        case 2:
          todoCenterStore.tableStore_ofsInfoWorkflow.setColSetVisible(true);
          todoCenterStore.tableStore_ofsInfoWorkflow.tableColSet(true);
          break;
        case 3:
          todoCenterStore.tableStore_ofsInfoLog.setColSetVisible(true);
          todoCenterStore.tableStore_ofsInfoLog.tableColSet(true);
          break;
      }
    }

    if (this.state.selectedKey == 1) {
      if (type == 'rb_1') {
        //注册流程类型
        // this.doDataMappingEditById({ randomField0: '' });
        todoCenterStore.setState({ Notab: true });
        let params = { sysid: todoCenterStore.status.ofsInfoAddFormHiddenFields.id };
        todoCenterStore.setState({ operateIndex: '' });
        todoCenterStore.getOfsInfoWorkflowTypeEditForm(params);
        this.getBtns();
        todoCenterStore.setState({ ofsInfoEditWorkflowTypeDialogVisible: true });
      }
      if (type == 'rb_2') {
        //删除
        if (rowSelectIds_ofsInfoWorkflowType.length > 0) {
          todoCenterStore.confirmModal(`${getLabel(385625, '确定要删除选择的记录吗？')
            } `, todoCenterStore.getOfsInfoWorkflowTypeOperation, { operation: 'delete', id: rowSelectIds_ofsInfoWorkflowType, sysid: todoCenterStore.status.ofsInfoAddFormHiddenFields.id });
        }
      }
      if (type == 'rb_3') {
        todoCenterStore.setState({ logOfsInfoWorklfowTypeVisible: true });
        this.setState({ belongTypeTargetId: todoCenterStore.operateRecordIndex, targetId: '' });
      }
    } else if (this.state.selectedKey == 2) {
      if (type == 'rb_2') {
        //删除
        if (rowSelectIds_ofsInfoWorkflow.length > 0) {
          todoCenterStore.confirmModal(`${getLabel(385625, '确定要删除选择的记录吗？')} `, todoCenterStore.getWorkflowOperation, { operation: 'delete', id: rowSelectIds_ofsInfoWorkflow, sysid: todoCenterStore.status.ofsInfoAddFormHiddenFields.id });
        }
      } else if (type == 'rb_3') {
        this.setState({ logOfWorkflowDatasVisible: true, belongTypeTargetId: todoCenterStore.operateRecordIndex });
      } else if (type == 'rb_1') {
        let id = "";
        getWorkflowViewFormEdit({ id, sysid: ofsInfoAddFormHiddenFields.id, syscode: formParams.syscode });
        todoCenterStore.setState({ WorkflowViewFormDialogVisible: true, onlyRead: false, operateIndex: id });
      }
    }
  }

}
