/** 入驻小区 **/ (function(vc) { vc.extends({ propTypes: { callBackListener: vc.propTypes.string, //父组件名称 }, data: { floorUnitTreeInfo: { units: [] } }, _initMethod: function() { $that._loadFloorAndUnits(); }, _initEvent: function() { }, methods: { _loadFloorAndUnits: function() { let param = { params: { communityId: vc.getCurrentCommunity().communityId } }; //发送get请求 vc.http.apiGet('/unit.queryUnits', param, function(json) { let _unitInfo = JSON.parse(json); $that.floorUnitTreeInfo.units = _unitInfo; $that._initJsTreeFloorUnit(); }, function() { console.log('请求失败处理'); }); }, _initJsTreeFloorUnit: function() { let _data = $that._doJsTreeData(); _data = _data.sort(function(a, b) { return a.floorNum - b.floorNum }) $.jstree.destroy() $("#jstree_floorUnit").jstree({ "checkbox": { "keep_selected_style": false }, 'state': { //一些初始化状态 "opened": true, }, 'core': { 'data': _data } }); $("#jstree_floorUnit").on("ready.jstree", function(e, data) { //data.instance.open_all();//打开所有节点 $('#jstree_floorUnit').jstree('select_node', _data[0].children[0].id /* , true */ ); }); $('#jstree_floorUnit').on("changed.jstree", function(e, data) { if (data.action == 'model' || data.action == 'ready') { //默认合并 //$("#jstree_floorUnit").jstree("close_all"); return; } let _selected = data.selected[0]; if (_selected.startsWith('f_')) { return; } //console.log(_selected, data.node.original.unitId) vc.emit($props.callBackListener, 'switchUnit', { unitId: data.node.original.unitId }) }); }, _doJsTreeData: function() { let _mFloorTree = []; let _units = $that.floorUnitTreeInfo.units; //构建 第一层菜单组 _units.forEach(pItem => { let _includeFloor = false; for (let _mgIndex = 0; _mgIndex < _mFloorTree.length; _mgIndex++) { if (pItem.floorId == _mFloorTree[_mgIndex].floorId) { _includeFloor = true; } } if (!_includeFloor) { let _floorItem = { id: 'f_' + pItem.floorId, floorId: pItem.floorId, floorNum: pItem.floorNum, icon: "/img/floor.png", text: pItem.floorNum + "栋", state: { opened: false }, children: [] }; $that._doJsTreeMenuData(_floorItem); _mFloorTree.push(_floorItem); } }); return _mFloorTree; }, _doJsTreeMenuData: function(_floorItem) { let _units = $that.floorUnitTreeInfo.units; //构建菜单 let _children = _floorItem.children; for (let _pIndex = 0; _pIndex < _units.length; _pIndex++) { if (_floorItem.floorId == _units[_pIndex].floorId) { let _includeMenu = false; for (let _mgIndex = 0; _mgIndex < _children.length; _mgIndex++) { if (_units[_pIndex].unitId == _children[_mgIndex].unitId) { _includeMenu = true; } } if (!_includeMenu) { let _menuItem = { id: 'u_' + _units[_pIndex].unitId, unitId: _units[_pIndex].unitId, text: _units[_pIndex].unitNum + "单元", icon: "/img/unit.png" }; _children.push(_menuItem); } } } }, } }); })(window.vc);