/** 费用明细表 **/ (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 } } }, _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 () { vc.toast('模板下载功能'); }, _importCostDetail: function () { vc.toast('费用导入功能'); }, _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);