/** 费用明细表 **/ (function (vc) { var DEFAULT_PAGE = 1; var DEFAULT_ROWS = 15; var $that = {}; vc.extends({ data: { costDetailInfo: { costDetails: [], communityList: [], paginationInfo: { currentPage: 1, rows: DEFAULT_ROWS, total: 1, dataCount: 0, pageList: [] }, jumpPage: 1, conditions: { date: '', communityName: '', communityCode: '', communityId: vc.getCurrentCommunity().communityId, flowNumber: '', projectCode: '', year: '', projectName: '', _communityName: vc.getCurrentCommunity().name } }, importCostDetailInfo: { communityId: vc.getCurrentCommunity().communityId, excelTemplate: '' }, importStatus: { isImporting: false, progress: 0, message: '' } }, _initMethod: function () { $that = vc.component; $that.costDetailInfo.conditions.communityId = vc.getCurrentCommunity().communityId; $that.costDetailInfo.conditions._communityName = vc.getCurrentCommunity().name; $that._loadCommunityList(); $that._initDate(); }, _initEvent: function () { vc.on('costDetail', 'listCostDetail', function (_param) { $that._listCostDetails(DEFAULT_PAGE, DEFAULT_ROWS); }); }, methods: { _initDate: function () { }, _loadCommunityList: function () { var communityInfos = vc.getCommunitys(); if (communityInfos && Array.isArray(communityInfos) && communityInfos.length > 0) { $that.costDetailInfo.communityList = communityInfos; $that.costDetailInfo.conditions.communityName = communityInfos[0].name; } else { var currentCommunity = vc.getCurrentCommunity(); if (currentCommunity && currentCommunity.name) { $that.costDetailInfo.communityList = [currentCommunity]; $that.costDetailInfo.conditions.communityName = currentCommunity.name; } } $that._listCostDetails(DEFAULT_PAGE, DEFAULT_ROWS); }, _listCostDetails: function (_page, _rows) { var selectedCommunityName = $that.costDetailInfo.conditions.communityName || vc.getCurrentCommunity().name; var params = { communityName: selectedCommunityName, page: _page, row: _rows }; if ($that.costDetailInfo.conditions.flowNumber) { params.flowNumber = $that.costDetailInfo.conditions.flowNumber; } if ($that.costDetailInfo.conditions.projectCode) { params.projectCode = $that.costDetailInfo.conditions.projectCode; } if ($that.costDetailInfo.conditions.year) { params.year = parseInt($that.costDetailInfo.conditions.year); } if ($that.costDetailInfo.conditions.projectName) { params.projectName = $that.costDetailInfo.conditions.projectName; } var param = { params: params }; vc.http.apiGet('/maintenancePayment/queryMaintenancePayment', param, function (json, res) { try { var _json = JSON.parse(json); if (_json.code === 0 && _json.data) { var records = Array.isArray(_json.data) ? _json.data : []; var mappedRecords = records.map(function (item) { var dateStr = ''; if (item.date) { dateStr = item.date.substring(0, 7); } else if (item.year && item.month) { var monthStr = item.month < 10 ? '0' + item.month : String(item.month); dateStr = item.year + '-' + monthStr; } return { flowCode: item.flowNumber || '--', communityCode: item.projectCode || '--', communityName: item.projectName || '--', date: dateStr, projectContent: item.projectContent || '--', managementAmount: item.managementOfficeAmount || '--', managementStamped: item.managementOfficeSeal === '是' ? '1' : '0', committeeAmount: item.ownersCommitteeAmount || '--', appraisalAmount: item.auditAmount || '--', committeeStamped: item.ownersCommitteeSeal === '是' ? '1' : '0', approvalDepartment: item.reportDepartment || '--', fundTypeLevel1: item.fundTypeLevel1 || '--', fundTypeLevel2: item.fundTypeLevel2 || '--', buildingType: item.buildingOrAll || '--', maintenanceType: item.maintenanceType || '--', costDetailId: item.id, _originalData: item }; }); var total = _json.total || 0; var totalPages = _json.records || 1; $that.costDetailInfo.paginationInfo.dataCount = total; $that.costDetailInfo.paginationInfo.total = totalPages; $that.costDetailInfo.costDetails = mappedRecords; $that.costDetailInfo.paginationInfo.currentPage = _page; $that._freshPageList(); } else { console.error('接口返回错误:', _json.msg || '未知错误', _json); vc.toast(_json.msg || '查询失败'); $that.costDetailInfo.costDetails = []; $that.costDetailInfo.paginationInfo.dataCount = 0; $that.costDetailInfo.paginationInfo.total = 1; $that._freshPageList(); } } catch (e) { vc.toast('数据解析失败'); $that.costDetailInfo.costDetails = []; $that.costDetailInfo.paginationInfo.dataCount = 0; $that.costDetailInfo.paginationInfo.total = 1; $that._freshPageList(); } }, function (errInfo, error) { vc.toast('请求失败,请检查网络连接'); $that.costDetailInfo.costDetails = []; $that.costDetailInfo.paginationInfo.dataCount = 0; $that.costDetailInfo.paginationInfo.total = 1; $that._freshPageList(); } ); }, _freshPageList: function () { var currentPage = $that.costDetailInfo.paginationInfo.currentPage; var total = $that.costDetailInfo.paginationInfo.total; var pageList = []; if (total <= 7) { for (var i = 1; i <= total; i++) { pageList.push({ page: i, pageView: i, currentPage: i == currentPage }); } } else { if (currentPage <= 4) { for (var i = 1; i <= 5; i++) { pageList.push({ page: i, pageView: i, currentPage: i == currentPage }); } pageList.push({ page: 0, pageView: '...', currentPage: false }); pageList.push({ page: total, pageView: total, currentPage: false }); } else if (currentPage >= total - 3) { pageList.push({ page: 1, pageView: 1, currentPage: false }); pageList.push({ page: 0, pageView: '...', currentPage: false }); for (var i = total - 4; i <= total; i++) { pageList.push({ page: i, pageView: i, currentPage: i == currentPage }); } } else { pageList.push({ page: 1, pageView: 1, currentPage: false }); pageList.push({ page: 0, pageView: '...', currentPage: false }); for (var i = currentPage - 1; i <= currentPage + 1; i++) { pageList.push({ page: i, pageView: i, currentPage: i == currentPage }); } pageList.push({ page: 0, pageView: '...', currentPage: false }); pageList.push({ page: total, pageView: total, currentPage: false }); } } $that.costDetailInfo.paginationInfo.pageList = pageList; }, _queryCostDetails: function () { $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows); }, _resetQuery: function () { if ($that.costDetailInfo.communityList && $that.costDetailInfo.communityList.length > 0) { $that.costDetailInfo.conditions.communityName = $that.costDetailInfo.communityList[0].name; } else { $that.costDetailInfo.conditions.communityName = ''; } $that.costDetailInfo.conditions.communityCode = ''; $that.costDetailInfo.conditions.flowNumber = ''; $that.costDetailInfo.conditions.projectCode = ''; $that.costDetailInfo.conditions.year = ''; $that.costDetailInfo.conditions.projectName = ''; $('.queryDate').val(''); $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows); }, _changePageSize: function () { $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows); }, _goToPage: function (_page) { if (!_page || _page < 1 || _page > $that.costDetailInfo.paginationInfo.total) { return; } $that._listCostDetails(_page, $that.costDetailInfo.paginationInfo.rows); }, _jumpToPage: function () { var page = parseInt($that.costDetailInfo.jumpPage); if (isNaN(page) || page < 1) { page = 1; } if (page > $that.costDetailInfo.paginationInfo.total) { page = $that.costDetailInfo.paginationInfo.total; } $that._listCostDetails(page, $that.costDetailInfo.paginationInfo.rows); }, /** * 下载导入模板 * 功能:提供费用导入模板的下载 * 实现:创建临时下载链接并触发点击 */ _downloadTemplate: function () { try { // 创建下载链接 var link = document.createElement('a'); // 模板路径,可根据需要从配置或后端获取 var templatePath = '/import/费用导入模板.xlsx'; var templateName = '费用导入模板.xlsx'; link.href = templatePath; link.download = templateName; link.style.display = 'none'; document.body.appendChild(link); link.click(); document.body.removeChild(link); vc.toast('模板下载中,请稍候...'); } catch (e) { console.error('模板下载失败:', e); vc.toast('模板下载失败,请重试'); } }, /** * 打开费用明细导入弹窗 * 功能:控制导入弹窗的显示 * 触发:点击页面上的"费用导入"按钮 */ _openImportModal: function () { $that.clearImportInfo(); $('#importCostDetailModal').modal('show'); }, importCostDetailValidate() { return vc.validate.validate({ importCostDetailInfo: $that.importCostDetailInfo }, { 'importCostDetailInfo.communityId': [{ limit: "required", param: "", errInfo: "数据异常还没有入驻小区" }], 'importCostDetailInfo.excelTemplate': [{ limit: "required", param: "", errInfo: "文件不能为空" }] }); }, getExcelTemplate: function(e) { $that.importCostDetailInfo.excelTemplate = e.target.files[0]; }, _importData: function() { try { if (!$that.importCostDetailValidate()) { vc.toast(vc.validate.errInfo); return; } // 导入数据 if (!$that.importCostDetailInfo.excelTemplate) { vc.toast('请选择要导入的文件'); return; } const fileExtension = $that.importCostDetailInfo.excelTemplate.name.split('.').pop(); if (!fileExtension || !$that.checkOwnerFileType(fileExtension)) { vc.toast('不是有效的Excel格式,请选择.xlsx或.xls文件'); return; } if (!$that.checkOwnerFileSize($that.importCostDetailInfo.excelTemplate.size)) { vc.toast('Excel文件大小不能超过20M'); return; } // 设置导入状态 $that.importStatus = { isImporting: true, progress: 0, message: '正在准备导入...' }; // 模拟进度更新 let progressInterval = setInterval(function() { if ($that.importStatus.progress < 90) { $that.importStatus.progress += 10; $that.importStatus.message = '导入中... ' + $that.importStatus.progress + '%'; } }, 500); var param = new FormData(); param.append("uploadFile", $that.importCostDetailInfo.excelTemplate); param.append('communityId', $that.importCostDetailInfo.communityId); // 导入适配参数,用于后端识别导入类型 // importReportMainV2:费用明细报表导入 param.append('importAdapt', "importReportMainV2"); param.append('userId', vc.getData('/userInfo/userId') || ''); // 添加导入来源标记,便于后端统计和分析 param.append('importSource', 'costDetailReport'); vc.http.upload( 'assetImport', 'importData', param, { emulateJSON: true, headers: { "Content-Type": "multipart/form-data" } }, function(json, res) { // 清除进度更新 clearInterval(progressInterval); $that.importStatus.progress = 100; $that.importStatus.message = '导入完成'; try { let _json = JSON.parse(json); if (_json.code == 0) { //关闭modal $('#importCostDetailModal').modal('hide'); $that.clearImportInfo(); vc.toast(_json.msg || '导入成功'); // 跳转到导入日志详情页面 if (_json.data && _json.data.logId) { vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _json.data.logId + '&logType=importReportMainV2'); } else { // 刷新费用明细列表 $that._listCostDetails($that.costDetailInfo.paginationInfo.currentPage, $that.costDetailInfo.paginationInfo.rows); } // 重置导入状态 setTimeout(function() { $that.importStatus = { isImporting: false, progress: 0, message: '' }; }, 1000); return; } vc.toast(_json.msg || '导入失败', 10000); // 重置导入状态 $that.importStatus = { isImporting: false, progress: 0, message: '' }; } catch (e) { console.error('导入响应解析失败:', e); vc.toast('导入响应解析失败,请重试', 10000); // 重置导入状态 $that.importStatus = { isImporting: false, progress: 0, message: '' }; } }, function(errInfo, error) { // 清除进度更新 clearInterval(progressInterval); console.error('导入请求失败:', errInfo, error); vc.toast(errInfo || '导入失败,请检查网络连接', 10000); // 重置导入状态 $that.importStatus = { isImporting: false, progress: 0, message: '' }; } ); } catch (e) { console.error('导入过程发生异常:', e); vc.toast('导入过程发生异常,请重试', 10000); // 重置导入状态 $that.importStatus = { isImporting: false, progress: 0, message: '' }; } }, /** * 清空导入表单信息 * 功能:重置导入表单的所有字段 * 调用时机:打开导入弹窗前和导入完成后 */ clearImportInfo: function() { $that.importCostDetailInfo = { communityId: vc.getCurrentCommunity().communityId, excelTemplate: '' }; }, /** * 查看导入历史记录 * 功能:跳转到导入历史记录页面 * 实现:跳转到资产导入日志列表页面,带上费用明细导入的筛选条件 */ _viewImportHistory: function() { try { // 跳转到导入日志列表页面,筛选费用明细导入记录 vc.jumpToPage('/#/pages/property/assetImportLog?logType=importReportMainV2&source=costDetailReport'); } catch (e) { console.error('跳转到导入历史页面失败:', e); vc.toast('跳转到导入历史页面失败,请重试'); } }, checkOwnerFileType: function(fileType) { const acceptTypes = ['xlsx', 'xls']; for (var i = 0; i < acceptTypes.length; i++) { if (fileType === acceptTypes[i]) { return true; } } return false; }, checkOwnerFileSize: function(fileSize) { //20M const MAX_SIZE = 20 * 1024 * 1024; if (fileSize > MAX_SIZE) { return false; } return true; }, _addCostDetail: function () { vc.jumpToPage('/#/pages/property/costDetail/add'); }, _viewCostDetail: function (_item) { vc.jumpToPage('/#/pages/property/costDetail/detail?costDetailId=' + _item.costDetailId); }, _viewMore: function (_item) { vc.jumpToPage('/#/pages/property/costDetail/more?costDetailId=' + _item.costDetailId); }, _editCostDetail: function (_item) { vc.jumpToPage('/#/pages/property/costDetail/edit?costDetailId=' + _item.costDetailId); }, _deleteCostDetail: function (_item) { if (!_item || !_item.costDetailId) { vc.toast('删除失败:缺少必要的数据'); return; } if (typeof vc.confirm === 'function') { vc.confirm('确定要删除这条费用明细吗?', function () { var param = { id: _item.costDetailId, communityId: vc.getCurrentCommunity().communityId }; vc.http.apiPost('/maintenancePayment/deleteMaintenancePayment', JSON.stringify(param), { headers: { 'Content-Type': 'application/json' } }, function (json, res) { try { var _json = JSON.parse(json); if (_json.code === 0 || _json.code === '0') { vc.toast(_json.msg || '删除成功'); $that._listCostDetails($that.costDetailInfo.paginationInfo.currentPage, $that.costDetailInfo.paginationInfo.rows); } else { vc.toast(_json.msg || '删除失败'); } } catch (e) { console.error('删除响应解析失败:', e); vc.toast('删除失败,请重试'); } }, function (errInfo, error) { console.error('删除请求失败:', errInfo, error); vc.toast(errInfo || '删除失败,请检查网络连接'); } ); }); } else { if (window.confirm('确定要删除这条费用明细吗?')) { var param = { id: _item.costDetailId, communityId: vc.getCurrentCommunity().communityId }; vc.http.apiPost('/maintenancePayment/deleteMaintenancePayment', JSON.stringify(param), { headers: { 'Content-Type': 'application/json' } }, function (json, res) { try { var _json = JSON.parse(json); if (_json.code === 0 || _json.code === '0') { vc.toast(_json.msg || '删除成功'); $that._listCostDetails($that.costDetailInfo.paginationInfo.currentPage, $that.costDetailInfo.paginationInfo.rows); } else { vc.toast(_json.msg || '删除失败'); } } catch (e) { console.error('删除响应解析失败:', e); vc.toast('删除失败,请重试'); } }, function (errInfo, error) { console.error('删除请求失败:', errInfo, error); vc.toast(errInfo || '删除失败,请检查网络连接'); } ); } } } } }); })(window.vc);