|
(function (vc) {
|
vc.extends({
|
data: {
|
formData: {
|
communityId: '',
|
newBId: '',
|
feePrice: '',
|
projectAddressProvince: '',
|
projectAddressCity: '',
|
projectAddressDistrict: '',
|
address: '',
|
projectAddressTown: '',
|
projectAddressRoad: '',
|
cityCode: '',
|
areaAddress: '',
|
houseCompletionDate: '',
|
projectNature: '',
|
projectType: '',
|
projectLandArea: '',
|
propertyRoomArea: '',
|
publicArea: '',
|
totalConstructionArea: '',
|
chargeableTotalArea: '',
|
chargeableAreaMultilayer: '',
|
chargeableAreaHighRise1: '',
|
chargeableAreaHighRiseUp: '',
|
chargeableAreaShop: '',
|
chargeableAreaVilla: '',
|
chargeableAreaOffice: '',
|
chargeableAreaCommercialHouse: '',
|
greenArea: '',
|
areaDetails: '',
|
propertyManagementAddress: '',
|
propertyManagerName: '',
|
propertyManagerPhone: '',
|
dayRepairPhone: '',
|
nightRepairPhone: '',
|
projectManager: '',
|
hasManagerCertificate: '',
|
certificateName: '',
|
managerCertificateNo: '',
|
managerPhone: '',
|
neighborhoodCommitteeName: '',
|
neighborhoodCommitteeAddress: '',
|
neighborhoodSecretary: '',
|
neighborhoodOfficePhone: '',
|
secretaryPhone: '',
|
ownersCommitteeAddress: '',
|
ownersCommitteeChairman: '',
|
chairmanPhone: '',
|
fireHydrantCount: '',
|
fireChannelCount: '',
|
waterTankCount: '',
|
reservoirCount: '',
|
totalMotorVehicleSpaces: '',
|
groundMotorVehicleSpaces: '',
|
undergroundMotorVehicleSpaces: '',
|
newEnergyChargingPiles: '',
|
nonMotorVehicleChargingPoints: '',
|
groundNonMotorVehicleArea: '',
|
undergroundNonMotorVehicleArea: '',
|
clubhouseArea: '',
|
hasDecorationRubbishPoint: '',
|
securityEntranceCount: '',
|
elevatorCount: '',
|
elevatorType: '',
|
elevatorInstallDate: '',
|
elevatorServiceLife: '',
|
elevatorBrand1: '',
|
elevatorBrand2: '',
|
monitorCount: '',
|
monitorMaintenanceCompany: '',
|
barrierGateCount: '',
|
barrierGateBrand: '',
|
barrierSupplierContact: '',
|
barrierSupplierPhone: '',
|
waterPumpCount: '',
|
groundParkingSpaces: '',
|
undergroundParkingSpaces: '',
|
groundNonMechanicalFee: '',
|
garageNonMechanicalFee: '',
|
temporaryHourlyFee: '',
|
temporaryDailyFee: '',
|
temporaryPerTimeFee: '',
|
totalBuildingCount: '',
|
buildingUnitCount: '',
|
highRiseBuildingCount: '',
|
multilayerVillaBuildingCount: '',
|
residentialHouseholdCount: '',
|
shopHouseholdCount: '',
|
takeTime: '',
|
outTime: '',
|
name: '',
|
communityCode: '',
|
state: '1100'
|
},
|
provs: [],
|
citys: [],
|
areas: [],
|
selectProv: '',
|
selectCity: '',
|
selectArea: '',
|
selectProvName: '',
|
selectCityName: '',
|
selectAreaName: ''
|
},
|
_initMethod: function () {
|
// 初始化省份
|
vc.component._initArea('101', '0');
|
// 确保 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 () {
|
// 初始化时添加输入事件监听,自动移除错误样式
|
const $that = this;
|
setTimeout(function() {
|
// 为所有输入框和选择框添加输入事件监听
|
const inputs = document.querySelectorAll('.community-add input, .community-add select');
|
inputs.forEach(function(input) {
|
input.addEventListener('input', function() {
|
$that.removeError(input.id);
|
});
|
input.addEventListener('change', function() {
|
$that.removeError(input.id);
|
});
|
});
|
}, 100);
|
},
|
methods: {
|
// 添加错误样式
|
addError: function(elementId) {
|
const element = document.getElementById(elementId);
|
if (element) {
|
element.classList.add('error');
|
}
|
},
|
// 移除错误样式
|
removeError: function(elementId) {
|
const element = document.getElementById(elementId);
|
if (element) {
|
element.classList.remove('error');
|
}
|
},
|
// 清除所有错误样式
|
clearAllErrors: function() {
|
const elements = document.querySelectorAll('.community-add input.error, .community-add select.error');
|
elements.forEach(function(element) {
|
element.classList.remove('error');
|
});
|
},
|
chooseProvince: function(event) {
|
const provCode = event.target.value;
|
vc.component.selectProv = provCode;
|
vc.component.selectCity = '';
|
vc.component.selectArea = '';
|
vc.component.citys = [];
|
vc.component.areas = [];
|
if (vc.component.provs && vc.component.provs.length > 0) {
|
vc.component.provs.forEach(function(_param) {
|
if (_param.areaCode == provCode) {
|
vc.component.selectProvName = _param.areaName;
|
vc.component.formData.projectAddressProvince = _param.areaName;
|
}
|
});
|
}
|
vc.component.formData.projectAddressCity = '';
|
vc.component.formData.projectAddressDistrict = '';
|
if (provCode) {
|
vc.component._initArea('202', provCode);
|
}
|
},
|
chooseCity: function(event) {
|
const cityCode = event.target.value;
|
vc.component.selectCity = cityCode;
|
vc.component.selectArea = '';
|
vc.component.areas = [];
|
if (vc.component.citys && vc.component.citys.length > 0) {
|
vc.component.citys.forEach(function(_param) {
|
if (_param.areaCode == cityCode) {
|
vc.component.selectCityName = _param.areaName;
|
vc.component.formData.projectAddressCity = _param.areaName;
|
}
|
});
|
}
|
vc.component.formData.projectAddressDistrict = '';
|
if (cityCode) {
|
vc.component._initArea('303', cityCode);
|
}
|
},
|
chooseArea: function(event) {
|
const areaCode = event.target.value;
|
vc.component.selectArea = areaCode;
|
vc.component.formData.cityCode = areaCode;
|
vc.component.formData.areaAddress = '';
|
if (vc.component.provs && vc.component.provs.length > 0) {
|
vc.component.provs.forEach(function(_param) {
|
if (_param.areaCode == vc.component.selectProv) {
|
vc.component.selectProvName = _param.areaName;
|
vc.component.formData.areaAddress = _param.areaName;
|
}
|
});
|
}
|
if (vc.component.citys && vc.component.citys.length > 0) {
|
vc.component.citys.forEach(function(_param) {
|
if (_param.areaCode == vc.component.selectCity) {
|
vc.component.selectCityName = _param.areaName;
|
if (vc.component.formData.areaAddress) {
|
vc.component.formData.areaAddress += _param.areaName;
|
} else {
|
vc.component.formData.areaAddress = _param.areaName;
|
}
|
}
|
});
|
}
|
if (vc.component.areas && vc.component.areas.length > 0) {
|
vc.component.areas.forEach(function(_param) {
|
if (_param.areaCode == vc.component.selectArea) {
|
vc.component.selectAreaName = _param.areaName;
|
vc.component.formData.projectAddressDistrict = _param.areaName;
|
if (vc.component.formData.areaAddress) {
|
vc.component.formData.areaAddress += _param.areaName;
|
} else {
|
vc.component.formData.areaAddress = _param.areaName;
|
}
|
}
|
});
|
}
|
},
|
_initArea: function(_areaLevel, _parentAreaCode) {
|
var _param = {
|
params: {
|
areaLevel: _areaLevel,
|
parentAreaCode: _parentAreaCode
|
}
|
};
|
vc.http.apiGet('/area.listAreas',
|
_param,
|
function (json, res) {
|
if (res.status == 200) {
|
var _tmpAreas = JSON.parse(json).areas;
|
if (_areaLevel == '101') {
|
vc.component.provs = _tmpAreas;
|
const provinceSelect = document.getElementById('province');
|
if (provinceSelect) {
|
_tmpAreas.forEach(function(item) {
|
const option = document.createElement('option');
|
option.value = item.areaCode;
|
option.textContent = item.areaName;
|
provinceSelect.appendChild(option);
|
});
|
}
|
} else if (_areaLevel == '202') {
|
vc.component.citys = _tmpAreas;
|
const citySelect = document.getElementById('city');
|
if (citySelect) {
|
citySelect.innerHTML = '<option value="">请选择市</option>';
|
_tmpAreas.forEach(function(item) {
|
const option = document.createElement('option');
|
option.value = item.areaCode;
|
option.textContent = item.areaName;
|
citySelect.appendChild(option);
|
});
|
}
|
} else {
|
vc.component.areas = _tmpAreas;
|
const areaSelect = document.getElementById('area');
|
if (areaSelect) {
|
areaSelect.innerHTML = '<option value="">请选择区</option>';
|
_tmpAreas.forEach(function(item) {
|
const option = document.createElement('option');
|
option.value = item.areaCode;
|
option.textContent = item.areaName;
|
areaSelect.appendChild(option);
|
});
|
}
|
}
|
return;
|
}
|
},
|
function (errInfo, error) {
|
console.log('请求失败处理', errInfo);
|
vc.toast('查询地区失败');
|
});
|
},
|
_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,无法加载小区详情');
|
vc.toast('缺少小区ID参数');
|
return;
|
}
|
vc.component.formData.communityId = _communityId;
|
const param = {
|
params: {
|
page: 1,
|
row: 1,
|
communityId: _communityId
|
}
|
};
|
vc.http.apiGet(
|
'/community.listCommunitys',
|
param,
|
function (json, res) {
|
if (res.status !== 200) {
|
vc.toast('获取小区信息失败');
|
return;
|
}
|
const data = JSON.parse(json);
|
const communitys = data.data || data.communitys || [];
|
if (!communitys.length) {
|
console.warn('未获取到小区详情数据');
|
vc.toast('未找到小区信息');
|
return;
|
}
|
const detail = vc.component._formatCommunityData(communitys[0]);
|
vc.component.formData = Object.assign({}, vc.component.formData, detail);
|
vc.component.formData.state = detail.state || (detail.outTime ? '1400' : '1100');
|
vc.component._prefillArea(detail);
|
},
|
function (errInfo) {
|
console.log('请求失败处理', errInfo);
|
vc.toast('获取小区信息失败');
|
}
|
);
|
},
|
_prefillArea: function(detail) {
|
if (!detail) {
|
return;
|
}
|
// 优先使用 cityCode(行政区编码,如310115 -> 省:310000,市:310100,区:310115)
|
const areaCode = detail.cityCode || '';
|
if (areaCode && areaCode.length >= 6) {
|
const provCode = areaCode.substring(0, 2) + '0000';
|
const cityCode = areaCode.substring(0, 4) + '00';
|
vc.component.selectProv = provCode;
|
vc.component.selectCity = cityCode;
|
vc.component.selectArea = areaCode;
|
// 先加载市,再加载区
|
vc.component._initArea('202', provCode);
|
vc.component._initArea('303', cityCode);
|
} else {
|
// 如果没有 cityCode,则根据接口返回的省市区名称匹配下拉选项
|
// 这里地区数据是异步加载的,因此采用重试方式,直到匹配成功或达到最大次数
|
let retry = 0;
|
const maxRetry = 20;
|
const matchAreaByName = function() {
|
const provName = detail.projectAddressProvince || '';
|
const cityName = detail.projectAddressCity || '';
|
const districtName = detail.projectAddressDistrict || '';
|
|
// 1. 匹配省
|
if (provName && !vc.component.selectProv && vc.component.provs && vc.component.provs.length > 0) {
|
const prov = vc.component.provs.find(p => p.areaName === provName);
|
if (prov) {
|
vc.component.selectProv = prov.areaCode;
|
vc.component.selectProvName = prov.areaName;
|
vc.component.formData.projectAddressProvince = prov.areaName;
|
// 加载市列表
|
vc.component._initArea('202', prov.areaCode);
|
}
|
}
|
|
// 2. 匹配市
|
if (cityName && vc.component.selectProv && !vc.component.selectCity &&
|
vc.component.citys && vc.component.citys.length > 0) {
|
const city = vc.component.citys.find(c => c.areaName === cityName);
|
if (city) {
|
vc.component.selectCity = city.areaCode;
|
vc.component.selectCityName = city.areaName;
|
vc.component.formData.projectAddressCity = city.areaName;
|
// 加载区列表
|
vc.component._initArea('303', city.areaCode);
|
}
|
}
|
|
// 3. 匹配区
|
if (districtName && vc.component.selectCity && !vc.component.selectArea &&
|
vc.component.areas && vc.component.areas.length > 0) {
|
const area = vc.component.areas.find(a => a.areaName === districtName);
|
if (area) {
|
vc.component.selectArea = area.areaCode;
|
vc.component.selectAreaName = area.areaName;
|
vc.component.formData.projectAddressDistrict = area.areaName;
|
vc.component.formData.cityCode = area.areaCode;
|
}
|
}
|
|
// 如果还没有完整匹配到区,并且未超过重试次数,则继续重试
|
if ((!vc.component.selectArea || !vc.component.formData.cityCode) && retry < maxRetry) {
|
retry++;
|
setTimeout(matchAreaByName, 100);
|
}
|
};
|
matchAreaByName();
|
}
|
// 补齐名称(用于提交,防止接口有值但上面未覆盖)
|
vc.component.formData.projectAddressProvince = detail.projectAddressProvince || vc.component.formData.projectAddressProvince;
|
vc.component.formData.projectAddressCity = detail.projectAddressCity || vc.component.formData.projectAddressCity;
|
vc.component.formData.projectAddressDistrict = detail.projectAddressDistrict || vc.component.formData.projectAddressDistrict;
|
},
|
_formatCommunityData: function (info) {
|
if (!info) {
|
return {};
|
}
|
// 将可能的布尔/数字/字符串值转换为 'true' / 'false' / ''
|
const toBoolString = function (val, fallback) {
|
if (val === true || val === 'true' || val === 1 || val === '1') {
|
return 'true';
|
}
|
if (val === false || val === 'false' || val === 0 || val === '0') {
|
return 'false';
|
}
|
return fallback;
|
};
|
return {
|
communityId: info.communityId || '',
|
newBId: info.newBId || '',
|
feePrice: info.feePrice || '',
|
projectAddressProvince: info.projectAddressProvince || '',
|
projectAddressCity: info.projectAddressCity || '',
|
projectAddressDistrict: info.projectAddressDistrict || info.areaName || '',
|
projectAddressTown: info.projectAddressTown || '',
|
projectAddressRoad: info.projectAddressRoad || '',
|
address: [info.projectAddressTown, info.projectAddressRoad].filter(Boolean).join(' ') || info.communityAddress || '',
|
nearbyLandmarks: '1',
|
houseCompletionDate: info.houseCompletionDate || info.completionDate || '',
|
projectNature: info.projectNature || info.propertyType || '',
|
projectType: info.projectType || info.communityType || '',
|
projectLandArea: info.projectLandArea || info.area || '',
|
propertyRoomArea: info.propertyRoomArea || '',
|
publicArea: info.publicArea || '',
|
totalConstructionArea: info.totalConstructionArea || info.totalArea || '',
|
chargeableTotalArea: info.chargeableTotalArea || info.chargeableArea || '',
|
chargeableAreaMultilayer: info.chargeableAreaMultilayer || info.multiStoreyArea || '',
|
chargeableAreaHighRise1: info.chargeableAreaHighRise1 || info.highStoreyArea1 || '',
|
chargeableAreaHighRiseUp: info.chargeableAreaHighRiseUp || info.highStoreyArea2 || '',
|
chargeableAreaShop: info.chargeableAreaShop || info.commercialArea || '',
|
chargeableAreaVilla: info.chargeableAreaVilla || info.villaArea || '',
|
chargeableAreaOffice: info.chargeableAreaOffice || info.officeArea || '',
|
chargeableAreaCommercialHouse: info.chargeableAreaCommercialHouse || '',
|
greenArea: info.greenArea || '',
|
areaDetails: info.areaDetails || '',
|
propertyManagementAddress: info.propertyManagementAddress || info.managementAddress || '',
|
propertyManagerName: info.propertyManagerName || info.managementContactName || '',
|
propertyManagerPhone: info.propertyManagerPhone || info.managementContactTel || '',
|
dayRepairPhone: info.dayRepairPhone || info.managementContactDayTel || '',
|
nightRepairPhone: info.nightRepairPhone || info.managementContactNightTel || '',
|
projectManager: info.projectManager || info.managerName || '',
|
hasManagerCertificate: toBoolString(info.hasManagerCertificate, info.managerCert ? 'true' : 'false'),
|
certificateName: info.certificateName || info.managerCertName || '',
|
managerCertificateNo: info.managerCertificateNo || info.managerCertNo || '',
|
managerPhone: info.managerPhone || info.managerTel || '',
|
neighborhoodCommitteeName: info.neighborhoodCommitteeName || info.committeeName || '',
|
neighborhoodCommitteeAddress: info.neighborhoodCommitteeAddress || info.committeeAddress || '',
|
neighborhoodSecretary: info.neighborhoodSecretary || info.committeeSecretaryName || '',
|
neighborhoodOfficePhone: info.neighborhoodOfficePhone || info.committeeOfficeTel || '',
|
secretaryPhone: info.secretaryPhone || info.committeeSecretaryTel || '',
|
ownersCommitteeAddress: info.ownersCommitteeAddress || '',
|
ownersCommitteeChairman: info.ownersCommitteeChairman || info.committeeChairmanName || '',
|
chairmanPhone: info.chairmanPhone || info.committeeChairmanTel || '',
|
fireHydrantCount: info.fireHydrantCount || info.fireSprinklerTotal || '',
|
fireChannelCount: info.fireChannelCount || info.fireChannelTotal || '',
|
waterTankCount: info.waterTankCount || info.waterTankTotal || '',
|
reservoirCount: info.reservoirCount || info.waterPoolTotal || '',
|
totalMotorVehicleSpaces: info.totalMotorVehicleSpaces || info.carTotal || '',
|
groundMotorVehicleSpaces: info.groundMotorVehicleSpaces || info.groundParkingSpaces || info.carGroundTotal || '',
|
undergroundMotorVehicleSpaces: info.undergroundMotorVehicleSpaces || info.undergroundParkingSpaces || info.carUndergroundTotal || '',
|
newEnergyChargingPiles: info.newEnergyChargingPiles || info.electricCarTotal || '',
|
nonMotorVehicleChargingPoints: info.nonMotorVehicleChargingPoints || info.nonElectricCarTotal || '',
|
groundNonMotorVehicleArea: info.groundNonMotorVehicleArea || info.nonElectricCarGroundArea || '',
|
undergroundNonMotorVehicleArea: info.undergroundNonMotorVehicleArea || info.nonElectricCarUndergroundArea || '',
|
clubhouseArea: info.clubhouseArea || info.clubArea || '',
|
hasDecorationRubbishPoint: info.hasDecorationRubbishPoint === '是' || info.garbageFixed == 1 ? '是' : '否',
|
securityEntranceCount: info.securityEntranceCount || info.gateGuardTotal || '',
|
elevatorCount: info.elevatorCount || info.elevatorTotal || '',
|
elevatorType: info.elevatorType || '',
|
elevatorInstallDate: info.elevatorInstallDate || '',
|
elevatorServiceLife: info.elevatorServiceLife || info.elevatorUseYears || '',
|
elevatorBrand1: info.elevatorBrand1 || '',
|
elevatorBrand2: info.elevatorBrand2 || '',
|
monitorCount: info.monitorCount || info.monitorTotal || '',
|
monitorMaintenanceCompany: info.monitorMaintenanceCompany || info.monitorMaintenanceUnit || '',
|
barrierGateCount: info.barrierGateCount || info.gateTotal || '',
|
barrierGateBrand: info.barrierGateBrand || info.gateBrand || '',
|
barrierSupplierContact: info.barrierSupplierContact || info.gateSupplierContactName || '',
|
barrierSupplierPhone: info.barrierSupplierPhone || info.gateSupplierContactTel || '',
|
waterPumpCount: info.waterPumpCount || info.pumpTotal || '',
|
groundParkingSpaces: info.groundParkingSpaces || '',
|
undergroundParkingSpaces: info.undergroundParkingSpaces || '',
|
groundNonMechanicalFee: info.groundNonMechanicalFee || '',
|
garageNonMechanicalFee: info.garageNonMechanicalFee || '',
|
temporaryHourlyFee: info.temporaryHourlyFee || info.hourlyFee || '',
|
temporaryDailyFee: info.temporaryDailyFee || info.dailyFee || '',
|
temporaryPerTimeFee: info.temporaryPerTimeFee || info.onceFee || '',
|
totalBuildingCount: info.totalBuildingCount || info.naturalBuildingTotal || '',
|
buildingUnitCount: info.buildingUnitCount || info.doorBuildingTotal || '',
|
highRiseBuildingCount: info.highRiseBuildingCount || info.highBuildingTotal || '',
|
multilayerVillaBuildingCount: info.multilayerVillaBuildingCount || info.lowBuildingTotal || '',
|
residentialHouseholdCount: info.residentialHouseholdCount || info.residentialHousehold || '',
|
shopHouseholdCount: info.shopHouseholdCount || info.commercialHousehold || '',
|
takeTime: info.takeTime || '',
|
outTime: info.outTime || '',
|
name: info.communityName || info.name || '',
|
communityCode: info.communityCode || info.code || '',
|
state: info.state || ''
|
};
|
},
|
submit: function () {
|
const $that = this;
|
const formData = vc.component.formData;
|
|
// 清除之前的错误样式
|
vc.component.clearAllErrors();
|
|
// 验证必填字段
|
if (!formData.name || formData.name.trim() === '') {
|
vc.toast('请输入小区名称');
|
vc.component.addError('input-name');
|
return;
|
}
|
|
// 构建详细地址
|
const addressParts = [];
|
if (formData.projectAddressTown) {
|
addressParts.push(formData.projectAddressTown);
|
}
|
if (formData.projectAddressRoad) {
|
addressParts.push(formData.projectAddressRoad);
|
}
|
const address = addressParts.join(' ') || '';
|
|
if (!address || address.trim() === '') {
|
vc.toast('请输入详细地址');
|
if (!formData.projectAddressTown || formData.projectAddressTown.trim() === '') {
|
vc.component.addError('input-town');
|
}
|
if (!formData.projectAddressRoad || formData.projectAddressRoad.trim() === '') {
|
vc.component.addError('input-road');
|
}
|
return;
|
}
|
|
// 构建区域地址
|
let areaAddress = formData.areaAddress || '';
|
// 如果 areaAddress 为空,尝试从省市区名称构建
|
if (!areaAddress || areaAddress.trim() === '') {
|
const areaParts = [];
|
if (vc.component.selectProvName) {
|
areaParts.push(vc.component.selectProvName);
|
} else if (formData.projectAddressProvince) {
|
areaParts.push(formData.projectAddressProvince);
|
}
|
if (vc.component.selectCityName) {
|
areaParts.push(vc.component.selectCityName);
|
} else if (formData.projectAddressCity) {
|
areaParts.push(formData.projectAddressCity);
|
}
|
if (vc.component.selectAreaName) {
|
areaParts.push(vc.component.selectAreaName);
|
} else if (formData.projectAddressDistrict) {
|
areaParts.push(formData.projectAddressDistrict);
|
}
|
areaAddress = areaParts.join('');
|
}
|
|
if (!areaAddress || areaAddress.trim() === '') {
|
vc.toast('请选择所在城市');
|
if (!vc.component.selectProv) {
|
vc.component.addError('province');
|
}
|
if (!vc.component.selectCity) {
|
vc.component.addError('city');
|
}
|
if (!vc.component.selectArea) {
|
vc.component.addError('area');
|
}
|
return;
|
}
|
|
// 验证区域编码(必须选择到区县级别)
|
const cityCode = formData.cityCode || vc.component.selectArea || '';
|
if (!cityCode || cityCode.trim() === '') {
|
vc.toast('请选择所在区域(需选择到区县)');
|
if (!vc.component.selectProv) {
|
vc.component.addError('province');
|
}
|
if (!vc.component.selectCity) {
|
vc.component.addError('city');
|
}
|
if (!vc.component.selectArea) {
|
vc.component.addError('area');
|
}
|
return;
|
}
|
|
// 验证联系电话(使用物业联系人电话或报修电话)
|
const tel = formData.propertyManagerPhone || formData.dayRepairPhone || '';
|
if (!tel || tel.trim() === '') {
|
vc.toast('请输入联系电话');
|
// 优先标记物业联系人电话,如果为空则标记日间电话
|
if (!formData.propertyManagerPhone || formData.propertyManagerPhone.trim() === '') {
|
vc.component.addError('input-phone');
|
}
|
// 如果物业联系人电话为空,且日间电话也为空,则也标记日间电话
|
if ((!formData.propertyManagerPhone || formData.propertyManagerPhone.trim() === '') &&
|
(!formData.dayRepairPhone || formData.dayRepairPhone.trim() === '')) {
|
vc.component.addError('input-day-phone');
|
}
|
return;
|
}
|
|
// 转换数据类型
|
const submitData = Object.assign({}, formData);
|
// 确保数字字段为数字类型
|
const numberFields = [
|
'fireHydrantCount', 'fireChannelCount', 'waterTankCount', 'reservoirCount',
|
'totalMotorVehicleSpaces', 'groundMotorVehicleSpaces', 'undergroundMotorVehicleSpaces',
|
'newEnergyChargingPiles', 'nonMotorVehicleChargingPoints',
|
'groundNonMotorVehicleArea', 'undergroundNonMotorVehicleArea', 'clubhouseArea',
|
'securityEntranceCount', 'elevatorCount', 'elevatorServiceLife', 'monitorCount',
|
'barrierGateCount', 'waterPumpCount', 'groundParkingSpaces', 'undergroundParkingSpaces',
|
'totalBuildingCount', 'buildingUnitCount', 'highRiseBuildingCount',
|
'multilayerVillaBuildingCount', 'residentialHouseholdCount', 'shopHouseholdCount'
|
];
|
numberFields.forEach(field => {
|
if (submitData[field] !== '' && submitData[field] !== null && submitData[field] !== undefined) {
|
submitData[field] = Number(submitData[field]);
|
}
|
});
|
// 确保BigDecimal字段为数字类型
|
const decimalFields = [
|
'feePrice', 'projectLandArea', 'totalConstructionArea', 'chargeableTotalArea',
|
'chargeableAreaMultilayer', 'chargeableAreaHighRise1', 'chargeableAreaHighRiseUp',
|
'chargeableAreaShop', 'chargeableAreaVilla', 'chargeableAreaOffice',
|
'chargeableAreaCommercialHouse', 'greenArea', 'groundNonMechanicalFee',
|
'garageNonMechanicalFee', 'temporaryHourlyFee', 'temporaryDailyFee', 'temporaryPerTimeFee'
|
];
|
decimalFields.forEach(field => {
|
if (submitData[field] !== '' && submitData[field] !== null && submitData[field] !== undefined) {
|
submitData[field] = Number(submitData[field]);
|
}
|
});
|
// 确保Integer字段为整数类型(仅用于需要传 0/1 的布尔字段)
|
const normalizeBoolToNumber = function(val) {
|
if (val === true || val === 'true' || val === 1 || val === '1' || val === '是') {
|
return 1;
|
}
|
if (val === false || val === 'false' || val === 0 || val === '0' || val === '否') {
|
return 0;
|
}
|
return val;
|
};
|
// 上岗证仍然按 0/1 提交
|
submitData.hasManagerCertificate = normalizeBoolToNumber(submitData.hasManagerCertificate);
|
// hasDecorationRubbishPoint 保持为“是 / 否”,直接随表单提交
|
// 提交数据
|
vc.http.apiPost(
|
'/community.updateCommunity',
|
JSON.stringify(submitData),
|
{
|
emulateJSON: true
|
},
|
function (json, res) {
|
const data = JSON.parse(json);
|
if (data.code == 0) {
|
vc.toast('更新成功');
|
setTimeout(function () {
|
$that.goBack();
|
}, 1500);
|
} else {
|
vc.toast(data.msg || '更新失败');
|
}
|
},
|
function (errInfo, error) {
|
console.log('请求失败处理', errInfo);
|
vc.toast('更新失败,请稍后重试');
|
}
|
);
|
},
|
goBack: function () {
|
// 跳转回小区管理列表页
|
window.location.href = '/#/pages/common/communityManage';
|
},
|
reset: function () {
|
// 重新加载数据
|
vc.component._loadCommunityDetail();
|
}
|
}
|
});
|
})(window.vc);
|