import React from "react";
import { inject, observer } from "mobx-react";
import { Button,Badge } from "antd";
import { toJS } from "mobx";
import { WeaTableNew} from "comsMobx";
import {
  WeaRightMenu,
  WeaDialog,
  WeaTab,
  WeaLocaleProvider
} from "ecCom";
import * as IntegrationUtil from "../../util/IntegrationUtil";

const getLabel = WeaLocaleProvider.getLabel;
const {WeaTable} = WeaTableNew;

@inject("workflowFlowStore")
@observer
export default class RegisterRunList extends React.Component {
    constructor (props) {
        super(props);
        this.state = {}
    }

    componentWillUnmount() {
      const {workflowFlowStore} = this.props;
      workflowFlowStore.setState({
        showSearchAd2: false
      })
    }

    getRunLogDialogRightMenu() {
      const {workflowFlowStore} = this.props;
      return [
        {
        key: 'BTN_SAVE',
        icon: <i className='icon-coms-go-back'/>,
        content : `${getLabel(309,'关闭')}`,
        onClick : () => {workflowFlowStore.setState({logRunListVisible:false})}
        }
      ];
    }

    getAdvancedSearch = () => {
      const {workflowFlowStore} = this.props;
      const {
        searchFormRunList,
        status
      } = workflowFlowStore;
      let {
        searchFormRunListCondition,
      } = toJS(status);

      return IntegrationUtil.getAdvancedItem(
        searchFormRunList,
        searchFormRunListCondition,
        this.getSearchFun,
        false,
        this && this.props && this.props.ecId || '', 
        "integrationWorkflowflowRunList",
      );
    };

    getTabButtonsAd() {
      const {workflowFlowStore} = this.props;
  
      return IntegrationUtil.getSearchBtns(
        this.getSearchFun, 
        () => {
          workflowFlowStore.searchFormRunList.reset();
          workflowFlowStore.searchFormRunList.updateFields({
            timeSag: "7"
          })
        }, 
        () => workflowFlowStore.setState({showSearchAd2: false}),
        this && this.props && this.props.ecId || '', 
        "integrationWorkflowflowRunList",
      );
    }

    getSearchFun = () => {
      const {workflowFlowStore} = this.props;
      const {status: {operateClickIndex}} = workflowFlowStore;

      workflowFlowStore.getInterfaceRegisterRunLogList({actiondbid: operateClickIndex});
      workflowFlowStore.setState({showSearchAd2: false});
    } 

    closeDialog = () => {
      const {workflowFlowStore} = this.props;
      workflowFlowStore.setState({
        logRunListVisible: false,
        showSearchAd2: false
      })  
    }

    render() {
        const {workflowFlowStore} = this.props;
        const {
            searchFormRunList,
            status,
            logRunListStore,
        } = workflowFlowStore;
        const {
            showSearchAd2,
            advancedSearchHeight,
            logRunListVisible,
        } = toJS(status);

        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@4clyv0`}
                title={getLabel( '131274' ,'运行日志')}
                moduleName="integration"
                visible={logRunListVisible}
                hasScroll={true}
                style={{width: 900, height: 650}}
                onCancel={this.closeDialog}
                buttons={[
                  <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@rwe6dq@integrationWorkflowRunListButtonClose`} type="primary" onClick={this.closeDialog}>{getLabel('309', '关闭')}</Button>
                ]}
                moreBtn={{
                  datas : this.getRunLogDialogRightMenu(),
                  collectParams: []
                }}
            >
              <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@mxevq0`}
                datas={this.getRunLogDialogRightMenu()}
                collectParams={[]}
              >
                <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@kvrtjj`}
                    datas={[]}
                    keyParam="viewcondition_dtt" //主键
                    searchType={['base','advanced']}
                    searchsBaseValue={searchFormRunList.getFormParams().actionshowname}
                    advanceHeight={advancedSearchHeight}
                    searchsAd={this.getAdvancedSearch()}
                    showSearchAd={showSearchAd2}
                    buttonsAd={this.getTabButtonsAd()}
                    setShowSearchAd={(bool) => workflowFlowStore.setState({ showSearchAd2: bool })}
                    hideSearchAd={() => workflowFlowStore.setState({ showSearchAd2: false })}
                    onSearch={this.getSearchFun}
                    onSearchChange={value => searchFormRunList.updateFields({actionshowname: value})}
                />
                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@tgfjhm`}
                    comsWeaTableStore={logRunListStore}
                    hasOrder={true}
                    needScroll={true}
                />
              </WeaRightMenu>
            </WeaDialog>
        )
    }
}
