| | |
| | | timer: {} |
| | | } |
| | | }, |
| | | |
| | | // 框架要求的字典初始化方法,必须定义在组件对象顶层 |
| | | _initDicts: function() { |
| | | console.log('水电抄表组件初始化字典数据'); |
| | | // 这里可以根据需要初始化字典数据,目前组件不需要字典数据,所以留空 |
| | | }, |
| | | |
| | | _initMethod: function () { |
| | | // 初始化房间树 |
| | | vc.emit('roomTreeDiv', 'initRoomTreeDiv', { |
| | | callName: 'meterWaterManage' |
| | | }); |
| | | $that.listMeterTypes(); |
| | | $that._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | |
| | | console.log('水电抄表组件初始化完成'); |
| | | |
| | | // 不要在_initMethod中加载数据,等待组件完全初始化 |
| | | }, |
| | | // 组件挂载完成后立即加载数据 |
| | | mounted: function() { |
| | | console.log('水电抄表组件已挂载,立即加载数据'); |
| | | |
| | | // 显式初始化footable表格 |
| | | if (window.$ && typeof window.$.fn.footable === 'function') { |
| | | console.log('显式初始化footable表格'); |
| | | $('.footable').footable(); |
| | | } |
| | | |
| | | // 加载表类型数据 |
| | | if (typeof vc.component.listMeterTypes === 'function') { |
| | | vc.component.listMeterTypes(); |
| | | } |
| | | |
| | | // 立即加载抄表数据,不依赖房间树 |
| | | if (typeof vc.component._listMeterWaters === 'function') { |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | } |
| | | |
| | | // 添加页面可见性变化监听 |
| | | document.addEventListener('visibilitychange', () => { |
| | | if (document.visibilityState === 'visible' && vc.component) { |
| | | console.log('页面变为可见,重新加载抄表数据'); |
| | | |
| | | // 加载表类型数据 |
| | | if (typeof vc.component.listMeterTypes === 'function') { |
| | | vc.component.listMeterTypes(); |
| | | } |
| | | |
| | | // 加载抄表数据 |
| | | if (typeof vc.component._listMeterWaters === 'function') { |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 添加组件激活监听 |
| | | window.addEventListener('hashchange', () => { |
| | | if (window.location.hash.includes('meterWaterManage') && vc.component) { |
| | | console.log('组件激活,重新加载抄表数据'); |
| | | |
| | | // 加载表类型数据 |
| | | if (typeof vc.component.listMeterTypes === 'function') { |
| | | vc.component.listMeterTypes(); |
| | | } |
| | | |
| | | // 加载抄表数据 |
| | | if (typeof vc.component._listMeterWaters === 'function') { |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 添加全局刷新事件监听 |
| | | vc.on('globalRefresh', 'refreshData', function () { |
| | | if (vc.component) { |
| | | console.log('收到全局刷新事件,重新加载抄表数据'); |
| | | |
| | | // 加载表类型数据 |
| | | if (typeof vc.component.listMeterTypes === 'function') { |
| | | vc.component.listMeterTypes(); |
| | | } |
| | | |
| | | // 加载抄表数据 |
| | | if (typeof vc.component._listMeterWaters === 'function') { |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | } |
| | | } |
| | | }); |
| | | }, |
| | | _initEvent: function () { |
| | | // 房间选择事件 |
| | | vc.on('meterWaterManage', 'selectRoom', function (_param) { |
| | | $that.meterWaterManageInfo.conditions.objId = _param.roomId; |
| | | $that.meterWaterManageInfo.conditions.roomNum = ''; |
| | | $that.meterWaterManageInfo.roomName = _param.roomName; |
| | | $that._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | console.log('选择房间,加载对应抄表数据:', _param); |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | vc.component.meterWaterManageInfo.conditions.objId = _param.roomId; |
| | | vc.component.meterWaterManageInfo.conditions.roomNum = ''; |
| | | vc.component.meterWaterManageInfo.roomName = _param.roomName; |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | }); |
| | | vc.on('meterWaterManage', 'listMeterWater', function (_param) { |
| | | $that._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | |
| | | // 列表刷新事件 |
| | | vc.on('meterWaterManage', 'listMeterWater', function () { |
| | | console.log('收到列表刷新事件,重新加载抄表数据'); |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | }); |
| | | |
| | | // 分页事件 |
| | | vc.on('pagination', 'page_event', function (_currentPage) { |
| | | $that._listMeterWaters(_currentPage, DEFAULT_ROWS); |
| | | console.log('分页事件触发,页码:', _currentPage); |
| | | vc.component._listMeterWaters(_currentPage, DEFAULT_ROWS); |
| | | }); |
| | | |
| | | // 房间通知事件 |
| | | vc.on('meterWaterManage', 'notifyRoom', function (_room) { |
| | | $that.meterWaterManageInfo.conditions.roomNum = _room.floorNum + "-" + _room.unitNum + "-" + _room.roomNum; |
| | | $that._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | console.log('收到房间通知事件:', _room); |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | vc.component.meterWaterManageInfo.conditions.roomNum = _room.floorNum + "-" + _room.unitNum + "-" + _room.roomNum; |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | }); |
| | | |
| | | // 查询按钮点击事件 |
| | | document.addEventListener('click', (e) => { |
| | | if (e.target.textContent === '查询' || e.target.textContent === '重置') { |
| | | console.log('查询/重置按钮点击,重新加载抄表数据'); |
| | | if (vc.component && vc.component.meterWaterManageInfo) { |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 监听社区切换事件 |
| | | vc.on('communitySwitch', 'communitySwitched', function () { |
| | | console.log('社区切换,重新加载抄表数据'); |
| | | if (vc.component && vc.component.meterWaterManageInfo) { |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | } |
| | | }); |
| | | }, |
| | | methods: { |
| | | _listMeterWaters: function (_page, _rows) { |
| | | $that.meterWaterManageInfo.conditions.page = _page; |
| | | $that.meterWaterManageInfo.conditions.row = _rows; |
| | | $that.meterWaterManageInfo.conditions.communityId = vc.getCurrentCommunity().communityId; |
| | | let param = { |
| | | params: $that.meterWaterManageInfo.conditions |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | |
| | | console.log('===== 开始加载抄表数据 ====='); |
| | | console.log('发起抄表数据请求,页码:', _page, '行数:', _rows); |
| | | |
| | | // 获取社区信息 |
| | | let currentCommunity = vc.getCurrentCommunity(); |
| | | console.log('当前社区信息:', currentCommunity); |
| | | |
| | | if (!currentCommunity) { |
| | | console.error('当前社区信息为空'); |
| | | // 尝试直接从全局获取社区信息 |
| | | currentCommunity = window._currentCommunity; |
| | | console.log('尝试从全局获取社区信息:', currentCommunity); |
| | | } |
| | | |
| | | if (!currentCommunity || !currentCommunity.communityId) { |
| | | console.error('社区信息不存在或缺少communityId,1秒后重试'); |
| | | // 延迟重试 |
| | | setTimeout(() => { |
| | | if (vc.component && vc.component._listMeterWaters) { |
| | | vc.component._listMeterWaters(_page, _rows); |
| | | } |
| | | }, 1000); |
| | | return; |
| | | } |
| | | |
| | | // 输出当前条件值 |
| | | console.log('当前条件值:', vc.component.meterWaterManageInfo.conditions); |
| | | |
| | | // 构建请求参数 |
| | | let params = { |
| | | page: _page, |
| | | row: _rows, |
| | | communityId: currentCommunity.communityId, |
| | | waterId: vc.component.meterWaterManageInfo.conditions.waterId ? vc.component.meterWaterManageInfo.conditions.waterId.trim() : '', |
| | | meterType: vc.component.meterWaterManageInfo.conditions.meterType || '', |
| | | roomNum: vc.component.meterWaterManageInfo.conditions.roomNum ? vc.component.meterWaterManageInfo.conditions.roomNum.trim() : '' |
| | | }; |
| | | param.params.waterId = param.params.waterId.trim(); |
| | | param.params.roomNum = param.params.roomNum.trim(); |
| | | //发送get请求 |
| | | |
| | | // 只有当objId有值时才传递,否则不传递该参数 |
| | | // 当选择房间时,objId会被设置为房间ID,否则为空 |
| | | let objId = vc.component.meterWaterManageInfo.conditions.objId; |
| | | console.log('当前objId:', objId); |
| | | if (objId && objId.trim() !== '') { |
| | | params.objId = objId; |
| | | console.log('传递objId参数:', objId); |
| | | } else { |
| | | console.log('不传递objId参数'); |
| | | } |
| | | |
| | | let param = { |
| | | params: params |
| | | }; |
| | | |
| | | console.log('请求参数:', JSON.stringify(param)); |
| | | |
| | | // 发送请求 |
| | | vc.http.apiGet('/meterWater.listMeterWaters', |
| | | param, |
| | | function (json, res) { |
| | | let _json = JSON.parse(json); |
| | | $that.meterWaterManageInfo.total = _json.total; |
| | | $that.meterWaterManageInfo.records = _json.records; |
| | | $that.meterWaterManageInfo.meterWaters = _json.data; |
| | | vc.emit('pagination', 'init', { |
| | | total: $that.meterWaterManageInfo.records, |
| | | dataCount: $that.meterWaterManageInfo.total, |
| | | currentPage: _page |
| | | }); |
| | | function (jsonStr, res) { |
| | | console.log('收到API响应字符串:', jsonStr); |
| | | |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 检查jsonStr是否已经是对象 |
| | | let _json; |
| | | if (typeof jsonStr === 'string') { |
| | | // 如果是字符串,解析为JSON对象 |
| | | _json = JSON.parse(jsonStr); |
| | | console.log('解析后的API响应:', _json); |
| | | } else { |
| | | // 如果已经是对象,直接使用 |
| | | _json = jsonStr; |
| | | console.log('API响应已为对象:', _json); |
| | | } |
| | | |
| | | if (_json && _json.code == 0) { |
| | | // 确保 data 是数组 |
| | | let meterWatersData = _json.data || []; |
| | | if (!Array.isArray(meterWatersData)) { |
| | | console.error('API返回的data不是数组,转换为空数组'); |
| | | meterWatersData = []; |
| | | } |
| | | |
| | | console.log('准备显示的抄表数据:', meterWatersData); |
| | | console.log('抄表数据数量:', meterWatersData.length); |
| | | |
| | | // 直接赋值,确保数据更新 |
| | | vc.component.meterWaterManageInfo.meterWaters = meterWatersData; |
| | | // 处理API返回的total和records为0但实际有数据的情况 |
| | | vc.component.meterWaterManageInfo.total = _json.total > 0 ? _json.total : meterWatersData.length; |
| | | vc.component.meterWaterManageInfo.records = _json.records > 0 ? _json.records : meterWatersData.length; |
| | | |
| | | console.log('数据更新后,meterWaters数量:', vc.component.meterWaterManageInfo.meterWaters.length); |
| | | console.log('数据更新后,total:', vc.component.meterWaterManageInfo.total); |
| | | console.log('数据更新后,records:', vc.component.meterWaterManageInfo.records); |
| | | |
| | | // 初始化分页 |
| | | vc.emit('pagination', 'init', { |
| | | total: vc.component.meterWaterManageInfo.records, |
| | | dataCount: vc.component.meterWaterManageInfo.total, |
| | | currentPage: _page |
| | | }); |
| | | |
| | | // 强制DOM更新,确保数据显示 |
| | | // 通过重新赋值数组引用,触发Vue的响应式更新 |
| | | vc.component.meterWaterManageInfo.meterWaters = [...vc.component.meterWaterManageInfo.meterWaters]; |
| | | console.log('强制DOM更新后,meterWaters数量:', vc.component.meterWaterManageInfo.meterWaters.length); |
| | | |
| | | // 手动刷新footable表格,确保数据正确显示 |
| | | setTimeout(() => { |
| | | if (window.$ && typeof window.$.fn.footable === 'function') { |
| | | console.log('手动刷新footable表格'); |
| | | $('.footable').footable('refresh'); |
| | | } |
| | | }, 100); |
| | | } else { |
| | | console.error('API请求失败:', _json.msg || '未知错误'); |
| | | vc.component.meterWaterManageInfo.meterWaters = []; |
| | | vc.component.meterWaterManageInfo.total = 0; |
| | | vc.component.meterWaterManageInfo.records = 0; |
| | | } |
| | | } catch (e) { |
| | | console.error('处理API响应失败:', e, '原始数据:', jsonStr); |
| | | vc.component.meterWaterManageInfo.meterWaters = []; |
| | | vc.component.meterWaterManageInfo.total = 0; |
| | | vc.component.meterWaterManageInfo.records = 0; |
| | | } |
| | | |
| | | console.log('===== 抄表数据加载完成 ====='); |
| | | }, |
| | | function (errInfo, error) { |
| | | console.log('请求失败处理'); |
| | | function (errInfo) { |
| | | console.error('API请求异常:', errInfo); |
| | | |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | |
| | | vc.component.meterWaterManageInfo.meterWaters = []; |
| | | vc.component.meterWaterManageInfo.total = 0; |
| | | vc.component.meterWaterManageInfo.records = 0; |
| | | |
| | | console.log('===== 抄表数据加载异常 ====='); |
| | | } |
| | | ); |
| | | }, |
| | | _openAddMeterWaterModal: function () { |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | vc.emit('addMeterWater', 'openAddMeterWaterModal', { |
| | | roomId:$that.meterWaterManageInfo.conditions.objId, |
| | | roomName:$that.meterWaterManageInfo.roomName, |
| | | roomId: vc.component.meterWaterManageInfo.conditions.objId, |
| | | roomName: vc.component.meterWaterManageInfo.roomName, |
| | | ownerName:'' |
| | | }); |
| | | }, |
| | |
| | | }, |
| | | //查询 |
| | | _queryMeterWaterMethod: function () { |
| | | $that._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | }, |
| | | //重置 |
| | | _resetMeterWaterMethod: function () { |
| | | $that.meterWaterManageInfo.conditions.roomNum = ""; |
| | | $that.meterWaterManageInfo.conditions.meterType = ""; |
| | | $that.meterWaterManageInfo.conditions.waterId = ""; |
| | | $that._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | vc.component.meterWaterManageInfo.conditions.roomNum = ""; |
| | | vc.component.meterWaterManageInfo.conditions.meterType = ""; |
| | | vc.component.meterWaterManageInfo.conditions.waterId = ""; |
| | | vc.component._listMeterWaters(DEFAULT_PAGE, DEFAULT_ROWS); |
| | | }, |
| | | _moreCondition: function () { |
| | | if ($that.meterWaterManageInfo.moreCondition) { |
| | | $that.meterWaterManageInfo.moreCondition = false; |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | if (vc.component.meterWaterManageInfo.moreCondition) { |
| | | vc.component.meterWaterManageInfo.moreCondition = false; |
| | | } else { |
| | | $that.meterWaterManageInfo.moreCondition = true; |
| | | vc.component.meterWaterManageInfo.moreCondition = true; |
| | | } |
| | | }, |
| | | _openMeterWaterImport: function () { |
| | | vc.emit('importMeterWaterFee', 'openImportMeterWaterFeeModal', {}); |
| | | }, |
| | | _openMeterQrCode:function(){ |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | vc.emit('roomMeterQrcode', 'openRoomMeterQrcodeModal', { |
| | | roomId:$that.meterWaterManageInfo.conditions.objId, |
| | | roomName:$that.meterWaterManageInfo.roomName, |
| | | roomId: vc.component.meterWaterManageInfo.conditions.objId, |
| | | roomName: vc.component.meterWaterManageInfo.roomName, |
| | | ownerName:'' |
| | | }); |
| | | }, |
| | | |
| | | _getMeteTypeName: function (_meterType) { |
| | | if (_meterType == '1010') { |
| | | return "电表"; |
| | |
| | | } |
| | | return "煤气费"; |
| | | }, |
| | | |
| | | listMeterTypes: function () { |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | |
| | | // 获取社区信息 |
| | | let currentCommunity = vc.getCurrentCommunity(); |
| | | if (!currentCommunity || !currentCommunity.communityId) { |
| | | console.error('社区信息不存在,无法获取表类型'); |
| | | return; |
| | | } |
| | | |
| | | let param = { |
| | | params: { |
| | | page: 1, |
| | | row: 100, |
| | | communityId: vc.getCurrentCommunity().communityId |
| | | communityId: currentCommunity.communityId |
| | | } |
| | | }; |
| | | |
| | | //发送get请求 |
| | | vc.http.apiGet('/meterType.listMeterType', |
| | | param, |
| | | function (json, res) { |
| | | let _json = JSON.parse(json); |
| | | $that.meterWaterManageInfo.meterTypes = _json.data; |
| | | function (jsonStr, res) { |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 检查jsonStr是否已经是对象 |
| | | let _json; |
| | | if (typeof jsonStr === 'string') { |
| | | // 如果是字符串,解析为JSON对象 |
| | | _json = JSON.parse(jsonStr); |
| | | console.log('解析后的表类型API响应:', _json); |
| | | } else { |
| | | // 如果已经是对象,直接使用 |
| | | _json = jsonStr; |
| | | console.log('表类型API响应已为对象:', _json); |
| | | } |
| | | |
| | | vc.component.meterWaterManageInfo.meterTypes = _json.data || []; |
| | | console.log('表类型数据加载完成,数量:', vc.component.meterWaterManageInfo.meterTypes.length); |
| | | } catch (e) { |
| | | console.error('处理表类型API响应失败:', e, '原始数据:', jsonStr); |
| | | vc.component.meterWaterManageInfo.meterTypes = []; |
| | | } |
| | | }, |
| | | function (errInfo, error) { |
| | | console.log('请求失败处理'); |
| | | console.error('请求表类型失败:', errInfo, error); |
| | | vc.component.meterWaterManageInfo.meterTypes = []; |
| | | } |
| | | ); |
| | | }, |
| | | _meterInputRoom: function () { |
| | | if ($that.meterWaterManageInfo.timer) { |
| | | clearTimeout($that.meterWaterManageInfo.timer) |
| | | // 验证vc.component是否存在 |
| | | if (!vc.component || !vc.component.meterWaterManageInfo) { |
| | | console.error('组件实例不存在'); |
| | | return; |
| | | } |
| | | $that.meterWaterManageInfo.timer = setTimeout(() => { |
| | | if (vc.component.meterWaterManageInfo.timer) { |
| | | clearTimeout(vc.component.meterWaterManageInfo.timer) |
| | | } |
| | | vc.component.meterWaterManageInfo.timer = setTimeout(() => { |
| | | vc.emit('inputSearchRoomInfo', 'searchRoom', { |
| | | callComponent: 'meterWaterManage', |
| | | roomName: $that.meterWaterManageInfo.conditions.roomNum |
| | | roomName: vc.component.meterWaterManageInfo.conditions.roomNum |
| | | }); |
| | | }, 1500) |
| | | }, |