'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports['default'] = undefined;

var _modal = require('choerodon-hap-ui/lib/modal');

var _modal2 = _interopRequireDefault(_modal);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

require('choerodon-hap-ui/lib/modal/style');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _common = require('../../common');

require('./style');

var _backage2x = require('./style/backage@2x.png');

var _backage2x2 = _interopRequireDefault(_backage2x);

var _data2x = require('./style/data@2x.png');

var _data2x2 = _interopRequireDefault(_data2x);

var _call2x = require('./style/call@2x.png');

var _call2x2 = _interopRequireDefault(_call2x);

var _pay2x = require('./style/pay@2x.png');

var _pay2x2 = _interopRequireDefault(_pay2x);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var Home = function (_Component) {
  (0, _inherits3['default'])(Home, _Component);

  function Home(props) {
    (0, _classCallCheck3['default'])(this, Home);

    var _this = (0, _possibleConstructorReturn3['default'])(this, (Home.__proto__ || Object.getPrototypeOf(Home)).call(this, props));

    _this.onChangeSearch = function (event) {
      _this.setState({
        keyword: event.target.value
      });
    };

    _this.searchList = function (type) {
      var pathName = '';
      if (_this.state.keyword) {
        if (type === 'qixin') {
          pathName = '#/hap-core/qixin';
        } else if (type === 'fenbao') {
          pathName = '#/hap-core/risk-search';
        } else if (type === 'dianhua') {
          pathName = '#/hap-core/dian-hua';
        } else {
          _modal2['default'].warning('敬请期待');
          return;
        }
        /* this.props.history.push({
          pathname: pathName,
        }); */
        window.open(pathName, '_blank');
        window.localStorage.setItem('keyword', _this.state.keyword);
      } else {
        _modal2['default'].warning('请先输入关键字');
      }
    };

    _this.showFunction = function () {
      if (_this.state.keyword) {
        _this.setState({
          showFlag: true
        });
      } else {
        _modal2['default'].warning('请先输入关键字');
        _this.setState({
          showFlag: false
        });
      }
    };

    _this.state = {
      keyword: '',
      showFlag: false
    };
    return _this;
  }

  (0, _createClass3['default'])(Home, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      var pathName = '';
      var keyword = (0, _common.getCookie)('keyword');
      var type = (0, _common.getCookie)('type');
      if (keyword && type) {
        if (type === 'qixin') {
          pathName = '#/hap-core/qixin';
        } else if (type === 'fenbao') {
          pathName = '#/hap-core/risk-search';
        } else if (type === 'dianhua') {
          pathName = '#/hap-core/dian-hua';
        }
        if (type !== 'pay') {
          /* this.props.history.push({
            pathname: pathName,
          }); */
          window.open(pathName, '_blank');
        }
        window.localStorage.setItem('keyword', keyword);
        window.localStorage.setItem('type', type);
        (0, _common.removeCookie)('keyword');
        (0, _common.removeCookie)('type');
      }
    }
  }, {
    key: 'functionComponent',
    value: function functionComponent() {
      var _this2 = this;

      return _react2['default'].createElement(
        'div',
        { className: 'function', id: 'function' },
        _react2['default'].createElement(
          'div',
          { className: 'list' },
          _react2['default'].createElement('img', { src: _data2x2['default'], alt: '' }),
          _react2['default'].createElement(
            'div',
            { className: 'item', onClick: function onClick() {
                return _this2.searchList('qixin');
              } },
            '\u4F01\u4FE1\u5B9D'
          ),
          _react2['default'].createElement(
            'div',
            { className: 'item', onClick: function onClick() {
                return _this2.searchList('fenbao');
              } },
            '\u98CE\u62A5'
          )
        ),
        _react2['default'].createElement(
          'div',
          { className: 'list' },
          _react2['default'].createElement('img', { src: _call2x2['default'], alt: '' }),
          _react2['default'].createElement(
            'div',
            { className: 'item', onClick: function onClick() {
                return _this2.searchList('dianhua');
              } },
            '\u7535\u8BDD\u90A6'
          )
        ),
        _react2['default'].createElement(
          'div',
          { className: 'list' },
          _react2['default'].createElement('img', { src: _pay2x2['default'], alt: '' }),
          _react2['default'].createElement(
            'div',
            { className: 'item', onClick: function onClick() {
                return _this2.searchList('pay');
              } },
            '\u94F6\u8054'
          )
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      var _this3 = this;

      return _react2['default'].createElement(
        'div',
        { className: 'choerodon-home' },
        _react2['default'].createElement(
          'div',
          { className: 'choerodon-home-content' },
          _react2['default'].createElement('img', { src: _backage2x2['default'], alt: '' })
        ),
        _react2['default'].createElement(
          'div',
          { className: 'search-box' },
          _react2['default'].createElement(
            'div',
            { className: 'search' },
            _react2['default'].createElement('input', { placeholder: '\u8BF7\u8F93\u5165\u5173\u952E\u5B57', onChange: this.onChangeSearch, name: 'searchKey', value: this.state.keyword }),
            _react2['default'].createElement(
              'div',
              { className: 'search-button', onClick: function onClick() {
                  return _this3.showFunction();
                } },
              '\u641C\u7D22'
            )
          )
        ),
        this.state.showFlag ? this.functionComponent() : null
      );
    }
  }]);
  return Home;
}(_react.Component);

exports['default'] = Home;