vue搜索表格功能,根据input输入框和下拉框传递的参数进行搜索

简介: vue搜索表格功能,根据input输入框和下拉框传递的参数进行搜索

json数据

{"msg":"success","total":0,"code":1,"data":[{"id":5,"userOrganId":null,"userName":"super","sex":1,"realName":"133","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":1,"roleName":"管理员","organId":1,"organName":"test311","authority":1,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":34,"userOrganId":null,"userName":"lijunfei","sex":1,"realName":"qqq","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":41,"roleName":"wangxiaotih","organId":26,"organName":"A部门","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":35,"userOrganId":null,"userName":"john","sex":1,"realName":"小猪","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":2,"organName":"研发部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":36,"userOrganId":null,"userName":"test","sex":0,"realName":"测试人员","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":27,"organName":"测试部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":37,"userOrganId":null,"userName":"www","sex":0,"realName":"ww","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":27,"organName":"测试部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":38,"userOrganId":null,"userName":"wwwwww","sex":0,"realName":"www","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":27,"organName":"测试部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1}]}

渲染表格

功能需求

1:在input输入框输入终端编号的时候,会查询出一条符合输入终端编号的数据

大概是这样子的

2:在选择下拉框里面的值的时候

将选中的值,传给后端,后端在数据库里面进行查询

返回符合条件的值

大概是这样子的

test.vue

<template>
  <div class="tab-container">
    <div class="filter-container" style="margin-bottom: 20px">
      <el-input
        maxlength="40"
        placeholder="用户名"
        style="width: 200px"
        class="filter-item"
        v-model="searchContent"
        @keyup.enter.native="handleFilter"
      />
      <el-select
        placeholder="全部部门"
        clearable
        style="width: 150px; margin-right: 30px"
        class="filter-item"
        v-model="questionForm.organId"
        @change="changeHandler"
      >
        <el-option
          v-for="item in getOrganList"
          :key="item.id"
          :label="item.organName"
          :value="item.id"
        ></el-option>
      </el-select>
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="searchContList"
        >搜索
      </el-button>
    </div>
    <el-table
      :data="pvData.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column
        prop="userName"
        label="用户名"
        width="180"
      ></el-table-column>
      <el-table-column prop="realName" label="姓名"></el-table-column>
      <el-table-column
        prop="sex"
        label="性别"
        :formatter="formatSex"
      ></el-table-column>
      <el-table-column prop="organName" label="所属部门"></el-table-column>
      <el-table-column
        prop="authority"
        label="权限"
        :formatter="formatauthority"
      ></el-table-column>
      <el-table-column prop="roleName" label="角色"></el-table-column>
    </el-table>
    <el-pagination
      style="margin: 12px 0px"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 20, 40]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pvData.length"
    >
    </el-pagination>
  </div>
</template>
<script>
//调用接口
import { getQuerycheckList, getOrgan } from "@/api/permission/user";
export default {
  data() {
    return {
      // 分页
      currentPage: 1, //初始页
      pagesize: 5, //    每页的数据
      total: 0,
      searchContent: "",
      questionForm: {
        organName: "",
        organId: "",
      },
      pvData: [],
      getOrganList: [],
    };
  },
  watch: {},
  created() {
    //加载用户列表信息接口
    this.getQuerycheckList();
    //加载部门
    this.getOrgan();
  },
  methods: {
    //部门下拉框
    changeHandler(value) {
      const checkedItem = this.getOrganList.find((a) => a.id === value);
      this.questionForm.organName = checkedItem.organName;
    },
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function (size) {
      this.pagesize = size;
      console.log(this.pagesize); //每页下拉显示数据
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      console.log(this.currentPage); //点击第几页
    },
    // 查询按钮
    searchContList() {
      this.getQuerycheckList();
    },
    //查询用户列表信息接口
    getQuerycheckList() {
      //取出来sessionStorage的值
      const userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
      const params = {
        userName: "",
        organId: "",
        userOrganId: userInfo.userOrganId,
        authority: userInfo.authority,
        page: 1,
        rows: 20,
        isPagination: false,
      };
      //搜索内容的参数
      if (this.searchContent) {
        params.userName = this.searchContent;
      }
      if (this.questionForm.organId) {
        params.organId = this.questionForm.organId;
      }
      this.dataLoading = true;
      getQuerycheckList(params).then((res) => {
        if (res.data !== null) {
          this.pvData = res.data;
        }
        this.dataLoading = false;
      });
    },
    //获取部门信息接口定义
    getOrgan() {
      const userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
      const params = {
        organId: userInfo.userOrganId,
        authority: userInfo.authority,
      };
      this.dataLoading = true;
      getOrgan(params).then((res) => {
        this.getOrganList = res.data.organs;
        this.dataLoading = false;
      });
    },
    //格式化性别
    formatSex(row, column) {
      return row.sex === 1 ? "男" : "女";
    },
    //格式化权限
    formatauthority(row, column) {
      return row.authority === 1 ? "所有部门权限" : "当前部门权限";
    },
  },
};
</script>
<style scoped>
.tab-container {
  margin: 30px;
}
</style>
相关文章
|
3天前
|
JavaScript
vue组件封装 | 数字输入框(限制只能输入数字的input,可以指定小数点位数,最大值、最小值)
vue组件封装 | 数字输入框(限制只能输入数字的input,可以指定小数点位数,最大值、最小值)
17 7
|
2天前
|
JavaScript 网络架构
vue 使用 this.$router.push 传参数,接参数的 query或params 两种方法示例
vue 使用 this.$router.push 传参数,接参数的 query或params 两种方法示例
8 4
|
3天前
|
JavaScript
vue 复杂表格的遍历渲染
vue 复杂表格的遍历渲染
11 2
|
3天前
|
JavaScript
vue拖拽 —— vuedraggable 表格拖拽行
vue拖拽 —— vuedraggable 表格拖拽行
5 1
|
22天前
|
JavaScript 前端开发
vue filters过滤器传多个参数
这段内容展示了如何在HTML和JavaScript中使用过滤器(filter)。在HTML中,通过`{{变量 | 过滤器名(参数)}}`的方式传递参数给过滤器。在JavaScript中,定义过滤器函数并接收参数,如`filterAa(aa, bb, cc)`,其中`aa`, `bb`, `cc`分别代表过滤器接收到的第1至第3个参数。示例逐步演示了传1个、2个到3个参数给过滤器的过程。
29 1
|
23天前
|
JavaScript
Vue.js中使用作用域插槽实现自定义表格组件
Vue.js中使用作用域插槽实现自定义表格组件
|
3天前
|
JavaScript 搜索推荐
vue【详解】props —— 子组件接收父组件传入的参数
vue【详解】props —— 子组件接收父组件传入的参数
6 0
|
28天前
|
JavaScript
|
9天前
|
前端开发 JavaScript
vue+el-select下拉多选实现,全选,反选,清空功能源码
vue+el-select下拉多选实现,全选,反选,清空功能源码
10 0
|
28天前
|
JavaScript Java 测试技术
基于ssm+vue.js+uniapp小程序的多功能智能手机阅读APP附带文章和源代码部署视频讲解等
基于ssm+vue.js+uniapp小程序的多功能智能手机阅读APP附带文章和源代码部署视频讲解等
18 0

相关实验场景

更多