(function (vc) { vc.extends({ data: { communityDetailInfo: { communityName: '', communityCode: '', provinceName: '', cityName: '', areaName: '', communityAddress: '', completionDate: '', takeTime: '', outTime: '', stateName: '', propertyType: '', propertyRoomArea: '', publicArea: '', communityType: '', area: '', totalArea: '', chargeableArea: '', multiStoreyArea: '', highStoreyArea1: '', highStoreyArea2: '', commercialArea: '', villaArea: '', officeArea: '', greenArea: '', residentialArea: '', nonResidentialArea: '', areaDetails: '', managementAddress: '', managementContactName: '', managementContactTel: '', managementContactDayTel: '', managementContactNightTel: '', managerName: '', managerTel: '', managerCert: '', managerCertName: '', managerCertNo: '', committeeName: '', committeeAddress: '', committeeSecretaryName: '', committeeSecretaryTel: '', committeeOfficeTel: '', committeeChairmanName: '', committeeChairmanTel: '', fireSprinklerTotal: '', fireChannelTotal: '', waterTankTotal: '', waterPoolTotal: '', elevatorTotal: '', elevatorType: '', elevatorInstallDate: '', elevatorUseYears: '', elevatorBrand1: '', monitorTotal: '', monitorMaintenanceUnit: '', gateTotal: '', gateBrand: '', gateSupplierContactName: '', gateSupplierContactTel: '', pumpTotal: '', garbageFixed: '', gateGuardTotal: '', carTotal: '', carGroundTotal: '', carUndergroundTotal: '', electricCarTotal: '', nonElectricCarTotal: '', nonElectricCarGroundArea: '', nonElectricCarUndergroundArea: '', clubArea: '', hourlyFee: '', dailyFee: '', onceFee: '', naturalBuildingTotal: '', doorBuildingTotal: '', highBuildingTotal: '', lowBuildingTotal: '', totalHousehold: '', residentialHousehold: '', commercialHousehold: '' } }, _initMethod: function () { // 确保 vc.component 已完全初始化后再调用 let retryCount = 0; const maxRetries = 20; // 最多重试20次(约1秒) const loadData = function() { if (vc.component && typeof vc.component._loadCommunityDetail === 'function') { vc.component._loadCommunityDetail(); } else { retryCount++; if (retryCount >= maxRetries) { console.error('无法找到 _loadCommunityDetail 方法,已重试', maxRetries, '次'); return; } // 如果还未初始化,等待一下再试 setTimeout(loadData, 50); } }; loadData(); }, _initEvent: function () { }, methods: { _loadCommunityDetail: function () { // 优先从 hash 中获取参数(单页应用使用 hash 路由) let _communityId = ''; const hash = location.hash; const search = location.search; // 先尝试从 hash 中获取 if (hash && hash.indexOf('?') !== -1) { const hashParams = hash.substring(hash.indexOf('?') + 1); const params = hashParams.split('&'); for (let i = 0; i < params.length; i++) { const param = params[i].split('='); if (param[0] === 'communityId') { _communityId = decodeURIComponent(param[1] || ''); break; } } } // 如果 hash 中没有,尝试从 search 中获取 if (!_communityId) { _communityId = vc.getParam('communityId') || ''; } console.log('获取到的 communityId:', _communityId, '当前 URL:', location.href, 'hash:', hash, 'search:', search); if (!_communityId) { console.warn('缺少communityId,无法加载小区详情'); return; } const param = { params: { page: 1, row: 1, communityId: _communityId } }; vc.http.apiGet( '/community.listCommunitys', param, function (json, res) { if (res.status !== 200) { return; } const data = JSON.parse(json); const communitys = data.data || data.communitys || []; if (!communitys.length) { console.warn('未获取到小区详情数据'); return; } const detail = vc.component._formatCommunityDetail(communitys[0]); vc.component.communityDetailInfo = Object.assign({}, vc.component.communityDetailInfo, detail); }, function (errInfo) { console.log('请求失败处理', errInfo); } ); }, _formatCommunityDetail: function (info) { if (!info) { return {}; } const totalHousehold = info.totalHousehold || (info.residentialHouseholdCount && info.shopHouseholdCount ? Number(info.residentialHouseholdCount || 0) + Number(info.shopHouseholdCount || 0) : ''); return { communityName: info.communityName || info.name || '', communityCode: info.communityCode || info.code || '', provinceName: info.projectAddressProvince || info.provinceName || '', cityName: info.projectAddressCity || info.cityName || '', areaName: info.projectAddressDistrict || info.areaName || '', communityAddress: [info.projectAddressTown, info.projectAddressRoad].filter(Boolean).join(' ') || info.communityAddress || '', completionDate: info.houseCompletionDate || info.completionDate || '', takeTime: info.takeTime || '', outTime: info.outTime || '', stateName: info.stateName || info.state || '', propertyType: info.projectNature || info.propertyType || '', propertyRoomArea: info.propertyRoomArea || '', publicArea: info.publicArea || '', communityType: info.projectType || info.communityType || '', area: info.projectLandArea || info.area || '', totalArea: info.totalConstructionArea || info.totalArea || '', chargeableArea: info.chargeableTotalArea || info.chargeableArea || '', multiStoreyArea: info.chargeableAreaMultilayer || info.multiStoreyArea || '', highStoreyArea1: info.chargeableAreaHighRise1 || info.highStoreyArea1 || '', highStoreyArea2: info.chargeableAreaHighRiseUp || info.highStoreyArea2 || '', commercialArea: info.chargeableAreaShop || info.chargeableAreaCommercialHouse || info.commercialArea || '', villaArea: info.chargeableAreaVilla || info.villaArea || '', officeArea: info.chargeableAreaOffice || info.officeArea || '', greenArea: info.greenArea || '', residentialArea: info.residentialArea || '', nonResidentialArea: info.nonResidentialArea || '', areaDetails: info.areaDetails || '', managementAddress: info.propertyManagementAddress || info.managementAddress || '', managementContactName: info.propertyManagerName || info.managementContactName || '', managementContactTel: info.propertyManagerPhone || info.managementContactTel || '', managementContactDayTel: info.dayRepairPhone || info.managementContactDayTel || '', managementContactNightTel: info.nightRepairPhone || info.managementContactNightTel || '', managerName: info.projectManager || info.managerName || '', managerTel: info.managerPhone || info.managerTel || '', hasManagerCertificate: info.hasManagerCertificate || info.hasManagerCertificate, managerCertName: info.certificateName || info.managerCertName || '', managerCertNo: info.managerCertificateNo || info.managerCertNo || '', committeeName: info.neighborhoodCommitteeName || info.committeeName || '', committeeAddress: info.neighborhoodCommitteeAddress || info.committeeAddress || '', committeeSecretaryName: info.neighborhoodSecretary || info.committeeSecretaryName || '', committeeSecretaryTel: info.secretaryPhone || info.committeeSecretaryTel || '', committeeOfficeTel: info.neighborhoodOfficePhone || info.committeeOfficeTel || '', committeeChairmanName: info.ownersCommitteeChairman || info.committeeChairmanName || '', committeeChairmanTel: info.chairmanPhone || info.committeeChairmanTel || '', fireSprinklerTotal: info.fireHydrantCount || info.fireSprinklerTotal || '', fireChannelTotal: info.fireChannelCount || info.fireChannelTotal || '', waterTankTotal: info.waterTankCount || info.waterTankTotal || '', waterPoolTotal: info.reservoirCount || info.waterPoolTotal || '', elevatorTotal: info.elevatorCount || info.elevatorTotal || '', elevatorType: info.elevatorType || '', elevatorInstallDate: info.elevatorInstallDate || '', elevatorUseYears: info.elevatorServiceLife || info.elevatorUseYears || '', elevatorBrand1: info.elevatorBrand1 || '', monitorTotal: info.monitorCount || info.monitorTotal || '', monitorMaintenanceUnit: info.monitorMaintenanceCompany || info.monitorMaintenanceUnit || '', gateTotal: info.barrierGateCount || info.gateTotal || '', gateBrand: info.barrierGateBrand || info.gateBrand || '', gateSupplierContactName: info.barrierSupplierContact || info.gateSupplierContactName || '', gateSupplierContactTel: info.barrierSupplierPhone || info.gateSupplierContactTel || '', pumpTotal: info.waterPumpCount || info.pumpTotal || '', hasDecorationRubbishPoint: info.hasDecorationRubbishPoint, gateGuardTotal: info.securityEntranceCount || info.gateGuardTotal || '', carTotal: info.totalMotorVehicleSpaces || info.carTotal || '', carGroundTotal: info.groundMotorVehicleSpaces || info.groundParkingSpaces || info.carGroundTotal || '', carUndergroundTotal: info.undergroundMotorVehicleSpaces || info.undergroundParkingSpaces || info.carUndergroundTotal || '', electricCarTotal: info.newEnergyChargingPiles || info.electricCarTotal || '', nonElectricCarTotal: info.nonMotorVehicleChargingPoints || info.nonElectricCarTotal || '', nonElectricCarGroundArea: info.groundNonMotorVehicleArea || info.nonElectricCarGroundArea || '', nonElectricCarUndergroundArea: info.undergroundNonMotorVehicleArea || info.nonElectricCarUndergroundArea || '', clubArea: info.clubhouseArea || info.clubArea || '', hourlyFee: info.temporaryHourlyFee || info.hourlyFee || '', dailyFee: info.temporaryDailyFee || info.dailyFee || '', onceFee: info.temporaryPerTimeFee || info.onceFee || '', naturalBuildingTotal: info.totalBuildingCount || info.naturalBuildingTotal || '', doorBuildingTotal: info.buildingUnitCount || info.doorBuildingTotal || '', highBuildingTotal: info.highRiseBuildingCount || info.highBuildingTotal || '', lowBuildingTotal: info.multilayerVillaBuildingCount || info.lowBuildingTotal || '', totalHousehold: totalHousehold, residentialHousehold: info.residentialHouseholdCount || info.residentialHousehold || '', commercialHousehold: info.shopHouseholdCount || info.commercialHousehold || '' }; }, goBack() { // 跳转回小区管理列表页 window.location.href = '/#/pages/common/communityManage'; }, } }); })(window.vc);