UNPKG

yyuap-ref

Version:

cloud os fe ref project which is based on tinper

130 lines (107 loc) 4.7 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _formControl = require('../../bee/form-control'); var _formControl2 = _interopRequireDefault(_formControl); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var RefSearch = function (_Component) { _inherits(RefSearch, _Component); function RefSearch(props) { _classCallCheck(this, RefSearch); var _this = _possibleConstructorReturn(this, (RefSearch.__proto__ || Object.getPrototypeOf(RefSearch)).call(this, props)); _this.onChange = function (value) { _this.setState({ value: value }); if (_this.props.onChange) { _this.props.onChange(encodeURI(value)); } }; _this.onClear = function () { _this.setState({ value: '' }); if (_this.props.onChange) { _this.props.onChange(''); } }; _this.keypress = function (e) { if (e.which !== 13) return; _this.onSearch(); }; _this.onSearch = function (value) { value = _this.state.value; console.log("搜索" + value); if (_this.props.onSearch) { _this.props.onSearch(encodeURI(value)); } else if (_this.props.url) { //发请求 //请求回来了 _this.props.onGetSearchResult(data); } }; _this.state = { value: "" }; return _this; } _createClass(RefSearch, [{ key: 'render', value: function render() { var _props = this.props, language = _props.language, searchPlaceholder = _props.searchPlaceholder; var searchtext = "编码/名称"; switch (language) { case "zh_CN": searchtext = '编码/名称'; break; case "en_US": searchtext = 'Code/name'; break; case "zh_TW": searchtext = '編碼/名稱'; break; case "fr_FR": searchtext = 'Codage/nom'; break; case "de_DE": searchtext = 'Code/Name'; break; case "ja_JP": searchtext = 'コード/名前'; break; default: searchtext = '编码/名称'; } return _react2.default.createElement( 'div', { className: 'Ref-Search' }, _react2.default.createElement(_formControl2.default, { className: 'Search-input', value: this.state.value, onChange: this.onChange, onKeyPress: this.keypress, placeholder: searchPlaceholder || searchtext, type: 'text' }), _react2.default.createElement( 'div', null, _react2.default.createElement('i', { className: 'uf uf-search search-input-que', onClick: this.onSearch.bind(this) }) ), this.state.value !== '' && _react2.default.createElement( 'div', null, _react2.default.createElement('i', { className: 'uf uf-close-c', onClick: this.onClear.bind(this) }) ) ); } }]); return RefSearch; }(_react.Component); exports.default = RefSearch; module.exports = exports['default'];