Commit dae528a7 authored by weizhikai's avatar weizhikai

机构地区三级联动选到区县

parent 7c182ce6
......@@ -32,6 +32,8 @@ public class CommonConstants {
public static final Integer REGION_LEVELTYPE_CITY = 2;
public static final Integer REGION_LEVELTYPE_DISTRICT= 3;
public static final Boolean ACTIVE_STATUS = true;
public static final Boolean DEACTIVE_STATUS = false;
......
......@@ -58,4 +58,12 @@ public class AreaRegionController {
logger.info("/api/v1/areaRegion/getCities");
return areaRegionService.getProvinces();
}
// @ApiOperation(value = "Get Provinces")
@RequestMapping(value = "getDistricts", method = RequestMethod.GET)
public @ResponseBody
List<AreaRegionDto> getDistricts(@RequestParam(name = "parentID") String parentId) {
logger.info("/api/v1/areaRegion/getDistricts");
return areaRegionService.getDistricts(parentId);
}
}
......@@ -246,6 +246,14 @@ public class AreaRegionServiceImpl {
}
public List<AreaRegionDto> getDistricts(String parentId) {
List<AreaRegionDto> districts = getRegions(CommonConstants.REGION_LEVELTYPE_DISTRICT);
List<AreaRegionDto> query = districts.stream().filter(s -> s.getRegionParentId().equals(parentId))
.collect(Collectors.toList());
return query;
}
private List<AreaRegionDto> getRegions(int levelType) {
RegionExample regionExample = new RegionExample();
regionExample.createCriteria().andIsActiveEqualTo(CommonConstants.ACTIVE_STATUS).andLevelTypeEqualTo(levelType);
......
......@@ -612,6 +612,7 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
$scope.CityList = defaultData;
$scope.ProvinceList = defaultData;
$scope.selectProvince = defaultData;
$scope.selectCity = defaultData;
$scope.selectRegionID = defaultData;
};
......@@ -694,9 +695,43 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
areaRegionService.getCities(regionID).success(function (data) {
if (data && data.length > 0) {
$scope.CityList = data;
$scope.selectCity = _.find($scope.CityList, function (num) {
return num.regionID === $scope.selectProvince.regionID || num.regionID === $scope.editOrgModel.parentRegionID;
});
if ($scope.selectCity) {
$scope.selectCityID = $scope.selectCity.regionID;
$scope.selectProvince = _.find($scope.ProvinceList, function (num) {
return num.regionID === $scope.selectCity.parentRegionID;
});
loadDistrictList($scope.selectCity.regionID);
}else{
$scope.selectCityID = data[0].regionID;
}
} else {
data = null;
$scope.CityList = data;
$scope.selectCity = data;
}
var target = _.find($scope.CityList, function (num) {
return num.regionID === $scope.editOrgModel.regionID;
});
}
};
// 加载区县信息
var loadDistrictList = function (regionID) {
if (regionID !== undefined && regionID !== null) {
areaRegionService.getDistricts(regionID).success(function (data) {
if (data && data.length > 0) {
$scope.DistrictList = data;
var target = _.find($scope.DistrictList, function (num) {
return num.regionID === $scope.selectCity;
});
if (target) {
......@@ -707,7 +742,7 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
} else {
data = null;
$scope.CityList = data;
$scope.DistrictList = data;
$scope.selectRegionID = null;
}
});
......@@ -1184,6 +1219,12 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
loadCityList(regionID);
};
// 市改变时联动区
$scope.populateDistricts = function () {
var regionID = $scope.selectCity && $scope.selectCity.regionID;
loadDistrictList(regionID);
};
// 验证是否为时间段
var validateDate = function (from, to) {
var fromDate = new Date(from + '-01');
......
......@@ -452,15 +452,27 @@
<div class="col-sm-5" style="padding-left: 10px;"
ng-class="{'has-error':orgControlForm.selectCity.$invalid && (orgControlForm.selectCity.$dirty || orgControlForm.$submitted)}">
<select class="form-control localRequired" name="selectCity"
id="selectCity" style="width: 119px; "
style="width: 120px; " ng-change="populateDistricts()"
ng-model="selectCity"
ng-options="x.regionName for x in CityList">
<option value="">{{pleaseSelect}}</option>
</select>
<p ng-show="orgControlForm.selectCity.$error.required && (orgControlForm.selectCity.$dirty || orgControlForm.$submitted)"
class="has-error label" style="margin-left: 30px">
{{resources.OrganizationMsgCityRequired}}</p>
</div>
<div class="col-sm-5" style="padding-left: 10px;"
ng-class="{'has-error':orgControlForm.selectDistrict.$invalid && (orgControlForm.selectDistrict.$dirty || orgControlForm.$submitted)}">
<select class="form-control localRequired" name="selectDistrict"
id="selectDistrict" style="width: 119px; "
ng-model="selectRegionID">
<option value="">{{pleaseSelect}}</option>
<option ng-repeat="x in CityList" value="{{x.regionID}}"
<option ng-repeat="x in DistrictList" value="{{x.regionID}}"
title="{{x.regionName}}">{{x.regionName |
limitString:10}}
</option>
</select>
<p ng-show="orgControlForm.selectCity.$error.required && (orgControlForm.selectCity.$dirty || orgControlForm.$submitted)"
<p ng-show="orgControlForm.selectDistrict.$error.required && (orgControlForm.selectDistrict.$dirty || orgControlForm.$submitted)"
class="has-error label" style="margin-left: 30px">
{{resources.OrganizationMsgCityRequired}}</p>
</div>
......
......@@ -15,6 +15,10 @@ function ($http, apiConfig, httpCacheService) {
//return $http.get('/areaRegion/getCities?parentID=' + parentID, apiConfig.create());
return httpCacheService.get('/areaRegion/getCities?parentID=' + parentID);
},
getDistricts: function (parentID) {
//return $http.get('/areaRegion/getCities?parentID=' + parentID, apiConfig.create());
return httpCacheService.get('/areaRegion/getDistricts?parentID=' + parentID);
},
update: function (model) {
return $http.post('/areaRegion/update', model, apiConfig.create());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment