/** 编辑费用明细 **/ (function (vc) { var $that = {}; vc.extends({ data: { costDetailInfo: { costDetailId: '', flowCode: '', date: '', communityName: '', communityCode: '', projectContent: '', managementAmount: '', managementStamped: '1', committeeAmount: '', appraisalAmount: '', committeeStamped: '1', approvalDepartment: '', fundTypeLevel1: '', fundTypeLevel2: '', buildingType: '1', maintenanceType: '', fundType: 'repair', fundSystemType: 'out', ownerScope: [], buildingScope: [] }, ownerScopeOptions: [ '机动车停车库(位)', '小区道路', '交通附属设施', '非机动车车库(相朋)', '小区公共照明', '锅炉', '排水、排污设施', '消防系统', '安防设施', '公共景观绿化', '健身、游乐设施', '小区宣传、标识', '强电', '弱电', '通信设施', '公共用房', '平屋面', '楼栋外立面', '供电设施', '暖通系统', '供水系统', '通用设施(配件)' ], ownerScopeDropdownOpen: false, buildingScopeOptions: [ '机动车停车库(位)', '交通附属设施', '小区道路', '公共景观绿化', '非机动车车库(棚)', '锅炉', '排水、排污设施', '消防系统', '安防设施', '健身、游乐设施', '小区宣传、标识', '强电', '弱电', '通信设施', '公共用房', '平屋面', '太阳能设施', '坡屋面', '结构', '楼栋外立面', '楼幢入口', '楼幢公共', '楼道设施', '供电设施', '暖通系统', '供水系统', '通用设施(配件)', '法院强制执行' ], buildingScopeDropdownOpen: false }, _initMethod: function () { $that = vc.component; if (!$that.costDetailInfo) { $that.costDetailInfo = {}; } if (!$that.costDetailInfo.ownerScope || !Array.isArray($that.costDetailInfo.ownerScope)) { $that.costDetailInfo.ownerScope = []; } if (!$that.costDetailInfo.buildingScope || !Array.isArray($that.costDetailInfo.buildingScope)) { $that.costDetailInfo.buildingScope = []; } if (!$that.ownerScopeOptions || !Array.isArray($that.ownerScopeOptions)) { $that.ownerScopeOptions = [ '机动车停车库(位)', '小区道路', '交通附属设施', '非机动车车库(相朋)', '小区公共照明', '锅炉', '排水、排污设施', '消防系统', '安防设施', '公共景观绿化', '健身、游乐设施', '小区宣传、标识', '强电', '弱电', '通信设施', '公共用房', '平屋面', '楼栋外立面', '供电设施', '暖通系统', '供水系统', '通用设施(配件)' ]; } if ($that.ownerScopeDropdownOpen === undefined) { $that.ownerScopeDropdownOpen = false; } if (!$that.buildingScopeOptions || !Array.isArray($that.buildingScopeOptions)) { $that.buildingScopeOptions = [ '机动车停车库(位)', '交通附属设施', '小区道路', '公共景观绿化', '非机动车车库(棚)', '锅炉', '排水、排污设施', '消防系统', '安防设施', '健身、游乐设施', '小区宣传、标识', '强电', '弱电', '通信设施', '公共用房', '平屋面', '太阳能设施', '坡屋面', '结构', '楼栋外立面', '楼幢入口', '楼幢公共', '楼道设施', '供电设施', '暖通系统', '供水系统', '通用设施(配件)', '法院强制执行' ]; } if ($that.buildingScopeDropdownOpen === undefined) { $that.buildingScopeDropdownOpen = false; } var clickHandler = function (e) { if (!e.target.closest('.multi-select-wrapper')) { if ($that && $that.ownerScopeDropdownOpen !== undefined) { $that.ownerScopeDropdownOpen = false; } if ($that && $that.buildingScopeDropdownOpen !== undefined) { $that.buildingScopeDropdownOpen = false; } } }; setTimeout(function () { document.addEventListener('click', clickHandler); }, 100); var costDetailId = vc.getParam('costDetailId'); if (costDetailId) { $that.costDetailInfo.costDetailId = costDetailId; $that._loadCostDetail(); } else { vc.toast('缺少费用明细ID'); setTimeout(function () { vc.goBack(); }, 1500); } }, methods: { toggleOwnerScopeDropdown: function () { if ($that && $that.ownerScopeDropdownOpen !== undefined) { $that.ownerScopeDropdownOpen = !$that.ownerScopeDropdownOpen; } }, toggleOwnerScopeOption: function (option) { if (!$that || !$that.costDetailInfo || !$that.costDetailInfo.ownerScope) { return; } var index = $that.costDetailInfo.ownerScope.indexOf(option); if (index === -1) { $that.costDetailInfo.ownerScope.push(option); } else { $that.costDetailInfo.ownerScope.splice(index, 1); } }, removeOwnerScopeItem: function (index) { if ($that && $that.costDetailInfo && $that.costDetailInfo.ownerScope) { $that.costDetailInfo.ownerScope.splice(index, 1); } }, toggleBuildingScopeDropdown: function () { if ($that && $that.buildingScopeDropdownOpen !== undefined) { $that.buildingScopeDropdownOpen = !$that.buildingScopeDropdownOpen; } }, toggleBuildingScopeOption: function (option) { if (!$that || !$that.costDetailInfo || !$that.costDetailInfo.buildingScope) { return; } var index = $that.costDetailInfo.buildingScope.indexOf(option); if (index === -1) { $that.costDetailInfo.buildingScope.push(option); } else { $that.costDetailInfo.buildingScope.splice(index, 1); } }, removeBuildingScopeItem: function (index) { if ($that && $that.costDetailInfo && $that.costDetailInfo.buildingScope) { $that.costDetailInfo.buildingScope.splice(index, 1); } }, _loadCostDetail: function () { var params = { communityName: vc.getCurrentCommunity().name, page: 1, row: 1000 }; var param = { params: params }; console.log('开始加载费用明细,ID:', $that.costDetailInfo.costDetailId); vc.http.apiGet('/maintenancePayment/queryMaintenancePayment', param, function (json, res) { try { var _json = JSON.parse(json); console.log('API返回数据:', _json); if (_json.code === 0 && _json.data) { var records = Array.isArray(_json.data) ? _json.data : []; console.log('查询到记录数:', records.length); var foundItem = null; var targetId = String($that.costDetailInfo.costDetailId); for (var i = 0; i < records.length; i++) { var recordId = String(records[i].id); console.log('比较ID: 目标=' + targetId + ', 记录=' + recordId); if (recordId === targetId || records[i].id == $that.costDetailInfo.costDetailId) { foundItem = records[i]; console.log('找到匹配记录:', foundItem); break; } } if (foundItem) { $that._fillFormData(foundItem); console.log('表单数据已填充:', $that.costDetailInfo); } else { console.error('未找到匹配的记录,目标ID:', $that.costDetailInfo.costDetailId); vc.toast('未找到该费用明细,ID: ' + $that.costDetailInfo.costDetailId); setTimeout(function () { vc.goBack(); }, 1500); } } else { console.error('API返回错误:', _json); vc.toast('未找到该费用明细'); setTimeout(function () { vc.goBack(); }, 1500); } } catch (e) { console.error('数据解析失败:', e); vc.toast('数据解析失败: ' + e.message); } }, function (errInfo, error) { console.error('请求失败:', errInfo, error); vc.toast('请求失败,请检查网络连接'); } ); }, _fillFormData: function (item) { console.log('开始填充表单数据,原始数据:', item); var dateStr = ''; if (item.date) { dateStr = item.date.substring(0, 10); } else if (item.year && item.month) { var monthStr = item.month < 10 ? '0' + item.month : String(item.month); var dayStr = item.day ? (item.day < 10 ? '0' + item.day : String(item.day)) : '01'; dateStr = item.year + '-' + monthStr + '-' + dayStr; } vc.component.costDetailInfo.flowCode = item.flowNumber || ''; vc.component.costDetailInfo.date = dateStr; vc.component.costDetailInfo.communityName = item.projectName || ''; vc.component.costDetailInfo.communityCode = item.projectCode || ''; vc.component.costDetailInfo.projectContent = item.projectContent || ''; vc.component.costDetailInfo.managementAmount = item.managementOfficeAmount || ''; vc.component.costDetailInfo.managementStamped = (item.managementOfficeSeal === '是' || item.managementOfficeSeal === '1') ? '1' : '0'; vc.component.costDetailInfo.committeeAmount = item.ownersCommitteeAmount || ''; vc.component.costDetailInfo.appraisalAmount = item.auditAmount || ''; vc.component.costDetailInfo.committeeStamped = (item.ownersCommitteeSeal === '是' || item.ownersCommitteeSeal === '1') ? '1' : '0'; vc.component.costDetailInfo.approvalDepartment = item.reportDepartment || ''; if (item.fundTypeLevel1 === '维修资金') { vc.component.costDetailInfo.fundType = 'repair'; if (item.fundTypeLevel2) { vc.component.costDetailInfo.ownerScope = typeof item.fundTypeLevel2 === 'string' ? item.fundTypeLevel2.split(',').filter(function (item) { return item.trim(); }) : []; } else { vc.component.costDetailInfo.ownerScope = []; } if (item.buildingOrAll) { vc.component.costDetailInfo.buildingScope = typeof item.buildingOrAll === 'string' ? item.buildingOrAll.split(',').filter(function (item) { return item.trim(); }) : []; } else { vc.component.costDetailInfo.buildingScope = []; } vc.component.costDetailInfo.fundSystemType = 'out'; } else if (item.fundTypeLevel1 === '公共收益') { vc.component.costDetailInfo.fundType = 'public'; if (item.fundTypeLevel2 === '系统外') { vc.component.costDetailInfo.fundSystemType = 'out'; } else if (item.fundTypeLevel2 === '系统内') { vc.component.costDetailInfo.fundSystemType = 'in'; } else { vc.component.costDetailInfo.fundSystemType = 'out'; } vc.component.costDetailInfo.ownerScope = []; vc.component.costDetailInfo.buildingScope = []; } else { vc.component.costDetailInfo.fundType = 'repair'; vc.component.costDetailInfo.ownerScope = []; vc.component.costDetailInfo.buildingScope = []; vc.component.costDetailInfo.fundSystemType = 'out'; } vc.component.costDetailInfo.fundTypeLevel1 = item.fundTypeLevel1 || ''; vc.component.costDetailInfo.fundTypeLevel2 = item.fundTypeLevel2 || ''; var buildingType = item.buildingOrAll || '1'; if (buildingType === '全体' || buildingType === '2' || buildingType === 2) { vc.component.costDetailInfo.buildingType = '全体'; } else { if (buildingType && buildingType.indexOf(',') !== -1) { vc.component.costDetailInfo.buildingType = '1'; } else { vc.component.costDetailInfo.buildingType = buildingType || '1'; } } vc.component.costDetailInfo.maintenanceType = item.maintenanceType || ''; console.log('表单数据填充完成:', vc.component.costDetailInfo); }, _saveCostDetail: function () { if (!$that.costDetailInfo.flowCode) { vc.toast('请输入流转编码'); return; } if (!$that.costDetailInfo.date) { vc.toast('请选择日期'); return; } if (!$that.costDetailInfo.communityName) { vc.toast('请输入小区名称'); return; } if (!$that.costDetailInfo.communityCode) { vc.toast('请输入小区编码'); return; } var fundTypeLevel1 = ''; if ($that.costDetailInfo.fundType === 'repair') { fundTypeLevel1 = '维修资金'; } else if ($that.costDetailInfo.fundType === 'public') { fundTypeLevel1 = '公共收益'; } var fundTypeLevel2 = ''; var buildingOrAll = ''; if ($that.costDetailInfo.fundType === 'repair') { fundTypeLevel2 = ($that.costDetailInfo.ownerScope && $that.costDetailInfo.ownerScope.length > 0) ? $that.costDetailInfo.ownerScope.join(',') : ''; buildingOrAll = ($that.costDetailInfo.buildingScope && $that.costDetailInfo.buildingScope.length > 0) ? $that.costDetailInfo.buildingScope.join(',') : ''; } else if ($that.costDetailInfo.fundType === 'public') { if ($that.costDetailInfo.fundSystemType === 'out') { fundTypeLevel2 = '系统外'; } else if ($that.costDetailInfo.fundSystemType === 'in') { fundTypeLevel2 = '系统内'; } buildingOrAll = ''; } else { buildingOrAll = ''; } var saveData = { id: $that.costDetailInfo.costDetailId, flowNumber: $that.costDetailInfo.flowCode, date: $that.costDetailInfo.date, projectName: $that.costDetailInfo.communityName, projectCode: $that.costDetailInfo.communityCode, projectContent: $that.costDetailInfo.projectContent, managementOfficeAmount: parseFloat($that.costDetailInfo.managementAmount) || 0, managementOfficeSeal: $that.costDetailInfo.managementStamped === '1' ? '是' : '否', ownersCommitteeAmount: parseFloat($that.costDetailInfo.committeeAmount) || 0, auditAmount: parseFloat($that.costDetailInfo.appraisalAmount) || 0, ownersCommitteeSeal: $that.costDetailInfo.committeeStamped === '1' ? '是' : '否', reportDepartment: $that.costDetailInfo.approvalDepartment || '', fundTypeLevel1: fundTypeLevel1, fundTypeLevel2: fundTypeLevel2, maintenanceType: $that.costDetailInfo.maintenanceType || '', communityId: vc.getCurrentCommunity().communityId }; if ($that.costDetailInfo.fundType === 'repair') { saveData.buildingOrAll = buildingOrAll; } if (saveData.date) { var dateParts = saveData.date.split('-'); if (dateParts.length >= 2) { saveData.year = parseInt(dateParts[0]); saveData.month = parseInt(dateParts[1]); if (dateParts.length >= 3) { saveData.day = parseInt(dateParts[2]); } } } vc.http.apiPost('/maintenancePayment/updateMaintenancePayment', JSON.stringify(saveData), { emulateJSON: true }, function (json, res) { try { var _json = JSON.parse(json); if (_json.code === 0) { vc.toast('保存成功'); setTimeout(function () { vc.goBack(); }, 1000); } else { vc.toast(_json.msg || '保存失败'); } } catch (e) { vc.toast('保存失败'); } }, function (errInfo, error) { vc.toast('保存失败,请检查网络连接'); } ); }, _cancel: function () { vc.goBack(); } } }); })(window.vc);