UNPKG

@beisen-phoenix/lookup

Version:

---

224 lines (186 loc) 6.92 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var React = _interopRequireWildcard(require("react")); var _index = _interopRequireDefault(require("./components/simpleList/index")); var _index2 = _interopRequireDefault(require("./components/advancedCmpt/index")); var _modal = _interopRequireDefault(require("@beisen-phoenix/modal")); var _util = require("./util.js"); var _isEmpty = _interopRequireDefault(require("lodash/isEmpty")); var Lookup = /*#__PURE__*/ function (_React$Component) { (0, _inherits2.default)(Lookup, _React$Component); // 默认配置 function Lookup(props) { var _this; (0, _classCallCheck2.default)(this, Lookup); _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Lookup).call(this, props)); _this.modalRef = React.createRef(); _this.advancedRef = React.createRef(); _this.onSearchAllClick = function (selectValue) { var advanceParam = _this.props.advanceParam; if (advanceParam) { _this.setState({ mode: 'advanced', advancedModalVbl: true, selectValue: selectValue }); } }; _this.renderSimpleList = function () { var _this$props = _this.props, isSearchBox = _this$props.isSearchBox, isAvator = _this$props.isAvator, multiple = _this$props.multiple, isAdvanceSearchVbl = _this$props.isAdvanceSearchVbl, options = _this$props.options, selectValue = _this$props.selectValue, onConfirm = _this$props.onConfirm, onSearchChange = _this$props.onSearchChange, formatData = _this$props.formatData, searchUrl = _this$props.searchUrl, autoFocus = _this$props.autoFocus, translation = _this$props.translation; return React.createElement(_index.default, { isSearchBox: isSearchBox, isAvator: isAvator, multiple: multiple, isAdvanceVbl: isAdvanceSearchVbl, options: options, selectValue: selectValue, onSearchAllClick: _this.onSearchAllClick, onSearchChange: onSearchChange, formatData: formatData, searchUrl: searchUrl, autoFocus: autoFocus, translation: translation, onOk: onConfirm }); }; _this.handleClose = function () { var _this$props2 = _this.props, onVisibleChange = _this$props2.onVisibleChange, mode = _this$props2.mode; if (onVisibleChange) { onVisibleChange(false); } _this.setState({ mode: mode, advancedModalVbl: false }); }; _this.handleCancel = function () { var _this$props3 = _this.props, onCancel = _this$props3.onCancel, mode = _this$props3.mode; if (onCancel) { onCancel(null); } _this.setState({ mode: mode, advancedModalVbl: false }); }; _this.handleAdvancedConfirm = function () { var _this$props4 = _this.props, onConfirm = _this$props4.onConfirm, mode = _this$props4.mode; if (onConfirm) { var data = _this.advancedRef.current.getSelected(); onConfirm(data); } _this.setState({ mode: mode, advancedModalVbl: false }); }; _this.getContainer = function () { return _this.modalRef.current; }; _this.renderAdvancedSelect = function () { var _this$props5 = _this.props, advanceParam = _this$props5.advanceParam, moreText = _this$props5.moreText, advancedVbl = _this$props5.advancedVbl, multiple = _this$props5.multiple, translation = _this$props5.translation; var _this$state = _this.state, advancedModalVbl = _this$state.advancedModalVbl, selectValue = _this$state.selectValue; return React.createElement(_modal.default, { ref: _this.modalRef, extraCls: "lookupAdvance", title: advanceParam && advanceParam.dlgTitle || moreText, visible: advancedVbl || advancedModalVbl, size: advanceParam && advanceParam.modalSize || 'large', height: advanceParam && advanceParam.modalHeight || '90%' //style={{height: advanceParam && advanceParam.modalHeight || '90%'} , escClosable: true, maskerClosable: false, onClose: _this.handleClose, onCancel: _this.handleCancel, onConfirm: _this.handleAdvancedConfirm, translation: translation }, React.createElement(_index2.default, (0, _extends2.default)({ ref: _this.advancedRef, multiple: multiple, modalHeight: advanceParam && advanceParam.modalHeight //getContainer={this.getContainer} }, advanceParam, { selectValue: selectValue }))); }; _this.state = { options: props.options, mode: props.mode, advancedModalVbl: props.advancedModalVbl || false, selectValue: [] }; return _this; } (0, _createClass2.default)(Lookup, [{ key: "componentDidUpdate", value: function componentDidUpdate(prevProps, prevState, snapshot) { var prop = (0, _util.getUpdateData)(['selectValue', 'options', 'mode'], this.props, prevProps); if (!(0, _isEmpty.default)(prop)) { this.setState(prop); } } }, { key: "render", value: function render() { var customCls = this.props.customCls; var mode = this.state.mode; return React.createElement("div", { className: 'phoenix-lookup ' + (customCls ? customCls : '') }, mode === 'simple' && this.renderSimpleList() || this.renderAdvancedSelect()); } }]); return Lookup; }(React.Component); exports.default = Lookup; Lookup.defaultProps = { mode: 'simple', multiple: false, autoFocus: true, translation: { clearSelected: "清空已选", selected: "已选", emptyMsg: "请在左侧选择内容", moreText: '全部查找', noDataText: '这里什么都没有', btnOkText: '确定', confirmText: '确定', cancelText: '取消' } };