import React, { Component } from 'react';
import { Icon } from 'antd-mobile';
import './Header.scss';

export default class Header extends Component {
  constructor(props) {
    super(props);
    this.state = {
      backIconFlag: this.props.backIconFlag ? this.props.backIconFlag : 'true',
    };
    window.back = this.goBack;
    window.backFunc = this.goBack.bind(this);
  }
  componentWillReceiveProps(nextProps) {
    !!nextProps.backIconFlag && this.setState({
      backIconFlag: nextProps.backIconFlag,
    });
  }
  goBack() {
    const backto = this.props.back;
    if (this.props.backFunc) {
      this.props.backFunc();
    } else if (backto === 'gtja') {
      this.goBackJh();
    } else {
      history.back();
    }
  }
  // 返回君弘
  goBackJh() {
    window.location.href = 'gtjanormal://goback';
  }
  render() {
    return (
      <div className="app_menu">
        {this.state.backIconFlag === 'true' &&
        <Icon type="left" color="#309fea" size="lg" onClick={this.goBack.bind(this)} />}
        {this.props.children}
      </div>
    );
  }
}
