1 | import "core-js/modules/es6.object.assign";
|
2 | import "core-js/modules/es7.array.includes";
|
3 | import "core-js/modules/es6.string.includes";
|
4 | import _extends from "@babel/runtime/helpers/extends";
|
5 | import "core-js/modules/es6.function.name";
|
6 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
7 | import _createClass from "@babel/runtime/helpers/createClass";
|
8 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
9 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
10 | import _inherits from "@babel/runtime/helpers/inherits";
|
11 | import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
12 | import React, { Component } from 'react';
|
13 | import ReactDom, { findDOMNode } from 'react-dom';
|
14 | import './index.css';
|
15 | import Tree from '@beisen-platform/tree';
|
16 | import CommonMount from '@beisen-platform/common-mount';
|
17 | import debounce from '@beisen/es6-promise-debounce';
|
18 | import { getSearchData, getCommonInputData, getHightLightData, setRealNode, getSysVersion, setMaskStyle, renderAutoUl, pushLi, getElByClass, renderTree } from './constant';
|
19 | import SearchFilters from './search_Filters.js';
|
20 | import AutoFormInput from './autoForm_Input.js';
|
21 | import FindAllpop from './FindAll_pop.js';
|
22 | import Loading from '@beisen-platform/loading';
|
23 | import Search from '@beisen-platform/search';
|
24 | import Tip from "@beisen-platform/platform-tip";
|
25 | import CommonLabel from '@beisen-platform/common-label';
|
26 | var offset = {};
|
27 | window.autoId;
|
28 |
|
29 | var AutoTree =
|
30 |
|
31 | function (_Component) {
|
32 | _inherits(AutoTree, _Component);
|
33 |
|
34 | function AutoTree(props) {
|
35 | var _this;
|
36 |
|
37 | _classCallCheck(this, AutoTree);
|
38 |
|
39 | _this = _possibleConstructorReturn(this, _getPrototypeOf(AutoTree).call(this, props));
|
40 |
|
41 | _this.returnAutoLi = function (bool) {
|
42 | var _this$state = _this.state,
|
43 | index = _this$state.index,
|
44 | isFocus = _this$state.isFocus,
|
45 | inputValue = _this$state.inputValue,
|
46 | searchValue = _this$state.searchValue,
|
47 | showTree = _this$state.showTree,
|
48 | autoTreeItems = _this$state.autoTreeItems,
|
49 | hasClick = _this$state.hasClick;
|
50 | var _this$props = _this.props,
|
51 | autoTreeData = _this$props.autoTreeData,
|
52 | componentId = _this$props.componentId,
|
53 | sync = _this$props.sync,
|
54 | sideTip = _this$props.sideTip,
|
55 | hiddenTip = _this$props.hiddenTip,
|
56 | single = _this$props.single,
|
57 | status = _this$props.status;
|
58 |
|
59 | var sessionData = _this.getSessionData(componentId);
|
60 |
|
61 | var dataResult = sync ? autoTreeItems : autoTreeData;
|
62 |
|
63 | if (dataResult != undefined && dataResult.length != 0) {
|
64 | _this.renderParents_Node = dataResult[0].pname == undefined ? false : true;
|
65 | }
|
66 |
|
67 | var itemClass = _this.renderParents_Node ? "auto-tree__item " : "auto-tree__item_notShow ";
|
68 | var ifbool = dataResult == undefined || dataResult.length == 0 && isFocus == true && sessionData != null && sessionData.length > 0;
|
69 | var autoLi = [];
|
70 | if (bool) ifbool = (dataResult == undefined || dataResult.length == 0) && !single && isFocus == true && sessionData != null && sessionData.length > 0 && hasClick == true || inputValue == '' && isFocus == true && sessionData != null && !single && sessionData.length > 0 && hasClick == false;
|
71 |
|
72 | if (ifbool) {
|
73 | for (var i = 0; i < sessionData.length; i++) {
|
74 | var holdon_class = i == index ? 'li-hold-on' : '';
|
75 | pushLi(autoLi, itemClass, holdon_class, i, sessionData[i].id, sessionData[i].name, sideTip, hiddenTip, -1, {}, {}, {}, _this.renderParents_Node, sessionData[i].pname, _this.props);
|
76 | }
|
77 | } else if (dataResult != undefined) {
|
78 |
|
79 | var searchInputValue = status == 'search' ? searchValue : single ? inputValue : showTree ? searchValue : inputValue;
|
80 |
|
81 | for (var _i = 0; _i < dataResult.length; _i++) {
|
82 | autoLi = getHightLightData(index, dataResult[_i], searchInputValue, autoLi, _i, _this.renderParents_Node, sideTip, hiddenTip, _this.props);
|
83 | }
|
84 | }
|
85 |
|
86 | _this.autoLi = autoLi;
|
87 | return autoLi;
|
88 | };
|
89 |
|
90 | _this.clearResultsData = function (index) {
|
91 | var _resultsData = _this.state.resultsData;
|
92 | var _hasCount = _this.state.hasCount;
|
93 | if (_hasCount == 0) return;
|
94 |
|
95 | if (index == undefined) {
|
96 | var _tempArr = _this._tempClosed.concat(_resultsData);
|
97 |
|
98 | _this._tempClosed = _tempArr;
|
99 | _resultsData.length = 0;
|
100 | _hasCount = 0;
|
101 | } else {
|
102 | _this._tempClosed.push(_resultsData[index]);
|
103 |
|
104 | _resultsData.splice(index, 1);
|
105 |
|
106 | _hasCount = _hasCount - 1;
|
107 | }
|
108 |
|
109 | _this.setState({
|
110 | resultsData: _resultsData,
|
111 | hasCount: _hasCount
|
112 | });
|
113 | };
|
114 |
|
115 | _this.handlerOver = function (event) {
|
116 | var dom = findDOMNode(_this.refs.autoForm_ref.refs.mouseIconClose);
|
117 |
|
118 | if (dom && dom.style.display == 'block' || _this.state.isFocus || !_this.state.inputValue || _this.props.disabled) {
|
119 | return;
|
120 | } else {
|
121 | _this.setState({
|
122 | isShowMouseOverIcon: true
|
123 | });
|
124 | }
|
125 | };
|
126 |
|
127 | _this.handlerOut = function (event) {
|
128 | var node = event.target;
|
129 |
|
130 | if (node && node.nodeName.toLowerCase() == 'span' || _this.props.disabled) {
|
131 | return;
|
132 | } else {
|
133 | _this.setState({
|
134 | isShowMouseOverIcon: false
|
135 | });
|
136 | }
|
137 | };
|
138 |
|
139 | _this.findAll_submit = function () {
|
140 | var _this$props2 = _this.props,
|
141 | treeData = _this$props2.treeData,
|
142 | submitCallBack = _this$props2.submitCallBack;
|
143 |
|
144 | _this.unmountMask();
|
145 |
|
146 | if (_this.state.resultsData.length === 0) {
|
147 | _this.setState({
|
148 | searchValue: '',
|
149 | defaultPlaceholder: '请选择'
|
150 | });
|
151 |
|
152 | } else {
|
153 | _this.setState({
|
154 | searchValue: '',
|
155 | defaultPlaceholder: ''
|
156 | });
|
157 |
|
158 | }
|
159 |
|
160 |
|
161 | _this._tempSeleted = [];
|
162 | _this._tempClosed = [];
|
163 | treeData.clearTreeData && treeData.clearTreeData();
|
164 | submitCallBack && submitCallBack(_this.state.resultsData);
|
165 | };
|
166 |
|
167 | _this.findAll_cancle = function () {
|
168 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
169 |
|
170 | var _this$props3 = _this.props,
|
171 | treeData = _this$props3.treeData,
|
172 | cancelCallBack = _this$props3.cancelCallBack;
|
173 | var resultsData = _this.state.resultsData;
|
174 | var _resultsData = [];
|
175 | var _temLength = self._tempSeleted.length;
|
176 | var _tempClosed = self._tempClosed;
|
177 |
|
178 | _this.unmountMask();
|
179 |
|
180 | _this.setState({
|
181 | searchValue: ''
|
182 | });
|
183 |
|
184 |
|
185 | var _tempArr = resultsData.concat(_tempClosed);
|
186 |
|
187 | resultsData = _tempArr;
|
188 | var _resLength = resultsData.length;
|
189 |
|
190 | for (var i = 0; i < _resLength; i++) {
|
191 | var flag = false;
|
192 | var it = resultsData[i];
|
193 |
|
194 | for (var j = 0; j < _temLength; j++) {
|
195 | var item = self._tempSeleted[j];
|
196 |
|
197 | if (it.id == item) {
|
198 | flag = true;
|
199 | }
|
200 | }
|
201 |
|
202 | if (!flag) _resultsData.push(it);
|
203 |
|
204 | if (_resultsData.length === 0) {
|
205 | _this.setState({
|
206 | defaultPlaceholder: '请选择'
|
207 | });
|
208 | }
|
209 | }
|
210 |
|
211 |
|
212 | self._tempClosed = [];
|
213 | treeData.clearTreeData && treeData.clearTreeData();
|
214 |
|
215 | _this.setState({
|
216 | resultsData: _resultsData,
|
217 | hasCount: _resultsData.length
|
218 | });
|
219 |
|
220 | cancelCallBack && cancelCallBack(_resultsData);
|
221 | };
|
222 |
|
223 | _this.renderMask = function () {
|
224 | var _this$state2 = _this.state,
|
225 | searchValue = _this$state2.searchValue,
|
226 | autoTreeItems = _this$state2.autoTreeItems,
|
227 | single = _this$state2.single;
|
228 | var _this$props4 = _this.props,
|
229 | treeData = _this$props4.treeData,
|
230 | autoTreeData = _this$props4.autoTreeData,
|
231 | sync = _this$props4.sync;
|
232 | var dataResult = sync ? autoTreeItems : autoTreeData;
|
233 |
|
234 | var autoLi = _this.returnAutoLi();
|
235 |
|
236 | var popResult_style = single ? {
|
237 | 'width': '100%'
|
238 | } : {};
|
239 |
|
240 | var _showTree = searchValue.length != 0 && dataResult != undefined && dataResult.length > 0;
|
241 |
|
242 | var popUl = _showTree ? React.createElement("ul", {
|
243 | className: "pop-auto-result",
|
244 | style: popResult_style,
|
245 | onClick: _this.itemClick
|
246 | }, autoLi) : React.createElement(Tree, _extends({}, treeData, {
|
247 | onClick: _this.treeItemClick
|
248 | }));
|
249 | var findAll_Data = {
|
250 | self: _assertThisInitialized(_assertThisInitialized(_this)),
|
251 | popUl: popUl,
|
252 | findAll_cancle: _this.findAll_cancle,
|
253 | findAll_submit: _this.findAll_submit,
|
254 | single: single
|
255 | };
|
256 | var autoTreeMask = React.createElement("div", null, React.createElement(FindAllpop, findAll_Data), React.createElement("div", {
|
257 | className: "AutoTree-mask "
|
258 | }));
|
259 | ReactDom.render(React.createElement("div", null, autoTreeMask), document.getElementById('AutoTree_Mask'));
|
260 | };
|
261 |
|
262 | _this.addClass = function (event) {
|
263 |
|
264 | _this.findAll();
|
265 |
|
266 | var isIE11 = /Trident\/7\./.test(navigator.userAgent);
|
267 | var _this$props5 = _this.props,
|
268 | focusCallBack = _this$props5.focusCallBack,
|
269 | componentId = _this$props5.componentId,
|
270 | disabled = _this$props5.disabled;
|
271 | var single = _this.state.single;
|
272 | _this.clickScroll = true;
|
273 | if (disabled || _this.state.isFocus == true) return;
|
274 |
|
275 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
276 |
|
277 | self.tar = single ? self.refs.autoForm_ref.refs.autoTreeInput : self.refs.autoForm_ref.refs.autoTree_commonInput;
|
278 | window.autoId = componentId;
|
279 | if (!single) self.addAndRemoveListen(true, true);
|
280 | document.addEventListener('mousedown', self.handelOnMouseDown);
|
281 | self.setState({
|
282 | isActive: true,
|
283 | isFocus: isIE11 ? false : true,
|
284 | isShow: false,
|
285 | autoTreeItems: [],
|
286 | showPanel: false
|
287 | });
|
288 | self['domState' + componentId] = self.state.isFocus == false ? true : false;
|
289 | focusCallBack && focusCallBack(event);
|
290 | };
|
291 |
|
292 | _this.editInput_focus = function () {
|
293 | var edit_input = _this.props.single ? _this.refs.autoForm_ref.refs.autoTreeInput : _this.refs.autoForm_ref.refs.autoTree_commonInput;
|
294 | var isIE11 = /Trident\/7\./.test(navigator.userAgent);
|
295 |
|
296 | _this.setState({
|
297 | isFocus: isIE11 ? false : true
|
298 | });
|
299 |
|
300 | _this.addClass(edit_input);
|
301 | };
|
302 |
|
303 | _this.handelOnMouseDown = function (event) {
|
304 | var _this$props6 = _this.props,
|
305 | status = _this$props6.status,
|
306 | single = _this$props6.single,
|
307 | componentId = _this$props6.componentId,
|
308 | treeData = _this$props6.treeData,
|
309 | isSearchAutoTreeEdit = _this$props6.isSearchAutoTreeEdit;
|
310 |
|
311 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
312 |
|
313 | var result_ul = status == 'edit' ? single ? getElByClass('autotree__tree-panel') : getElByClass('auto-result-container') : getElByClass('auto-result-container-search');
|
314 | var inputDom = _this.refs.AutoTree;
|
315 | _this.clickScroll = result_ul && result_ul.contains(event.target) || inputDom && inputDom.contains(event.target) && !inputDom.querySelector(".form-item__title").contains(event.target) ? false : true;
|
316 |
|
317 | if (event.target.className.indexOf("icon-foldup") != -1) {
|
318 | setTimeout(function () {
|
319 | self['domState' + componentId] = true;
|
320 | }, 100);
|
321 | }
|
322 |
|
323 | if (status == 'edit' && single) {
|
324 | if (_this.clickScroll) {
|
325 | _this['domState' + componentId] = false;
|
326 |
|
327 | _this.unmountComponent(componentId);
|
328 |
|
329 | if (single && !isSearchAutoTreeEdit) {
|
330 | treeData.clearTreeData && treeData.clearTreeData();
|
331 | }
|
332 |
|
333 | document.removeEventListener('mousedown', _this.handelOnMouseDown);
|
334 | setTimeout(function () {
|
335 | self._tempCleared = false;
|
336 | self.setState({
|
337 | isActive: false,
|
338 | isFocus: false
|
339 | });
|
340 | }, 300);
|
341 | }
|
342 | }
|
343 | };
|
344 |
|
345 | _this.removeClass = function (event) {
|
346 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
347 |
|
348 | var _this$props7 = _this.props,
|
349 | componentId = _this$props7.componentId,
|
350 | blurCallBack = _this$props7.blurCallBack;
|
351 | var _this$state3 = _this.state,
|
352 | status = _this$state3.status,
|
353 | single = _this$state3.single;
|
354 | setTimeout(function () {
|
355 | if (self._tempCleared) return;
|
356 | var isShow_Value = single ? false : true;
|
357 | if (!single) self['domState' + componentId] = false;
|
358 | self.setState({
|
359 | isActive: false,
|
360 | isFocus: false,
|
361 | isShow: isShow_Value
|
362 | });
|
363 |
|
364 | if (single && window.autoId == componentId && self.clickScroll) {
|
365 | self.unmountComponent(componentId);
|
366 | document.removeEventListener('mousedown', self.handelOnMouseDown);
|
367 | }
|
368 |
|
369 | if (single && self.clickScroll) self.addAndRemoveListen(true, false);
|
370 | }, 300);
|
371 | if (status == 'edit' && single) _this['domState' + componentId] = false;
|
372 | blurCallBack && blurCallBack(event);
|
373 | };
|
374 |
|
375 | _this.addAndRemoveListen = function (remove, add) {
|
376 | if (remove) document.removeEventListener('click', _this.onClose);
|
377 | if (add) document.addEventListener('click', _this.onClose);
|
378 | };
|
379 |
|
380 | _this.filterData = function (filterCondition) {
|
381 | var autoTreeItems = _this.props.autoTreeData;
|
382 | var filterData = filterCondition == '' ? [] : autoTreeItems.filter(function (item) {
|
383 | return item.name.includes(filterCondition);
|
384 | });
|
385 | filterData.length > 0 ? _this.setState({
|
386 | autoTreeItems: filterData
|
387 | }) : _this.setState({
|
388 | autoTreeItems: []
|
389 | });
|
390 | };
|
391 |
|
392 | _this.handleChange = function (val) {
|
393 | var _this$props8 = _this.props,
|
394 | getAutoTreeDataAPI = _this$props8.getAutoTreeDataAPI,
|
395 | sync = _this$props8.sync,
|
396 | getAutoTreeData = _this$props8.getAutoTreeData,
|
397 | componentId = _this$props8.componentId,
|
398 | findAllSearch = _this$props8.findAllSearch;
|
399 | var filters = _this.state.filters;
|
400 |
|
401 | _this.setState({
|
402 | index: -1,
|
403 | showTreeResult: true,
|
404 | searchValue: val.value
|
405 | });
|
406 |
|
407 | findAllSearch && findAllSearch(val.value);
|
408 | if (val.value == '') return;
|
409 | _this['domState' + componentId] = true;
|
410 | };
|
411 |
|
412 | _this.changeFilter = function (event, target, val) {
|
413 | var _this$props9 = _this.props,
|
414 | autoTreeSearchCallBack = _this$props9.autoTreeSearchCallBack,
|
415 | componentId = _this$props9.componentId,
|
416 | defaultValueObj = _this$props9.defaultValueObj;
|
417 | var _this$state4 = _this.state,
|
418 | hasClick = _this$state4.hasClick,
|
419 | single = _this$state4.single,
|
420 | resultsData = _this$state4.resultsData;
|
421 | var temp_val = val == '' ? val : val.text;
|
422 |
|
423 | _this.setState({
|
424 | filters: temp_val
|
425 | });
|
426 |
|
427 | if (_this['val' + componentId] == null || hasClick == false) {
|
428 | _this['val' + componentId] = {
|
429 | id: defaultValueObj && defaultValueObj.id || '',
|
430 | name: defaultValueObj && defaultValueObj.name || '',
|
431 | path: defaultValueObj && defaultValueObj.path || '',
|
432 | level: defaultValueObj && defaultValueObj.level || '',
|
433 | filters: temp_val
|
434 | };
|
435 | } else if (hasClick == true) {
|
436 | _this['val' + componentId]['filters'] = temp_val;
|
437 | }
|
438 |
|
439 | if (!single && resultsData.length != 0) {
|
440 | for (var i = 0; i < resultsData.length; i++) {
|
441 | resultsData[i]['filters'] = temp_val;
|
442 | }
|
443 |
|
444 | _this.setState({
|
445 | resultsData: resultsData
|
446 | });
|
447 | }
|
448 |
|
449 | autoTreeSearchCallBack && autoTreeSearchCallBack(single ? _this['val' + componentId] : resultsData, temp_val);
|
450 | };
|
451 |
|
452 | _this.findAll = function () {
|
453 | var _this$props10 = _this.props,
|
454 | clearAutoTreeData = _this$props10.clearAutoTreeData,
|
455 | showPopCallback = _this$props10.showPopCallback,
|
456 | componentId = _this$props10.componentId;
|
457 | clearAutoTreeData();
|
458 | setMaskStyle();
|
459 | _this['domState' + componentId] = true;
|
460 |
|
461 | _this.setState({
|
462 | isShow: false,
|
463 | showTree: true
|
464 | });
|
465 |
|
466 | _this.renderMask();
|
467 |
|
468 | _this.unmountComponent(componentId);
|
469 |
|
470 | _this.addAndRemoveListen(true, false);
|
471 |
|
472 | showPopCallback && showPopCallback();
|
473 | };
|
474 |
|
475 | _this.setSessionData = function (self, componentId) {
|
476 | sessionStorage.setItem('search' + componentId, JSON.stringify(self['temp' + componentId]));
|
477 | _this.props.setSessionCallBack && _this.props.setSessionCallBack();
|
478 | };
|
479 |
|
480 | _this.getSessionData = function (componentId) {
|
481 | return JSON.parse(sessionStorage.getItem('search' + componentId));
|
482 | };
|
483 |
|
484 | _this.itemClick = function (event) {
|
485 | var _this$props11 = _this.props,
|
486 | componentId = _this$props11.componentId,
|
487 | autoTreeData = _this$props11.autoTreeData,
|
488 | itemCallBack = _this$props11.itemCallBack;
|
489 | var single = _this.state.single;
|
490 | var node = setRealNode(event);
|
491 |
|
492 | if (node) {
|
493 | var nodeId = node.getAttribute('data-index');
|
494 | if (!single) _this.renderDom();
|
495 |
|
496 | _this.commonClick_Callback(false, nodeId, componentId, autoTreeData, itemCallBack);
|
497 | }
|
498 | };
|
499 |
|
500 | _this.handleKeyDown = function (e) {
|
501 | var _this$props12 = _this.props,
|
502 | componentId = _this$props12.componentId,
|
503 | autoTreeData = _this$props12.autoTreeData,
|
504 | itemCallBack = _this$props12.itemCallBack,
|
505 | sync = _this$props12.sync;
|
506 | var _this$state5 = _this.state,
|
507 | index = _this$state5.index,
|
508 | showTree = _this$state5.showTree,
|
509 | autoTreeItems = _this$state5.autoTreeItems,
|
510 | isFocus = _this$state5.isFocus,
|
511 | hasClick = _this$state5.hasClick,
|
512 | inputValue = _this$state5.inputValue;
|
513 | var trueIndex = index;
|
514 | var popAutoResult = getElByClass('pop-auto-result');
|
515 | var popAutoResult_ClientHeight, maxLength, tempLength, autoResult;
|
516 | var ItemHeight = _this.renderParents_Node ? 54 : 30;
|
517 |
|
518 | if (popAutoResult != undefined) {
|
519 | popAutoResult_ClientHeight = popAutoResult.offsetHeight - 10;
|
520 | maxLength = parseInt(popAutoResult_ClientHeight / ItemHeight);
|
521 | }
|
522 |
|
523 | tempLength = showTree ? maxLength : _this.renderParents_Node ? 5 : 8;
|
524 |
|
525 | var sessionData = _this.getSessionData(componentId);
|
526 |
|
527 | var dataResult = sync ? autoTreeItems : autoTreeData;
|
528 | var ifBool = (dataResult == undefined || dataResult.length == 0) && isFocus == true && sessionData != null && sessionData.length > 0 && hasClick == true || inputValue == '' && isFocus == true && sessionData != null && sessionData.length > 0 && hasClick == false;
|
529 | dataResult = ifBool ? sessionData : dataResult;
|
530 | autoResult = getElByClass('auto-result');
|
531 | autoResult = showTree == true && popAutoResult != undefined ? popAutoResult : autoResult;
|
532 |
|
533 | switch (e.keyCode) {
|
534 | case 38:
|
535 |
|
536 | if (_this.state.index <= 0) {
|
537 | return;
|
538 | } else {
|
539 | trueIndex = --_this.state.index % _this.autoLi.length;
|
540 | }
|
541 |
|
542 | if (trueIndex >= tempLength - 1) {
|
543 | autoResult.scrollTop = trueIndex == tempLength - 1 ? autoResult.scrollTop - ItemHeight : (trueIndex - (tempLength - 1)) * ItemHeight;
|
544 | }
|
545 |
|
546 | _this.setState({
|
547 | index: trueIndex
|
548 | });
|
549 |
|
550 | break;
|
551 |
|
552 | case 40:
|
553 |
|
554 | if (_this.state.index == dataResult.length - 1) return;
|
555 | trueIndex = index < 0 ? 0 : ++index % _this.autoLi.length;
|
556 |
|
557 | if (trueIndex >= tempLength) {
|
558 | autoResult.scrollTop = dataResult.length - 1 == trueIndex ? (trueIndex - (tempLength - 1)) * ItemHeight + 44 : (trueIndex - (tempLength - 1)) * ItemHeight;
|
559 | }
|
560 |
|
561 | _this.setState({
|
562 | index: trueIndex
|
563 | });
|
564 |
|
565 | break;
|
566 |
|
567 | case 13:
|
568 |
|
569 | if (index == -1) return;
|
570 | var nodeId = index;
|
571 |
|
572 | _this.commonClick_Callback(true, nodeId, componentId, dataResult, itemCallBack);
|
573 |
|
574 | if (_this.refs.autoForm_ref.refs.autoTreeInput) _this.refs.autoForm_ref.refs.autoTreeInput.blur();
|
575 | break;
|
576 |
|
577 | default:
|
578 | break;
|
579 | }
|
580 | };
|
581 |
|
582 | _this.clearDom = function () {
|
583 | var dom_1 = getElByClass('');
|
584 | var dom_2 = getElByClass('-arrow');
|
585 |
|
586 | if (dom_1 && dom_2) {
|
587 | var parNode = dom_1.parentNode;
|
588 | parNode.removeChild(dom_1);
|
589 | parNode.removeChild(dom_2);
|
590 | }
|
591 | };
|
592 |
|
593 | _this.commonClick_Callback = function (type, nodeId, componentId, dataResult, func) {
|
594 |
|
595 | var _this$props13 = _this.props,
|
596 | isSearchAutoTreeEdit = _this$props13.isSearchAutoTreeEdit,
|
597 | single = _this$props13.single,
|
598 | status = _this$props13.status,
|
599 | showDropDown = _this$props13.showDropDown,
|
600 | removeComponent = _this$props13.removeComponent,
|
601 | totalCount = _this$props13.totalCount;
|
602 | _this['domState' + componentId] = true;
|
603 | var _resultsData = _this.state.resultsData;
|
604 |
|
605 | var sessionData = _this.getSessionData(componentId);
|
606 |
|
607 | var autoTreeList = dataResult != undefined && dataResult.length > 0 ? dataResult : sessionData;
|
608 |
|
609 | _this.clearDom();
|
610 |
|
611 | for (var i = 0; i < autoTreeList.length; i++) {
|
612 | var real_Id = type == true ? i : autoTreeList[i].id;
|
613 | if (real_Id == nodeId) _this['val' + componentId] = autoTreeList[i];
|
614 | }
|
615 |
|
616 | if ((!isSearchAutoTreeEdit || status == 'edit' && single) && !showDropDown) _this.unmountMask();
|
617 |
|
618 | _this.setClickData(_this['val' + componentId].name, Object.assign({}, _this['val' + componentId]), sessionData);
|
619 |
|
620 | _this['val' + componentId]['filters'] = _this.state.filters;
|
621 |
|
622 | var temp_resultsData = _resultsData.filter(function (child) {
|
623 | return _this['val' + componentId].id == child.id;
|
624 | });
|
625 |
|
626 | if (temp_resultsData.length == 0 && _resultsData.length < totalCount) _resultsData.push(_this['val' + componentId]);
|
627 |
|
628 | var _inputValue = _this.props.status == 'search' || _this.state.single ? _this['val' + componentId].name : '';
|
629 |
|
630 | _this.setState({
|
631 | inputValue: _inputValue,
|
632 |
|
633 | isFocus: false,
|
634 | itemId: nodeId,
|
635 | hasClick: true,
|
636 | resultsData: _resultsData,
|
637 | hasCount: _resultsData.length,
|
638 | showPanel: false,
|
639 | searchChange: false
|
640 | });
|
641 |
|
642 | if (!showDropDown) removeComponent && removeComponent();
|
643 | if (single) _this.setState({
|
644 | searchValue: _inputValue
|
645 | });
|
646 | if (_this.state.showTree) _this._tempSeleted.push(_this['val' + componentId].id);
|
647 | if (!_this.state.showTree && !_this.state.single || _this.state.single) func && func(_this.state.single ? _this['val' + componentId] : _resultsData);
|
648 | };
|
649 |
|
650 | _this.setClickData = function (name, value, sessionData) {
|
651 | var componentId = _this.props.componentId;
|
652 | var jsonFlag = false;
|
653 |
|
654 | if (sessionData != null) {
|
655 | for (var j = 0; j < sessionData.length; j++) {
|
656 | if (sessionData[j].name == name) jsonFlag = true;
|
657 | }
|
658 | }
|
659 |
|
660 | var tempSessionLength = sessionData == null ? 0 : sessionData.length;
|
661 | _this['temp' + componentId] = _this['temp' + componentId] == undefined ? [] : _this['temp' + componentId];
|
662 |
|
663 | if (tempSessionLength < 10 && jsonFlag == false) {
|
664 | _this['temp' + componentId].length == 0 ? _this['temp' + componentId].push(value) : _this['temp' + componentId].unshift(value);
|
665 |
|
666 | _this.setSessionData(_assertThisInitialized(_assertThisInitialized(_this)), componentId);
|
667 | } else if (tempSessionLength >= 10 && jsonFlag == false) {
|
668 | _this['temp' + componentId].pop();
|
669 |
|
670 | var s = value;
|
671 |
|
672 | _this['temp' + componentId].unshift(s);
|
673 |
|
674 | _this.setSessionData(_assertThisInitialized(_assertThisInitialized(_this)), componentId);
|
675 | } else {
|
676 | _this.setSessionData(_assertThisInitialized(_assertThisInitialized(_this)), componentId);
|
677 | }
|
678 | };
|
679 |
|
680 | _this.clearData = function (event) {
|
681 | var clearCallback = _this.props.clearCallback;
|
682 |
|
683 | if (_this.state.isFocus) {
|
684 | _this.setState({
|
685 | isFocus: true,
|
686 | isShow: true,
|
687 | inputValue: "",
|
688 | hasClick: false
|
689 | });
|
690 | } else {
|
691 | _this.setState({
|
692 | inputValue: "",
|
693 | isShow: false,
|
694 | hasClick: false,
|
695 | isFocus: false
|
696 | });
|
697 | }
|
698 |
|
699 | _this._tempCleared = true;
|
700 | clearCallback && clearCallback();
|
701 | };
|
702 |
|
703 | _this.unmountComponent = function (componentId) {
|
704 |
|
705 | _this.setState({
|
706 | index: -1
|
707 | });
|
708 |
|
709 |
|
710 | _this.addAndRemoveListen(true, false);
|
711 |
|
712 | _this['domState' + componentId] = false;
|
713 | _this.props.unmountCallBack && _this.props.unmountCallBack();
|
714 | };
|
715 |
|
716 | _this.unmountMask = function () {
|
717 | _this.setState({
|
718 | showTree: false
|
719 | });
|
720 |
|
721 | _this.unmountComponent(_this.props.componentId);
|
722 |
|
723 | if (document.getElementById('AutoTree_Mask')) {
|
724 | ReactDom.unmountComponentAtNode(document.getElementById('AutoTree_Mask'));
|
725 | }
|
726 | };
|
727 |
|
728 | _this.onClose = function (event) {
|
729 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
730 |
|
731 | setTimeout(function () {
|
732 | self._tempCleared = false;
|
733 | }, 400);
|
734 | var _this$props14 = _this.props,
|
735 | status = _this$props14.status,
|
736 | onCloseCallback = _this$props14.onCloseCallback,
|
737 | componentId = _this$props14.componentId;
|
738 |
|
739 | if (window.autoId == componentId) {
|
740 | if (event && event.target.innerHTML == '全部查找' || event.target.innerHTML == "“查找全部”" || event.target.className.includes('icon-close')) return;
|
741 | var area = _this.tar;
|
742 | var result_ul = status == 'edit' ? getElByClass('auto-result-container') : getElByClass('auto-result-container-search');
|
743 |
|
744 | if (area == undefined && _this.state.showTree == false) {
|
745 | _this.setState({
|
746 | isShow: false
|
747 | });
|
748 |
|
749 | _this.unmountComponent(componentId);
|
750 |
|
751 | onCloseCallback && onCloseCallback(event);
|
752 | return;
|
753 | }
|
754 |
|
755 | if (area != undefined && result_ul != undefined && !area.contains(event.target) && !result_ul.contains(event.target)) {
|
756 | _this.setState({
|
757 | isFocus: false,
|
758 | isShow: false
|
759 | });
|
760 |
|
761 | _this.unmountComponent(componentId);
|
762 |
|
763 | onCloseCallback && onCloseCallback(event);
|
764 | if (_this.state.hasClick == false) _this.setState({
|
765 | inputValue: ''
|
766 | });
|
767 | }
|
768 | }
|
769 | };
|
770 |
|
771 | _this.itemClose = function (event, item, index) {
|
772 | var itemCloseCallBack = _this.props.itemCloseCallBack;
|
773 | var _resultsData = _this.state.resultsData;
|
774 | var _hasCount = _this.state.hasCount;
|
775 | _resultsData = _resultsData.filter(function (child) {
|
776 | return item.id != child.id;
|
777 | });
|
778 |
|
779 | _this.setState({
|
780 | resultsData: _resultsData,
|
781 | hasCount: _hasCount - 1
|
782 | });
|
783 |
|
784 | if (_resultsData.length === 0) {
|
785 | _this.setState({
|
786 | defaultPlaceholder: '请选择'
|
787 | });
|
788 | }
|
789 |
|
790 | itemCloseCallBack && itemCloseCallBack(_resultsData);
|
791 | };
|
792 |
|
793 | _this.treeItemClick = function (e, valObj) {
|
794 |
|
795 | var _this$props15 = _this.props,
|
796 | componentId = _this$props15.componentId,
|
797 | itemCallBack = _this$props15.itemCallBack,
|
798 | status = _this$props15.status,
|
799 | treeData = _this$props15.treeData,
|
800 | showDropDown = _this$props15.showDropDown,
|
801 | isSearchAutoTreeEdit = _this$props15.isSearchAutoTreeEdit,
|
802 | removeComponent = _this$props15.removeComponent,
|
803 | totalCount = _this$props15.totalCount;
|
804 | _this['domState' + componentId] = true;
|
805 | var single = _this.state.single;
|
806 |
|
807 | if (single && !isSearchAutoTreeEdit) {
|
808 | treeData.clearTreeData && treeData.clearTreeData();
|
809 | }
|
810 |
|
811 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
812 |
|
813 | var _resultsData = _this.state.resultsData;
|
814 | var currentDataLength = _resultsData.length;
|
815 |
|
816 | var sessionData = _this.getSessionData(componentId);
|
817 |
|
818 | _this.setClickData(valObj.name, Object.assign({}, valObj), sessionData);
|
819 |
|
820 | if (_this['val' + componentId] != null) {
|
821 | valObj.filters = _this['val' + componentId].filters;
|
822 | }
|
823 |
|
824 | _this['val' + componentId] = valObj;
|
825 |
|
826 | if ((!isSearchAutoTreeEdit && single || status == 'edit' && single) && !showDropDown) {
|
827 | _this.unmountMask();
|
828 | }
|
829 |
|
830 | var temp_resultsData = _resultsData.filter(function (child) {
|
831 | return _this['val' + componentId].id == child.id;
|
832 | });
|
833 |
|
834 |
|
835 | if (currentDataLength === totalCount) {
|
836 | _this.setState({
|
837 | isShowSaveTips: true,
|
838 | tipsTitle: '最多只能选择' + totalCount + '项'
|
839 | });
|
840 | }
|
841 |
|
842 |
|
843 | var temp_falg = true;
|
844 |
|
845 | if (temp_resultsData.length == 0 && _resultsData.length < totalCount) {
|
846 | _resultsData.map(function (child) {
|
847 | if (valObj.pid == child.id) {
|
848 | temp_falg = false;
|
849 | }
|
850 | });
|
851 |
|
852 | if (temp_falg) {
|
853 | _resultsData.push(_this['val' + componentId]);
|
854 | } else {
|
855 | _this.setState({
|
856 | isShowSaveTips: true,
|
857 | tipsTitle: '需删除父级后,才可选择子级'
|
858 | });
|
859 | }
|
860 | }
|
861 |
|
862 |
|
863 | var real_resultsData = [];
|
864 |
|
865 | if (currentDataLength < totalCount) {
|
866 | real_resultsData = _resultsData.filter(function (child) {
|
867 | return valObj.id !== child.pid;
|
868 | });
|
869 | } else {
|
870 | real_resultsData = _resultsData;
|
871 | }
|
872 |
|
873 | var _inputValue = status == 'search' || single ? valObj.name : '';
|
874 |
|
875 | if (status == 'search') {
|
876 | _this.setState({
|
877 | nodeValue: valObj.name,
|
878 | searchValue: _inputValue,
|
879 | hasClick: true,
|
880 | resultsData: real_resultsData,
|
881 | hasCount: real_resultsData.length,
|
882 | showPanel: false
|
883 | }, _this.forceUpdate());
|
884 | } else {
|
885 | _this.setState({
|
886 | nodeValue: valObj.name,
|
887 | inputValue: _inputValue,
|
888 | searchValue: _inputValue,
|
889 | hasClick: true,
|
890 | resultsData: real_resultsData,
|
891 | hasCount: real_resultsData.length,
|
892 | showPanel: false,
|
893 | isFocus: false
|
894 | }, _this.forceUpdate());
|
895 | }
|
896 |
|
897 | if (_this.state.showTree) _this._tempSeleted.push(_this['val' + componentId].id);
|
898 |
|
899 | if (!showDropDown) {
|
900 | removeComponent && removeComponent();
|
901 | }
|
902 |
|
903 | if (single && !isSearchAutoTreeEdit || status == 'search' || isSearchAutoTreeEdit) {
|
904 | itemCallBack && itemCallBack(_this['val' + componentId]);
|
905 | }
|
906 |
|
907 | setTimeout(function () {
|
908 | self['domState' + self.props.componentId] = false;
|
909 | }, 500);
|
910 | };
|
911 |
|
912 | _this.handelSubmit = function () {
|
913 | var searchValue = _this.state.searchValue;
|
914 | var _this$props16 = _this.props,
|
915 | isSearchAutoTreeEdit = _this$props16.isSearchAutoTreeEdit,
|
916 | treeData = _this$props16.treeData;
|
917 |
|
918 | if (isSearchAutoTreeEdit) {
|
919 | _this.unmountMask();
|
920 |
|
921 | treeData.clearTreeData && treeData.clearTreeData();
|
922 | }
|
923 |
|
924 | var val;
|
925 |
|
926 | if (_this['val' + _this.props.componentId] && searchValue == _this['val' + _this.props.componentId].name) {
|
927 | val = _this['val' + _this.props.componentId];
|
928 | } else {
|
929 | val = null;
|
930 | }
|
931 |
|
932 | _this.props.searchSubmitCallBack && _this.props.searchSubmitCallBack(val);
|
933 | };
|
934 |
|
935 | _this.state = {
|
936 | isFocus: props && props.defaultStatus || false,
|
937 |
|
938 | isShowMouseOverIcon: false,
|
939 | inputValue: props && props.defaultValue || '',
|
940 |
|
941 | itemId: '',
|
942 | isShow: true,
|
943 | showTree: false,
|
944 |
|
945 | status: props && props.status || 'edit',
|
946 | showTreeResult: false,
|
947 |
|
948 | searchValue: "",
|
949 | autoTreeItems: [],
|
950 | filters: '',
|
951 |
|
952 | hidden: props && props.hidden || false,
|
953 | hasClick: props.defaultValue == '' || props.defaultValue == undefined ? false : true,
|
954 | index: -1,
|
955 |
|
956 | hasCount: props && props.resultsData.length || 0,
|
957 | resultsData: props && props.resultsData || [],
|
958 |
|
959 | isActive: false,
|
960 | single: props && props.single || props.single == undefined ? true : false,
|
961 | defaultPlaceholder: props && (props.resultsData.length > 0 ? '' : props.placeholder) || '',
|
962 | showPanel: props.status == 'search' ? true : false,
|
963 | searchChange: false,
|
964 | isShowSaveTips: false,
|
965 | tipsTitle: ''
|
966 | };
|
967 | _this._tempClosed = [];
|
968 | _this._tempSeleted = [];
|
969 | _this._tempCleared = false;
|
970 | _this.autoLi = [];
|
971 | _this.clickScroll = true;
|
972 | _this.chrome_tag = true;
|
973 | _this.renderParents_Node = false;
|
974 | _this['temp' + props.componentId] = [];
|
975 | sessionStorage.setItem('search' + props.componentId, JSON.stringify(_this['temp' + props.componentId]));
|
976 | _this['val' + props.componentId] = props && props.defaultValueObj || null;
|
977 | _this.tar = null;
|
978 |
|
979 | _this.createDom();
|
980 |
|
981 | _this['domState' + props.componentId] = false;
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 | _this.onChange = _this.onChange.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
991 | _this.searchClick = _this.searchClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
992 | _this.onChange = debounce(_this.onChange, 200);
|
993 | return _this;
|
994 | }
|
995 |
|
996 | _createClass(AutoTree, [{
|
997 | key: "createDom",
|
998 | value: function createDom() {
|
999 | if (document.getElementById('AutoTree_Mask')) return;
|
1000 | var mDiv = document.createElement('div');
|
1001 | mDiv.id = 'AutoTree_Mask';
|
1002 | document.body.appendChild(mDiv);
|
1003 | }
|
1004 |
|
1005 | }, {
|
1006 | key: "onChange",
|
1007 |
|
1008 | value: function onChange(event) {
|
1009 | var self = this;
|
1010 | var _this$props17 = this.props,
|
1011 | getAutoTreeDataAPI = _this$props17.getAutoTreeDataAPI,
|
1012 | sync = _this$props17.sync,
|
1013 | componentId = _this$props17.componentId,
|
1014 | getAutoTreeData = _this$props17.getAutoTreeData,
|
1015 | changeCallBack = _this$props17.changeCallBack,
|
1016 | clearCallback = _this$props17.clearCallback,
|
1017 | single = _this$props17.single,
|
1018 | status = _this$props17.status;
|
1019 | var inputValue = status == 'search' ? event.value : event.target.value;
|
1020 | var filters = this.state.filters;
|
1021 | var formRef = this.refs.autoForm_ref;
|
1022 | this._tempCleared = false;
|
1023 |
|
1024 | if (status == 'search' || single) {
|
1025 | this.setState({
|
1026 | index: -1,
|
1027 | isShow: true,
|
1028 | showPanel: true,
|
1029 | searchChange: true,
|
1030 | hasClick: false,
|
1031 | searchValue: inputValue
|
1032 | });
|
1033 | } else {
|
1034 | this.setState({
|
1035 | index: -1,
|
1036 | isShow: true,
|
1037 | hasClick: false,
|
1038 | inputValue: inputValue
|
1039 | });
|
1040 | }
|
1041 |
|
1042 | this['domState' + componentId] = true;
|
1043 | if (formRef) this.tar = this.props.single ? formRef.refs.autoTreeInput : formRef.refs.autoTree_commonInput;
|
1044 | offset = {
|
1045 | zIndex: '99999',
|
1046 | position: 'fixed'
|
1047 | };
|
1048 | if (inputValue == '') clearCallback && clearCallback();
|
1049 |
|
1050 | sync == false ? getAutoTreeData && getAutoTreeData(getAutoTreeDataAPI, inputValue, filters) : this.filterData(inputValue);
|
1051 | setTimeout(function () {
|
1052 | self.renderDom(false, offset);
|
1053 | }, 200);
|
1054 | changeCallBack && changeCallBack(event, this.state, inputValue);
|
1055 | }
|
1056 | }, {
|
1057 | key: "onRealChange",
|
1058 | value: function onRealChange(event) {
|
1059 | event.persist();
|
1060 | this.onChange(event);
|
1061 | }
|
1062 |
|
1063 | }, {
|
1064 | key: "componentDidUpdate",
|
1065 | value: function componentDidUpdate() {
|
1066 | var _this$state6 = this.state,
|
1067 | status = _this$state6.status,
|
1068 | showTree = _this$state6.showTree,
|
1069 | inputValue = _this$state6.inputValue,
|
1070 | isFocus = _this$state6.isFocus,
|
1071 | autoTreeItems = _this$state6.autoTreeItems;
|
1072 | var _this$props18 = this.props,
|
1073 | componentId = _this$props18.componentId,
|
1074 | autoTreeData = _this$props18.autoTreeData,
|
1075 | sync = _this$props18.sync,
|
1076 | single = _this$props18.single;
|
1077 | var popAutoResult = getElByClass('pop-auto-result');
|
1078 |
|
1079 | var searchContainer = getElByClass('searchContainer');
|
1080 | var autoResultContainer = getElByClass('auto-result-container');
|
1081 | var windowH = window.innerHeight;
|
1082 | var windowW = window.innerWidth;
|
1083 | var ItemHeight = this.renderParents_Node ? 54 : 30;
|
1084 | var selected_Component = getElByClass('selected_Component');
|
1085 |
|
1086 | if (selected_Component) {
|
1087 | selected_Component.style.width = windowW * 0.65 - 301 + 'px';
|
1088 | selected_Component.style.marginLeft = '15px';
|
1089 | selected_Component.style.marginTop = '15px';
|
1090 | }
|
1091 |
|
1092 | if (popAutoResult != undefined) {
|
1093 | var popAutoResult_ClientHeight = searchContainer.offsetHeight * 0.85 - 10;
|
1094 | var maxLength = parseInt(popAutoResult_ClientHeight / ItemHeight);
|
1095 | var finalHeight = maxLength * ItemHeight;
|
1096 | popAutoResult.style.maxHeight = finalHeight + 'px';
|
1097 | }
|
1098 |
|
1099 | if (status == 'search') {
|
1100 | var reConNode = getElByClass('autoTree_Search');
|
1101 | var resultNode = getElByClass('auto-result-container-search');
|
1102 | var searchInput = getElByClass('autoTree-search-input');
|
1103 | if (searchInput && !this.chrome_tag) searchInput.style.lineHeight = 23 + 'px';
|
1104 |
|
1105 | if (reConNode != undefined && resultNode != undefined && !showTree) {
|
1106 | reConNode.style.boxShadow = '0px 3px 10px rgba(0, 0, 0, 0.15)';
|
1107 | }
|
1108 | }
|
1109 |
|
1110 | var dataResult = sync ? autoTreeItems : autoTreeData;
|
1111 |
|
1112 | if (status == 'status' && inputValue.length > 0 && dataResult.length == 0 && isFocus == true) {
|
1113 | autoResultContainer.style.height = '360px';
|
1114 | }
|
1115 |
|
1116 |
|
1117 | if (showTree && searchContainer != undefined) {
|
1118 | var temp_Height = status == 'edit' ? 50 : 0;
|
1119 | searchContainer.style.left = (windowW - searchContainer.offsetWidth) * 0.5 + 'px';
|
1120 | searchContainer.style.top = '30px';
|
1121 | }
|
1122 |
|
1123 | if (status == 'edit' && !single) {
|
1124 | if (inputValue.length == 0 && isFocus == true) this['domState' + componentId] = true;
|
1125 | if (showTree == true) this['domState' + componentId] = true;
|
1126 | }
|
1127 |
|
1128 | var self = this;
|
1129 |
|
1130 | if (this['domState' + componentId]) {
|
1131 | self.renderDom(false, offset);
|
1132 | }
|
1133 |
|
1134 | if (showTree) {
|
1135 | this.renderMask();
|
1136 | }
|
1137 | }
|
1138 | }, {
|
1139 | key: "componentDidMount",
|
1140 | value: function componentDidMount() {
|
1141 | var status = this.state.status;
|
1142 |
|
1143 | if (status == 'search') {
|
1144 | var reConNode = this.refs.AutoTree;
|
1145 |
|
1146 | if (reConNode != undefined) {
|
1147 | reConNode.style.boxShadow = '0px 3px 10px rgba(0, 0, 0, 0.15)';
|
1148 | }
|
1149 |
|
1150 | this.setState({
|
1151 | isFocus: true
|
1152 | });
|
1153 | }
|
1154 |
|
1155 | this.chrome_tag = parseInt(getSysVersion().chrome) >= 50;
|
1156 |
|
1157 | if (this.props.defaultStatus) {
|
1158 | this.refs.autoForm_ref.refs.autoTreeInput.focus();
|
1159 | }
|
1160 |
|
1161 | ;
|
1162 | setMaskStyle();
|
1163 | }
|
1164 |
|
1165 | }, {
|
1166 | key: "componentWillReceiveProps",
|
1167 | value: function componentWillReceiveProps(nextProps) {
|
1168 | var nextAutoData = nextProps.autoTreeData;
|
1169 | var nextTreeData = nextProps.treeData.treeData;
|
1170 | var _this$props19 = this.props,
|
1171 | autoTreeData = _this$props19.autoTreeData,
|
1172 | treeData = _this$props19.treeData;
|
1173 |
|
1174 | if (nextProps.defaultValue != this.props.defaultValue && nextProps.defaultValue != this.state.inputValue) {
|
1175 | this.setState({
|
1176 | defaultValue: nextProps.defaultValue,
|
1177 | inputValue: nextProps.defaultValue
|
1178 | });
|
1179 |
|
1180 | if (nextProps.defaultValue.length == 0 && this['val' + this.props.componentId]) {
|
1181 | this['val' + this.props.componentId].filters = '';
|
1182 | }
|
1183 | }
|
1184 |
|
1185 |
|
1186 | if (nextAutoData != undefined && autoTreeData != undefined && nextAutoData.length != autoTreeData.length) {
|
1187 | this.setState({
|
1188 | showPanel: true
|
1189 | });
|
1190 | }
|
1191 |
|
1192 |
|
1193 | if (nextTreeData != undefined && treeData.treeData != undefined && nextTreeData.length != treeData.treeData.length) {
|
1194 | this.setState({
|
1195 | showPanel: true
|
1196 | });
|
1197 | }
|
1198 | }
|
1199 |
|
1200 | }, {
|
1201 | key: "renderDom",
|
1202 | value: function renderDom(temp) {
|
1203 | var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1204 | var self = this;
|
1205 | var _this$props20 = this.props,
|
1206 | status = _this$props20.status,
|
1207 | single = _this$props20.single,
|
1208 | isSearchAutoTreeEdit = _this$props20.isSearchAutoTreeEdit,
|
1209 | showDropDown = _this$props20.showDropDown,
|
1210 | DropDownData = _this$props20.DropDownData;
|
1211 | var _this$state7 = this.state,
|
1212 | isShow = _this$state7.isShow,
|
1213 | inputValue = _this$state7.inputValue,
|
1214 | searchChange = _this$state7.searchChange,
|
1215 | showPanel = _this$state7.showPanel;
|
1216 |
|
1217 | if (status != 'search') {
|
1218 | if (single) {
|
1219 | var ul_Content;
|
1220 | var autoLi = this.returnAutoLi(true);
|
1221 | var autoLiChild = autoLi.length > 0 ? autoLi : '';
|
1222 | if (isShow) ul_Content = autoLi.length == 0 && inputValue.length > 0 ? React.createElement("div", {
|
1223 | className: "findNothing empty-con"
|
1224 | }) : autoLiChild;
|
1225 | var searchCom = React.createElement(SearchFilters, {
|
1226 | DropDownData: DropDownData,
|
1227 | isSearchAutoTreeEdit: isSearchAutoTreeEdit,
|
1228 | changeFilter: this.changeFilter,
|
1229 | showDropDown: showDropDown,
|
1230 | handelSubmit: this.handelSubmit,
|
1231 | isPanelShow: isShow
|
1232 | });
|
1233 | renderTree(self, temp, offset, self.treeItemClick, ul_Content, self.itemClick, searchChange, searchCom, showPanel);
|
1234 | } else {
|
1235 | renderAutoUl(self, temp, offset);
|
1236 | }
|
1237 | }
|
1238 | }
|
1239 | }, {
|
1240 | key: "searchClick",
|
1241 | value: function searchClick(event) {
|
1242 | var showPanel = this.state.showPanel;
|
1243 |
|
1244 | if (!showPanel) {
|
1245 | this.setState({
|
1246 | showPanel: true
|
1247 | });
|
1248 | }
|
1249 | }
|
1250 | }, {
|
1251 | key: "render",
|
1252 | value: function render() {
|
1253 | var _this2 = this;
|
1254 |
|
1255 | var _this$state8 = this.state,
|
1256 | isFocus = _this$state8.isFocus,
|
1257 | inputValue = _this$state8.inputValue,
|
1258 | isShow = _this$state8.isShow,
|
1259 | searchValue = _this$state8.searchValue,
|
1260 | status = _this$state8.status,
|
1261 | single = _this$state8.single,
|
1262 | resultsData = _this$state8.resultsData,
|
1263 | isShowMouseOverIcon = _this$state8.isShowMouseOverIcon,
|
1264 | defaultPlaceholder = _this$state8.defaultPlaceholder,
|
1265 | showPanel = _this$state8.showPanel,
|
1266 | searchChange = _this$state8.searchChange,
|
1267 | isShowSaveTips = _this$state8.isShowSaveTips,
|
1268 | tipsTitle = _this$state8.tipsTitle;
|
1269 | var _this$props21 = this.props,
|
1270 | showDropDown = _this$props21.showDropDown,
|
1271 | errorMsg = _this$props21.errorMsg,
|
1272 | showText = _this$props21.showText,
|
1273 | errorStatus = _this$props21.errorStatus,
|
1274 | placeholder = _this$props21.placeholder,
|
1275 | autoTreeData = _this$props21.autoTreeData,
|
1276 | isSearchAutoTreeEdit = _this$props21.isSearchAutoTreeEdit,
|
1277 | readOnly = _this$props21.readOnly,
|
1278 | treeData = _this$props21.treeData,
|
1279 | componentId = _this$props21.componentId,
|
1280 | DropDownData = _this$props21.DropDownData,
|
1281 | disabled = _this$props21.disabled,
|
1282 | defaultValue = _this$props21.defaultValue;
|
1283 | var ul_Content;
|
1284 | var autoLi = this.returnAutoLi(true);
|
1285 | var autoLiChild = autoLi.length > 0 ? autoLi : '';
|
1286 |
|
1287 | var _defaultValue = resultsData.length == 0 ? defaultValue || '' : '';
|
1288 |
|
1289 | var cInputData = getCommonInputData(this.state.isActive, defaultPlaceholder, _defaultValue, disabled, errorStatus, errorMsg, this.state.resultsData, this.itemClose, this.onChange, this.addClass, this.removeClass);
|
1290 | var autoTreeSum = autoTreeData ? autoTreeData : [];
|
1291 | var assignTreeData = Object.assign({}, treeData, {
|
1292 | style: {
|
1293 | "height": "325px"
|
1294 | }
|
1295 | });
|
1296 |
|
1297 | if (isShow) {
|
1298 | ul_Content = autoLi.length == 0 && inputValue.length > 0 ? React.createElement("div", {
|
1299 | className: "findNothing empty-con"
|
1300 | }) : autoLiChild;
|
1301 | }
|
1302 |
|
1303 | var tipProps = {
|
1304 | infoType: 'warning',
|
1305 | disappearTime: '3000',
|
1306 | isAutomaticCloseTip: true,
|
1307 | title: tipsTitle,
|
1308 | hide: function hide() {
|
1309 | _this2.setState({
|
1310 | isShowSaveTips: false
|
1311 | });
|
1312 | }
|
1313 | };
|
1314 | return React.createElement("div", null, React.createElement("div", {
|
1315 | ref: "AutoTree",
|
1316 | onKeyDown: this.handleKeyDown,
|
1317 | className: 'field auto-tree' + (status == 'search' ? ' autoTree_Search' : '')
|
1318 | }, status == 'edit' ? React.createElement("div", {
|
1319 | className: status == 'edit' ? 'innerAutoTree' : ''
|
1320 | }, React.createElement("div", {
|
1321 | className: 'form-item ' + (errorStatus && single ? 'base-input-error-label' : '')
|
1322 | }, status == 'edit' ? React.createElement(CommonLabel, this.props) : '', React.createElement(AutoFormInput, {
|
1323 | status: status,
|
1324 | isShowMouseOverIcon: isShowMouseOverIcon,
|
1325 | isFocus: isFocus,
|
1326 | disabled: disabled,
|
1327 | single: single,
|
1328 | showDropDown: showDropDown,
|
1329 | placeholder: defaultPlaceholder,
|
1330 | inputValue: inputValue,
|
1331 | defaultValue: defaultValue,
|
1332 | errorMsg: errorMsg,
|
1333 | showText: showText,
|
1334 | autoId: window.autoId,
|
1335 | componentId: componentId,
|
1336 | DropDownData: DropDownData,
|
1337 | errorStatus: errorStatus,
|
1338 | commmonInput_Data: cInputData,
|
1339 | handlerOver: this.handlerOver,
|
1340 | readOnly: readOnly,
|
1341 | handlerOut: this.handlerOut,
|
1342 | clearData: this.clearData,
|
1343 | addClass: this.addClass,
|
1344 | editInput_focus: this.editInput_focus,
|
1345 | removeClass: this.removeClass,
|
1346 | onChange: this.onRealChange.bind(this),
|
1347 | findAll: this.findAll,
|
1348 | changeFilter: this.changeFilter,
|
1349 | isSearchAutoTreeEdit: isSearchAutoTreeEdit,
|
1350 | ref: "autoForm_ref"
|
1351 | }))) : React.createElement("div", {
|
1352 | className: "auto-tree__search-panel"
|
1353 | }, React.createElement(Search, _extends({}, getSearchData(searchValue, showPanel ? true : false, true), {
|
1354 | onChange: this.onChange,
|
1355 | onClick: this.searchClick
|
1356 | })), this.props.isFetching ? React.createElement("div", {
|
1357 | style: {
|
1358 | "maxHeight": '310px',
|
1359 | 'overflowY': 'scroll',
|
1360 | backgroundColor: "#FFF",
|
1361 | height: '310px'
|
1362 | }
|
1363 | }, React.createElement(Loading, {
|
1364 | type: "small"
|
1365 | })) : searchChange ? searchValue.length > 0 && autoTreeSum.length > 0 ? React.createElement("div", {
|
1366 | className: "auto-result-container-search",
|
1367 | style: {
|
1368 | display: showPanel ? 'block' : 'none'
|
1369 | }
|
1370 | }, React.createElement("ul", {
|
1371 | className: "auto-result",
|
1372 | onClick: this.itemClick
|
1373 | }, ul_Content)) : searchValue.length > 0 && autoTreeSum.length == 0 ? React.createElement("div", {
|
1374 | className: "empty-con error_page"
|
1375 | }) : showPanel ? React.createElement(Tree, _extends({}, assignTreeData, {
|
1376 | onClick: this.treeItemClick
|
1377 | })) : '' : showPanel ? React.createElement(Tree, _extends({}, assignTreeData, {
|
1378 | onClick: this.treeItemClick
|
1379 | })) : '', React.createElement(SearchFilters, {
|
1380 | DropDownData: DropDownData,
|
1381 | isSearchAutoTreeEdit: isSearchAutoTreeEdit,
|
1382 | changeFilter: this.changeFilter,
|
1383 | showDropDown: showDropDown,
|
1384 | handelSubmit: this.handelSubmit
|
1385 | }))), isShowSaveTips && React.createElement("div", {
|
1386 | style: {
|
1387 | "z-index": '999999'
|
1388 | }
|
1389 | }, React.createElement(Tip, tipProps), " "));
|
1390 | }
|
1391 | }]);
|
1392 |
|
1393 | return AutoTree;
|
1394 | }(Component);
|
1395 |
|
1396 | export { AutoTree as default }; |
\ | No newline at end of file |