温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

avue如何实现自定义搜索栏及清空搜索事件

发布时间:2021-12-14 11:34:55 来源:亿速云 阅读:3526 作者:iii 栏目:开发技术

这篇文章主要介绍“avue如何实现自定义搜索栏及清空搜索事件”,在日常操作中,相信很多人在avue如何实现自定义搜索栏及清空搜索事件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”avue如何实现自定义搜索栏及清空搜索事件”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

对搜索栏进行自定义,并通过按钮实现折叠搜索栏效果。自定义效果如下:

折叠前:

avue如何实现自定义搜索栏及清空搜索事件

折叠后:

avue如何实现自定义搜索栏及清空搜索事件

1、自定义搜索栏内容

其实也简单,只要在对应的vue文件中\src\views\admin\sysxxfsjl.vue对template 设置slot-scope="scope"和 slot="search"属性即可自定义搜索栏内容:

<template slot-scope="scope" slot="search">
                  <el-form ref="form" :model="searchForm"  label-width="100px">
                    <el-row>
                      <el-form-item label="主题:">
                        <el-input v-model="searchForm.xxbt"  @change="getList()"></el-input>
                      </el-form-item>
                      <el-form-item label="发送人:">
                        <el-cascader
                          v-model="fsrid"
                          :options="options"
                          clearable
                          
                          :props="{ expandTrigger: 'hover' }"
                          @change="getList()"></el-cascader>
                      </el-form-item>
                    </el-row>
                    <el-row v-show="moreshow">
                      <el-form-item label="发送时间:">
                        <el-date-picker
                          
                          v-model="timeSlot"
                          type="daterange"
                          align="right"
                          unlink-panels
                          format="yyyy-MM-dd HH:mm:ss"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期"
                          :picker-options="pickerOptions"
                          @change="getList()">
                        </el-date-picker>
                      </el-form-item>
                      <el-form-item label="方式:" >
                        <el-radio-group v-model="searchForm.fsfs" size="small"  @change="getList()">
                          <el-radio-button label="4">系统消息</el-radio-button>
                          <el-radio-button label="1">手机短信</el-radio-button>
                          <el-radio-button label="3">微信发送</el-radio-button>
                        </el-radio-group>
                      </el-form-item>
                    </el-row>
                    <el-row v-show="moreshow">
                      <el-form-item label="阅读状态:">
                        <el-radio-group v-model="sfyd" size="small"  @change="getList()">
                          <el-radio-button label="2">所有</el-radio-button>
                          <el-radio-button label="1">已读</el-radio-button>
                          <el-radio-button label="0">未读</el-radio-button>
                        </el-radio-group>
                      </el-form-item>
                      <el-form-item label="是否转待办:">
                        <el-radio-group v-model="checkList"  @change="getList()">
                          <el-radio-button label="1">是</el-radio-button>
                          <el-radio-button label="0">否</el-radio-button>
                        </el-radio-group>
                      </el-form-item>
                    </el-row>
                  </el-form>
                </template>

搜索按钮 调用的是getList中的方法,给表格赋值数据

getList(page, params) {
              this.tableData=[]
                if (this.timeSlot && this.timeSlot.length == 2) {//发送时间
                  this.searchForm.startTime = this.timeSlot[0].replace(/\+/g, ' ')
                  this.searchForm.endTime = this.timeSlot[1].replace(/\+/g, ' ')
                }else {
                  delete this.searchForm.startTime
                  delete this.searchForm.endTime
                }
                if (this.fsrid.length){//发送人
                  this.searchForm.fsrid = this.fsrid[this.fsrid.length-1]
                }else {
                  delete this.searchForm.fsrid
                }
                if (this.sfyd.length>0){//是否转待办
                  if (this.sfyd== 1){
                    this.searchForm.sfyd = 1
                  }else if (this.sfyd== 0){
                    this.searchForm.sfyd = 0
                  }else {
                    delete this.searchForm.sfyd
                  }
                }else {
                  delete this.searchForm.sfyd
                }
                if (this.checkList!=''){//是否转待办
                  if (this.checkList== '1'){
                    this.searchForm.sfdb = 1
                  }else {
                    this.searchForm.sfdb = 0
                  }
                }else {
                  delete this.searchForm.sfdb
                }
                if (!page) {
                  page = this.page
                }
                this.tableLoading = true
                fetchList(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                }, params, this.searchForm )).then(response => {
                  for(var i=0;i<response.data.data.records.length;i++){
                    response.data.data.records[i].checkbox=[]
                    if(response.data.data.records[i].sfyd==0){
                      response.data.data.records[i].checkbox.push(' 未读')
                    }else{
                      response.data.data.records[i].checkbox.push(' 已读')
                    }
                    if(response.data.data.records[i].sfdb==1){
                      response.data.data.records[i].checkbox.push(' 待办')
                    }
                    if(response.data.data.records[i].sfsc==1){
                      response.data.data.records[i].checkbox.push(' 收藏')
                    }
                    if(response.data.data.records[i].sfhf==1){
                      response.data.data.records[i].checkbox.push(' 已回')
                    }
                    if(response.data.data.records[i].xxfjmc){
                      response.data.data.records[i].xxfjmc=response.data.data.records[i].xxfjmc.split(',')
                    }else{
                      response.data.data.records[i].xxfjmc=[]
                    }
                    this.tableData.push(response.data.data.records[i])
                  }
                    this.page.total = response.data.data.total
                    this.tableLoading = false
                }).catch(() => {
                    this.tableLoading=false
                })
            },

2、自定义搜索按钮

template 设置slot-scope="scope"和 slot="searchMenu"属性即可自定义搜索按钮,加上更多按钮:

<template slot-scope="scope" slot="searchMenu">
                  <el-button v-if="moreshow" type="success" class="el-button--small" icon="el-icon-caret-top" @click="getmoreshow(1)">隐藏</el-button>
                  <el-button v-else class="el-button--small" icon="el-icon-caret-bottom" @click="getmoreshow(2)">更多</el-button>
                </template>

更多、隐藏按钮调用方法对搜索项进行显隐

getmoreshow(type){
            if(type==1){
              this.moreshow=false
            }else{
              this.moreshow=true
            }
          },

清空按钮 需在avue-crud上增加@search-reset事件。进行清空选项内容并调用this.getList(this.page);

avue如何实现自定义搜索栏及清空搜索事件

//搜索清空按钮事件
            searchReset(){
              this.searchForm = {}
              this.searchForm.sfyd = ''
              if (this.searchForm.sfyd!=''){//是否转待办
                if (this.searchForm.sfyd== '1'){
                  this.searchForm.sfyd = 1
                }else {
                  this.searchForm.sfyd = 0
                }
              }else {
                delete this.searchForm.sfyd
              }
              this.fsrid = []
              this.timeSlot = []
              this.checkList = ''
              this.sfyd = ''
              this.$refs.crud.toggleSelection();
              this.getList(this.page);
            },

到此,关于“avue如何实现自定义搜索栏及清空搜索事件”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI