码迷,mamicode.com
首页 > 其他好文 > 详细

联动切换搜索域

时间:2018-05-21 21:17:12      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:fine   mod   imp   很多   联动   初始化   style   下拉   stty   

this.listQuery[this.paramsName] = this.paramsValue;

  

<el-select v-model="paramsName" placeholder="搜索项" @change="toggle"> <el-option v-for="item in paramsOptions" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="姓名" v-model="paramsValue" v-show="inputText"> </el-input> <el-select v-model="paramsValue" clearable placeholder="请选择" v-show="inputSelect"> <el-option v-for="item in paramsValueOptions" :key="item.value" :label="item.labelDefault" :value="item.value"></el-option> </el-select> <el-button class="filter-item" type="primary" icon="search" @click="handleFilter">搜索</el-button> <el-button class="filter-item" v-if="baseEmployeeManager_btn_add" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="edit">添加</el-button>

  搜索栏

技术分享图片

这里有三个变量:
paramsName    对应修改搜索选项的model,同时也是选项的key
paramsValue    对应选项的内容的model,对应选项的value
paramsOptions   存储这些key
paramsValueOptions  存储每一个key的取值集合,比如下拉框就是很多值
 
首先如果paramsName 对应下拉框:
先取下拉框的字典值,使用字典
import { getTypeValue } from ‘@/api/dict/dictValue/index‘;

  技术分享图片

初始化全局变量

      statusOptions: [],
      sexOptions: [],

  

调用字典,保存传回来的值到变量

 

    getTypeValue(‘type_is_flag‘).then(response => {
      this.statusOptions = response.data.rows;
    });
    getTypeValue(‘comm_sex‘).then(response => {
      this.sexOptions = response.data.rows;
    });
    getTypeValue(‘specialist_type‘).then(response => {
      this.specialistOptions = response.data.rows;
    });

  

技术分享图片

切换的标志位

      paramsValue: undefined,
      paramsName: undefined,
      paramsValueOptions: [],
      inputText: true,
      inputSelect: false,
      specialistOptions: []

  技术分享图片

点击切换,触发toggle方法,toggle方法

    toggle() {
      this.paramsValue = undefined;
      switch (this.paramsName) {
        case ‘empName‘:
          this.inputText = true;
          this.inputSelect = false;
          break;
        case ‘sex‘:
          this.paramsValueOptions = this.sexOptions;
          this.inputText = false;
          this.inputSelect = true;
          break;
        case ‘status‘:
          this.paramsValueOptions = this.statusOptions;
          this.inputText = false;
          this.inputSelect = true;
          break;
        case ‘specialistType‘:
          this.paramsValueOptions = this.specialistOptions;
          this.inputText = false;
          this.inputSelect = true;
          break;
      }
    },

  技术分享图片

现在触发能修改值,修改的值也传进来了,要搜索,还要把搜索的参数在搜索时使用

this.listQuery[this.paramsName] = this.paramsValue;

  

 

技术分享图片

好了

联动切换搜索域

标签:fine   mod   imp   很多   联动   初始化   style   下拉   stty   

原文地址:https://www.cnblogs.com/tabCtrlShift/p/9069163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!