ElementUI 省市区多选搜索(前台+后台传参)详细

用到的ElementUi组件

直达链接: https://element.eleme.cn/#/zh-CN/component/select

效果
在这里插入图片描述

在这里插入图片描述
一、前台(element-ui+vue)
1)添加组件
在这里插入图片描述
2)js部分,添加到return里


3)加入查询数组定义
在这里插入图片描述
4)搜索方法内添加

if(this.searchOptions.length>0){

        var cityCode = this.searchOptions;
        var zoneCode = this.searchOptions;

        /*省市区选择处理数据 start*/
        var provinceList = new Array();
        var cityList = new Array();
        var zoneList = new Array();

        cityCode.forEach(cit => {
          if(cit[1] != 'undefined' && cit[1] != undefined && cit[1] != null && cit[1] != ''){
            // cityList.push(CodeToText[cit[1]]);
          }else if(cit[0] != 'undefined' && cit[0] != undefined && cit[0] != null && cit[0] != ''){
            provinceList.push(CodeToText[cit[0]]);
          }
        });
        zoneCode.forEach(zon => {
          if(zon[2] != 'undefined' && zon[2] != undefined && zon[2] != null && zon[2] != ''){
            zoneList.push(CodeToText[zon[2]]);
          }else if(zon[1] != 'undefined' && zon[1] != undefined && zon[1] != null && zon[1] != ''){
            cityList.push(CodeToText[zon[1]]);
          }
        });

        let provinceListSet = new Set(provinceList);
        let cityListSet = new Set(cityList);
        let zoneListSet = new Set(zoneList);

        var proResult = "";
        var citResult = "";
        var zonResult = "";

        provinceListSet.forEach( ptemp =>{
          proResult = proResult + ptemp + ',';
        })
        cityListSet.forEach( ctemp =>{
          citResult = citResult + ctemp + ',';
        })
        zoneListSet.forEach( ztemp =>{
          zonResult = zonResult + ztemp + ',';
        })
        /*end*/

        this.queryParams.province = proResult;
        this.queryParams.city = citResult;
        this.queryParams.zone = zonResult;
      }else{
        this.queryParams.province = null;
        this.queryParams.city = null;
        this.queryParams.zone = null;
      }

二、后台方法
String,接收,sql处理

       if(StrUtil.isEmpty(paperMailInfo.getProvince())){
            paperMailInfo.setProvince(null);
        }
        if(StrUtil.isEmpty(paperMailInfo.getCity())){
            paperMailInfo.setCity(null);
        }
        if(StrUtil.isEmpty(paperMailInfo.getZone())){
            paperMailInfo.setZone(null);
        }

  <if test='zone != null or province != null or  city != null '>
                and (
                <if test='province != null'>
                    a.province in
                    <foreach item="id" collection='province.split(",")' open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
                <if test='city != null'>
                    <if test='province != null'>or</if>
                    a.city in
                    <foreach item="id" collection='city.split(",")' open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
                <if test='zone != null'>
                    <if test='province != null or city != null'>or</if>
                    a.zone in
                    <foreach item="id" collection='zone.split(",")' open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
                )
            </if>

用到的省市区js放到下载了,命名为city.js引入
import { regionData } from “@/api/paper/city-data/city”;
点击下载省市区js
齐活=

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue-ElementUI提供了一个el-cascader级联选择器组件,可以用来实现省市区三级选择器。 首先,需要引入ElementUI: ```html <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/element-ui/lib/index.js"></script> ``` 然后,在Vue组件中使用el-cascader组件: ```html <template> <div> <el-cascader :options="options" v-model="selectedOptions" @change="handleChange"> </el-cascader> </div> </template> <script> export default { data() { return { options: [], // 省市区数据 selectedOptions: [], // 已选中的选项 }; }, mounted() { // 加载省市区数据 this.loadOptions(); }, methods: { loadOptions() { // 使用ajax加载省市区数据 // 省市区数据格式: // [ // { // value: '110000', // label: '北京市', // children: [ // { // value: '110100', // label: '市辖区', // children: [ // { // value: '110101', // label: '东城区', // }, // ... // ] // }, // ... // ] // }, // ... // ] this.options = [...省市区数据]; }, handleChange(value) { // 选项改变时触发,value为已选中的选项值 console.log(value); }, }, }; </script> ``` 其中,options是一个省市区数据的数组,selectedOptions是一个已选中的选项值的数组,handleChange方法会在选项改变时触发。 需要注意的是,el-cascader组件的options和selectedOptions属性都需要使用v-model进行双向绑定。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xkng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值