Commit 72e93798 authored by weizhikai's avatar weizhikai

机构地区三级联动选到区县展示问题

parent dae528a7
...@@ -51,6 +51,14 @@ public class AreaRegionController { ...@@ -51,6 +51,14 @@ public class AreaRegionController {
return areaRegionService.getCities(parentId); return areaRegionService.getCities(parentId);
} }
// @ApiOperation(value = "Get cities")
@RequestMapping(value = "getProvincesByCityID", method = RequestMethod.GET)
public @ResponseBody
AreaRegionDto getProvincesByCityID(@RequestParam(name = "cityID") String cityID) {
logger.info("/api/v1/areaRegion/getProvincesByCityID");
return areaRegionService.getProvincesByCityID(cityID);
}
// @ApiOperation(value = "Get Provinces") // @ApiOperation(value = "Get Provinces")
@RequestMapping(value = "getProvinces", method = RequestMethod.GET) @RequestMapping(value = "getProvinces", method = RequestMethod.GET)
public @ResponseBody public @ResponseBody
......
...@@ -246,6 +246,21 @@ public class AreaRegionServiceImpl { ...@@ -246,6 +246,21 @@ public class AreaRegionServiceImpl {
} }
public AreaRegionDto getProvincesByCityID(String cityId) {
Region region = regionMapper.selectByPrimaryKey(cityId);
if(region != null){
Region region1 = regionMapper.selectByPrimaryKey(region.getParentId());
if(region1!=null){
return rotateRegion(region1);
}else{
return null;
}
}else{
return null;
}
}
public List<AreaRegionDto> getDistricts(String parentId) { public List<AreaRegionDto> getDistricts(String parentId) {
List<AreaRegionDto> districts = getRegions(CommonConstants.REGION_LEVELTYPE_DISTRICT); List<AreaRegionDto> districts = getRegions(CommonConstants.REGION_LEVELTYPE_DISTRICT);
List<AreaRegionDto> query = districts.stream().filter(s -> s.getRegionParentId().equals(parentId)) List<AreaRegionDto> query = districts.stream().filter(s -> s.getRegionParentId().equals(parentId))
......
...@@ -669,17 +669,23 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', ' ...@@ -669,17 +669,23 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
// 获取省市 // 获取省市
var loadProvinceList = function () { var loadProvinceList = function () {
areaRegionService.getProvinces().success(function (data) { areaRegionService.getProvinces().success(function (data) {
if (data && data.length > 0) { if (data && data.length > 0) {
$scope.ProvinceList = data; $scope.ProvinceList = data;
$scope.selectProvince = _.find($scope.ProvinceList, function (num) { //根据当前机构的父级(即市的层级)获取对应的省的regionID
return num.regionID === $scope.editOrgModel.parentRegionID; //目前情况为省市区三级联动,参数为$scope.editOrgModel.parentRegionID,若为省市两级联动,参数改为$scope.editOrgModel.regionID即可
areaRegionService.getProvincesByCityID($scope.editOrgModel.parentRegionID).success(function (resp) {
if(resp){
$scope.selectProvince = _.find($scope.ProvinceList, function (num) {
return num.regionID === resp.regionID;
});
if ($scope.selectProvince) {
loadCityList($scope.selectProvince.regionID);
}
}
}); });
if ($scope.selectProvince) {
loadCityList($scope.selectProvince.regionID);
}
} else { } else {
data = null; data = null;
$scope.ProvinceList = data; $scope.ProvinceList = data;
...@@ -696,20 +702,11 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', ' ...@@ -696,20 +702,11 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
if (data && data.length > 0) { if (data && data.length > 0) {
$scope.CityList = data; $scope.CityList = data;
$scope.selectCity = _.find($scope.CityList, function (num) { $scope.selectCity = _.find($scope.CityList, function (num) {
return num.regionID === $scope.selectProvince.regionID || num.regionID === $scope.editOrgModel.parentRegionID; return num.regionID === $scope.editOrgModel.parentRegionID;
}); });
if ($scope.selectCity) { 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); loadDistrictList($scope.selectCity.regionID);
}else{
$scope.selectCityID = data[0].regionID;
} }
} else { } else {
...@@ -717,7 +714,6 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', ' ...@@ -717,7 +714,6 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
$scope.CityList = data; $scope.CityList = data;
$scope.selectCity = data; $scope.selectCity = data;
} }
}); });
} }
}; };
...@@ -731,7 +727,7 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', ' ...@@ -731,7 +727,7 @@ controller('editOrganizationModalController', ['$scope', '$log', '$translate', '
$scope.DistrictList = data; $scope.DistrictList = data;
var target = _.find($scope.DistrictList, function (num) { var target = _.find($scope.DistrictList, function (num) {
return num.regionID === $scope.selectCity; return num.regionID === $scope.editOrgModel.regionID;
}); });
if (target) { if (target) {
......
...@@ -11,6 +11,10 @@ function ($http, apiConfig, httpCacheService) { ...@@ -11,6 +11,10 @@ function ($http, apiConfig, httpCacheService) {
//return $http.get('/areaRegion/getProvinces', apiConfig.create()); //return $http.get('/areaRegion/getProvinces', apiConfig.create());
return httpCacheService.get('/areaRegion/getProvinces'); return httpCacheService.get('/areaRegion/getProvinces');
}, },
getProvincesByCityID: function (cityID) {
//return $http.get('/areaRegion/getCities?parentID=' + parentID, apiConfig.create());
return $http.get('/areaRegion/getProvincesByCityID?cityID=' + cityID, apiConfig.create());
},
getCities: function (parentID) { getCities: function (parentID) {
//return $http.get('/areaRegion/getCities?parentID=' + parentID, apiConfig.create()); //return $http.get('/areaRegion/getCities?parentID=' + parentID, apiConfig.create());
return httpCacheService.get('/areaRegion/getCities?parentID=' + parentID); return httpCacheService.get('/areaRegion/getCities?parentID=' + parentID);
......
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