| | |
| | | communityId: vc.getCurrentCommunity().communityId |
| | | } |
| | | }; |
| | | |
| | | // 验证社区ID是否存在 |
| | | let communityId = vc.getCurrentCommunity().communityId; |
| | | console.log('当前社区ID:', communityId); |
| | | if (!communityId) { |
| | | console.error('未获取到有效的社区ID'); |
| | | $that.roomTreeDivInfo.units = []; |
| | | $that._initJsTreeRoomTreeDivFloorUnit(); |
| | | return; |
| | | } |
| | | |
| | | // 发送 GET 请求获取单元数据 |
| | | vc.http.apiGet('/unit.queryUnits', |
| | | param, |
| | |
| | | console.log('单元API返回原始数据:', json); |
| | | let unitsData = []; |
| | | |
| | | if (json) { |
| | | if (json && json.trim() !== '') { |
| | | try { |
| | | // 解析 JSON 数据 |
| | | let _unitInfo = JSON.parse(json); |
| | | console.log('解析后的单元数据:', _unitInfo); |
| | | |
| | | // 增强数据处理,支持多种响应格式 |
| | | if (_unitInfo && Array.isArray(_unitInfo)) { |
| | | if (_unitInfo && _unitInfo.code == 0) { |
| | | // 标准组件API返回格式 |
| | | if (_unitInfo.data && Array.isArray(_unitInfo.data)) { |
| | | unitsData = _unitInfo.data; |
| | | console.log('使用标准格式.data字段数组,共', unitsData.length, '条单元数据'); |
| | | } else if (_unitInfo.units && Array.isArray(_unitInfo.units)) { |
| | | unitsData = _unitInfo.units; |
| | | console.log('使用标准格式.units字段数组,共', unitsData.length, '条单元数据'); |
| | | } |
| | | } else if (_unitInfo && Array.isArray(_unitInfo)) { |
| | | // 直接数组格式 |
| | | unitsData = _unitInfo; |
| | | console.log('使用直接数组格式,共', unitsData.length, '条单元数据'); |
| | | } else if (_unitInfo && _unitInfo.data && Array.isArray(_unitInfo.data)) { |
| | | unitsData = _unitInfo.data; |
| | | console.log('使用.data字段数组,共', unitsData.length, '条单元数据'); |
| | | } else if (_unitInfo && _unitInfo.units && Array.isArray(_unitInfo.units)) { |
| | | unitsData = _unitInfo.units; |
| | | console.log('使用.units字段数组,共', unitsData.length, '条单元数据'); |
| | | } else if (_unitInfo && typeof _unitInfo === 'object') { |
| | | // 处理其他可能的对象格式 |
| | | console.warn('单元数据格式不符合预期,尝试查找数组字段:', _unitInfo); |
| | | // 遍历对象属性,查找可能的数据数组 |
| | | for (let key in _unitInfo) { |
| | | if (Array.isArray(_unitInfo[key])) { |
| | | unitsData = _unitInfo[key]; |
| | | console.log('从', key, '字段获取单元数据,共', unitsData.length, '条'); |
| | | break; |
| | | } |
| | | } |
| | | // 单对象格式 |
| | | unitsData = [_unitInfo]; |
| | | console.log('使用单对象格式,共 1 条单元数据'); |
| | | } else { |
| | | console.warn('单元数据格式不符合预期,无法提取数组:', _unitInfo); |
| | | } |
| | | } catch (e) { |
| | | console.error('解析单元数据时发生错误:', e); |
| | | console.error('原始响应数据:', json); |
| | | } |
| | | } else { |
| | | console.warn('单元API返回空数据'); |
| | | } |
| | | |
| | | console.log('最终处理后的单元数据:', unitsData); |
| | |
| | | if (_callName == 'oweFeeCallable') { |
| | | return; |
| | | } |
| | | // 默认选中第一个单元 |
| | | // 默认选中第一个单元,添加安全检查避免出错 |
| | | if (_data && _data.length > 0 && _data[0].children && _data[0].children.length > 0) { |
| | | $('#jstree_floorUnitRoomDiv').jstree('select_node', _data[0].children[0].id /* , true */); |
| | | } else { |
| | | console.log('没有可用的单元数据,无法默认选中'); |
| | | } |
| | | }); |
| | | /** |
| | | * 监听树节点变化事件 |