1 | import "core-js/modules/es6.regexp.split";
|
2 | import "core-js/modules/es6.string.small";
|
3 | import "core-js/modules/es6.object.assign";
|
4 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
5 | import _createClass from "@babel/runtime/helpers/createClass";
|
6 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
7 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
8 | import _inherits from "@babel/runtime/helpers/inherits";
|
9 | import React, { Component, PropTypes } from 'react';
|
10 | import { render } from 'react-dom';
|
11 | import Loading from '@beisen-platform/loading';
|
12 | import { decode } from '@beisen-platform/common-func';
|
13 |
|
14 | function empty() {}
|
15 |
|
16 | var List =
|
17 |
|
18 | function (_Component) {
|
19 | _inherits(List, _Component);
|
20 |
|
21 | function List(props) {
|
22 | var _this;
|
23 |
|
24 | _classCallCheck(this, List);
|
25 |
|
26 | _this = _possibleConstructorReturn(this, _getPrototypeOf(List).call(this, props));
|
27 |
|
28 | _this.handlerScroll = function (e) {
|
29 | var scrollHeight = e.target.scrollHeight;
|
30 | var clientHeight = e.target.clientHeight;
|
31 | var scrollTop = e.target.scrollTop;
|
32 | var footerDom = _this.refs.lookupFooter;
|
33 |
|
34 | if (clientHeight + scrollTop >= scrollHeight) {
|
35 | footerDom.style.borderTop = "1px solid #ffffff";
|
36 | } else {
|
37 | footerDom.style.borderTop = "1px solid #e4ebf0";
|
38 | }
|
39 | };
|
40 |
|
41 | _this.handlerClick = function () {
|
42 | if (!_this.props.multiple) {
|
43 | _this.props.setComState('isShowDoropList', false);
|
44 |
|
45 | _this.props.commonMount.unmountBox();
|
46 | }
|
47 | };
|
48 |
|
49 | _this.handlerFindAll = function (event) {
|
50 | _this.props.setComState('isShowDoropList', false);
|
51 |
|
52 | _this.props.handlerFindAll();
|
53 | };
|
54 |
|
55 | _this.state = {
|
56 | fetchingFlag: false
|
57 | };
|
58 | return _this;
|
59 | }
|
60 |
|
61 | _createClass(List, [{
|
62 | key: "componentWillReceiveProps",
|
63 | value: function componentWillReceiveProps(nextProps) {
|
64 | if (!nextProps.isFetching) {
|
65 | this.setState({
|
66 | fetchingFlag: false
|
67 | });
|
68 | }
|
69 | }
|
70 | }, {
|
71 | key: "componentDidUpdate",
|
72 | value: function componentDidUpdate(prevProps, prevState) {
|
73 | if (this.refs.selectList && this.refs.selectList.clientHeight > 300) {
|
74 | this.refs.lookupFooter.style.borderTop = "1px solid #e4ebf0";
|
75 | }
|
76 | }
|
77 | }, {
|
78 | key: "render",
|
79 | value: function render() {
|
80 | var _this2 = this;
|
81 |
|
82 | var props = Object.assign({}, this.props);
|
83 | var fetchingFlag = this.state.fetchingFlag;
|
84 |
|
85 | if (props.isNotAllow || props.isNotInstall) {
|
86 | var fetchHeight = props.status == 'search' ? 320 : 360;
|
87 | var notClass = props.isNotAllow ? 'BS_lookupV2__not-allow' : '';
|
88 | notClass = props.isNotInstall ? 'BS_lookupV2__not-install' : notClass;
|
89 | return React.createElement("div", {
|
90 | className: "BS_lookupV2__mountContainer",
|
91 | style: {
|
92 | height: fetchHeight
|
93 | }
|
94 | }, React.createElement("div", {
|
95 | className: "BS_lookupV2__not-allow-wrapper"
|
96 | }, React.createElement("div", {
|
97 | className: notClass
|
98 | })));
|
99 | }
|
100 |
|
101 | var _containerClass = " BS_lookupV2__mountContainer_data-null",
|
102 | findAllText = "全部查找",
|
103 | footerShadow = {};
|
104 |
|
105 | if (Array.isArray(props.listValue)) {
|
106 | _containerClass = props.listValue.length ? '' : fetchingFlag ? '' : ' BS_lookupV2__mountContainer_no-data';
|
107 | findAllText = props.listValue.length ? "全部查找" : fetchingFlag ? "全部查找" : "“全部查找”";
|
108 | footerShadow = props.listValue.length > 8 ? {
|
109 | borderTop: "1px solid #e4ebf0"
|
110 | } : {};
|
111 | }
|
112 |
|
113 | footerShadow = fetchingFlag ? {
|
114 | position: 'absolute',
|
115 | bottom: 0,
|
116 | right: 0
|
117 | } : {};
|
118 | var loadingstyle, mountContainer;
|
119 | loadingstyle = props.isShowFindAll ? {
|
120 | height: '90%'
|
121 | } : {};
|
122 | mountContainer = fetchingFlag ? props.status == 'search' ? {
|
123 | height: 320
|
124 | } : {
|
125 | height: 360
|
126 | } : {};
|
127 | return React.createElement("div", {
|
128 | className: "BS_lookupV2__mountContainer" + _containerClass,
|
129 | style: mountContainer
|
130 | }, fetchingFlag ? React.createElement(Loading, {
|
131 | type: "small",
|
132 | style: loadingstyle
|
133 | }) : Array.isArray(props.listValue) && props.listValue.length ? React.createElement("div", {
|
134 | onScroll: this.handlerScroll,
|
135 | style: {
|
136 | maxHeight: '300px'
|
137 | }
|
138 | }, React.createElement("ul", {
|
139 | className: "lookupv2__select-list",
|
140 | ref: "selectList"
|
141 | }, props.listValue.map(function (item, index) {
|
142 | return React.createElement(ListItem, {
|
143 | key: index,
|
144 | value: props.value,
|
145 | data: item,
|
146 | listClick: props.listClick,
|
147 | handlerClick: _this2.handlerClick
|
148 | });
|
149 | }))) : null, React.createElement("div", {
|
150 | className: "lookupv2__footer",
|
151 | ref: "lookupFooter",
|
152 | style: footerShadow
|
153 | }, Array.isArray(props.listValue) && !props.listValue.length && !fetchingFlag ? React.createElement("div", {
|
154 | className: "lookupv2__empty-data"
|
155 | }) : null, props.isShowFindAll && !fetchingFlag ? React.createElement("p", {
|
156 | className: "lookupv2__findAll",
|
157 | onClick: this.handlerFindAll
|
158 | }, findAllText) : null));
|
159 | }
|
160 | }]);
|
161 |
|
162 | return List;
|
163 | }(Component);
|
164 |
|
165 | List.defaultProps = {
|
166 | isFetching: false,
|
167 | isNotAllow: false,
|
168 | isNotInstall: false,
|
169 | isShowFindAll: true,
|
170 | onFindAll: empty,
|
171 | listClick: empty,
|
172 | listHeight: 0
|
173 | };
|
174 | export { List as default };
|
175 |
|
176 | var ListItem =
|
177 |
|
178 | function (_Component2) {
|
179 | _inherits(ListItem, _Component2);
|
180 |
|
181 | function ListItem(props) {
|
182 | var _this3;
|
183 |
|
184 | _classCallCheck(this, ListItem);
|
185 |
|
186 | _this3 = _possibleConstructorReturn(this, _getPrototypeOf(ListItem).call(this, props));
|
187 |
|
188 | _this3.highlightText = function (text) {
|
189 | var obj = {
|
190 | a: null,
|
191 | b: null,
|
192 | c: text
|
193 | };
|
194 | var index = text && text.indexOf(_this3.props.value);
|
195 | var highlightLength = _this3.props.value.length;
|
196 |
|
197 | if (index == 0) {
|
198 | var subValue = text.substring(index, highlightLength);
|
199 | obj['b'] = React.createElement("em", null, subValue);
|
200 | obj['c'] = text.substring(highlightLength, text.length);
|
201 | } else if (index > 0) {
|
202 | obj['a'] = text.substring(0, index);
|
203 |
|
204 | var _subValue = text.substring(index, highlightLength + index);
|
205 |
|
206 | obj['b'] = React.createElement("em", null, _subValue);
|
207 | obj['c'] = text.substring(highlightLength + index, text.length);
|
208 | }
|
209 |
|
210 | return {
|
211 | a: obj['a'],
|
212 | b: obj['b'],
|
213 | c: obj['c']
|
214 | };
|
215 | };
|
216 |
|
217 | _this3.handlerClick = function (event) {
|
218 | _this3.props.handlerClick();
|
219 |
|
220 | _this3.props.listClick(event, _this3.props.data);
|
221 | };
|
222 |
|
223 | _this3.renderContent = function () {
|
224 | var text1 = decode(_this3.props.data[0]['text']);
|
225 |
|
226 | var _objText_1 = _this3.highlightText(text1);
|
227 |
|
228 | if (_this3.props.data.length == 1) {
|
229 | return React.createElement("div", {
|
230 | className: "lookupv2__content-wrapper"
|
231 | }, React.createElement("p", {
|
232 | className: "lookupv2__content-top"
|
233 | }, _objText_1['a'], _objText_1['b'], _objText_1['c']));
|
234 | } else {
|
235 | var text2 = decode(_this3.props.data[1]['text']);
|
236 |
|
237 | var _objText_2 = _this3.highlightText(text2);
|
238 |
|
239 | return React.createElement("div", {
|
240 | className: "lookupv2__content-wrapper"
|
241 | }, React.createElement("p", {
|
242 | className: "lookupv2__content-top"
|
243 | }, _objText_1['a'], _objText_1['b'], _objText_1['c']), React.createElement("p", {
|
244 | className: "lookupv2__content-bottom"
|
245 | }, _objText_2['a'], _objText_2['b'], _objText_2['c']));
|
246 | }
|
247 | };
|
248 |
|
249 | return _this3;
|
250 | }
|
251 |
|
252 | _createClass(ListItem, [{
|
253 | key: "render",
|
254 | value: function render() {
|
255 | var props = Object.assign({}, this.props);
|
256 |
|
257 | var _avatarDom;
|
258 |
|
259 | for (var i = 0; i < 2; i++) {
|
260 | if (props.data[i] && props.data[i]['avatars']) {
|
261 | for (var j in props.data[i]['avatars']) {
|
262 | if (props.data[i]['avatars'][j]['hasAvatar']) {
|
263 | _avatarDom = React.createElement("span", {
|
264 | className: "avatar avatar_size-30"
|
265 | }, React.createElement("img", {
|
266 | src: props.data[i]['avatars'][j]['small']
|
267 | }));
|
268 | } else {
|
269 | _avatarDom = React.createElement("span", {
|
270 | className: "avatar avatar_size-30",
|
271 | style: {
|
272 | backgroundColor: props.data[i]['avatars'][j]['color']
|
273 | }
|
274 | }, props.data[i]['text'].split("")[0]);
|
275 | }
|
276 | }
|
277 | }
|
278 | }
|
279 |
|
280 | return React.createElement("li", {
|
281 | className: "lookupv2__drop-item lookupv2__drop-item_has-avatar",
|
282 | onClick: this.handlerClick
|
283 | }, _avatarDom, this.renderContent());
|
284 | }
|
285 | }]);
|
286 |
|
287 | return ListItem;
|
288 | }(Component); |
\ | No newline at end of file |