소스 검색

省市二级联动

heyun 6 년 전
부모
커밋
05596230c5

+ 15 - 1
WebService/src/main/java/com/java110/web/components/CompanyComponent.java

@@ -48,7 +48,21 @@ public class CompanyComponent {
             return responseEntity;
         }
     }
-
+    /**
+     * 功能描述: 查询所有省市
+     * @param pd
+     * @return
+     */
+    public ResponseEntity<String> getAreas(IPageData pd){
+        ResponseEntity<String> responseEntity = null;
+        try{
+            responseEntity =  companyServiceSMOImpl.getAreas(pd);
+        }catch (Exception e){
+            responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+        }finally {
+            return responseEntity;
+        }
+    }
 
     public ICompanyServiceSMO getCompanyServiceSMOImpl() {
         return companyServiceSMOImpl;

+ 7 - 0
WebService/src/main/java/com/java110/web/smo/ICompanyServiceSMO.java

@@ -23,4 +23,11 @@ public interface ICompanyServiceSMO {
      * @return
      */
     public ResponseEntity<String> saveCompanyInfo(IPageData pd);
+
+    /**
+     * 查询所有省市
+     * @param pd
+     * @return
+     */
+    public ResponseEntity<String> getAreas(IPageData pd);
 }

+ 20 - 0
WebService/src/main/java/com/java110/web/smo/impl/CompanyServiceSMOImpl.java

@@ -130,6 +130,26 @@ public class CompanyServiceSMOImpl extends BaseComponentSMO implements ICompanyS
         return responseEntity;
     }
 
+    /**
+     * 查询 所有省市
+     * @param pd
+     * @return
+     */
+    @Override
+    public ResponseEntity<String> getAreas(IPageData pd) {
+        ResponseEntity<String> responseEntity = null;
+        Assert.hasLength(pd.getUserId(),"用户还未登录请先登录");
+
+        responseEntity = this.callCenterService(restTemplate,pd,"", ServiceConstant.SERVICE_API_URL+"/api/api.queryAreas", HttpMethod.GET);
+
+        if(responseEntity.getStatusCode() == HttpStatus.OK){
+            Assert.jsonObjectHaveKey(responseEntity.getBody(),"areas","查询中心服务异常,不是有效json或未包含areas节点");
+            //将areas 返回出去
+            responseEntity = new ResponseEntity<String>(JSONObject.parseObject(responseEntity.getBody()).getJSONArray("areas").toJSONString(),HttpStatus.OK);
+        }
+        return responseEntity;
+    }
+
 
     /**
      * 校验公司信息

+ 17 - 5
WebService/src/main/resources/components/companyPackage/company-base/company-base.html

@@ -9,11 +9,23 @@
             <div class="dropdown">
                 <label>公司地址 *</label>
 
-                <select id="pro" class="btn btn-secondary dropdown-toggle" >
-                <option value="">请选择省</option>
-            </select>
-                <select id="city" class="btn btn-secondary dropdown-toggle" >
-                    <option value="">请选择市</option>
+                <select id="pro" class="form-control form-control-sm" style="width: 10vw;display: inline;"
+                        v-model="selectProv"
+                        @change="getProv($event)" >
+                    <option value='' disabled selected style='display:none;'>请选择省</option>
+                <option v-for="item in provs"
+                        :label="item.label"
+                        :value="item.id">{{item.label}}</option>
+
+                </select>
+                <select id="city" class="form-control form-control-sm" style="width: 10vw;display: inline;"
+                        v-if="selectProv!=''"
+                        v-model="selectCity"
+                        @change="getCity($event)" >
+                    <option value='' disabled selected style='display:none;'>请选择城市</option>
+                    <option v-for="item in citys"
+                            :label="item.label"
+                            :value="item.id">{{item.label}}</option>
                 </select>
                 <input  name="address" v-model="companyBaseInfo.address" type="text" class="form-control required" aria-required="true" />
             </div>

+ 42 - 1
WebService/src/main/resources/components/companyPackage/company-base/company-base.js

@@ -13,7 +13,13 @@
                 tel:"",
                 storeTypeCd:"",
                 nearbyLandmarks:""
-            }
+            },
+            areas:[],
+            provs:[],
+            citys: [],
+            selectProv: '',
+            selectCity: '',
+            allCity:[]
         },
          _initMethod:function(){
              vc.component.initStoreType();
@@ -34,6 +40,21 @@
              }
         },
         methods:{
+            getProv: function (prov) {
+                let tempCity=[];
+                this.citys=[];
+                this.selectCity='';
+                for (var val of this.allCity){
+                    if (prov.currentTarget.value == val.pid){
+                        tempCity.push({label: val.label, id: val.id})
+                    }
+                }
+                this.citys = tempCity;
+            },
+            getCity: function (city) {
+                console.log(this.selectCity);
+                console.log(this.selectProv);
+            },
             initStoreType:function(){
                 var param = {
                                     params:{
@@ -53,6 +74,26 @@
                                 console.log('请求失败处理',errInfo,error);
                                 vc.component.$emit('errorInfoEvent',errInfo);
                              });
+                vc.http.get('company','getAreas',
+                    JSON.stringify(param),
+                    function(json,res){
+                        if(res.status == 200){
+                            vc.component.areas = JSON.parse(json);
+                            for (var i=0;i<vc.component.areas.length;i++){
+                                if(vc.component.areas[i].level==1){
+                                    vc.component.provs.push(vc.component.areas[i])
+                                }
+                                if(vc.component.areas[i].level==2){
+                                    vc.component.allCity.push(vc.component.areas[i])
+                                }
+                            }
+                            return ;
+                        }
+                        //vc.component.$emit('errorInfoEvent',json);
+                    },function(errInfo,error){
+                        console.log('请求失败处理',errInfo,error);
+                        vc.component.$emit('errorInfoEvent',errInfo);
+                    });
             },
             validateBase:function(){
                 return vc.validate.validate({