Vue实现下拉表格组件

<template>
  <div>
    <div class="select-table">
      <el-form ref="verification" label-width="80px" :model="selectData" :rules="rules">
        <el-form-item label="姓名" prop="userName">
          <el-input @change="changeTab" v-model="selectData.userName" placeholder="选择用户" :suffix-icon="showTree?'el-icon-arrow-up':'el-icon-arrow-down'" @click.native="deptogglePanel($event)"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div v-if="showTree" class="treeDiv" ref="tableList">
      <div style="display: flex;align-items: center;margin-bottom: 10px">
        <span style="font-size: 14px;color: #606266;margin: 0 10px">姓名</span>
        <el-input style="width: 200px" clearable v-model="formData.userName"  size="small" placeholder="请输入姓名"></el-input>
        <span style="font-size: 14px;color: #606266;margin: 0 10px">职务</span>
        <el-input style="width: 200px" clearable v-model="formData.position" size="small" placeholder="请输入职务"></el-input>
        <el-button style="margin-left: 10px" size="small" type="primary" plain @click="getTableData">查询</el-button>
      </div>
      <el-table @row-click="handleRegionNodeClick" :data="tableData" border stripe ref="tableView" size="small" height='200px' highlight-current-row :header-cell-style="{background:'#ECF5FF',color:'#606266',fontWeight:'bold'}">
        <el-table-column prop="userName" label="姓名" header-align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="position" label="职位" align="center"></el-table-column>
        <el-table-column prop="orgName" label="标段" align="center"></el-table-column>
      </el-table>
      <el-pagination
          style="width: calc(100% - 10px); bottom: 10px;background: rgb(236, 245, 255);"
          @size-change="dolNandleSizeChange"
          @current-change="dolHandleCurrentChange"
          :current-page="formData.page"
          :page-sizes="[15, 30, 50, 100]"
          :page-size="formData.rows"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>
export default {
  name: "selectTable",
  data() {
    return {

      total: 0,
      //表单验证
      rules: {
        userName: [{ required: true, message: "姓名不能为空", trigger: "blur" }]
      },
      tableData:[],
      formData:{
        userName:"",
        position:"",
        rows: 15,
        page: 1,
      },
      queryInfo:{},
      showTree: false,
      selectData:{
        userName:''
      }
    }
  },
  mounted() {
    this.getTableData()
  },
  methods: {
    // 获取查询数据
    getTableData() {
      this.$axios.get('/api/smartbs/userPower/selectPersonList',{params:this.formData}).then((res) => {
        if (res.data.success) {
          this.tableData = res.data.data.rows
          this.total = res.data.data.total
        }
      })
    },
    // 点击input 阻止冒泡 控制table显示隐藏
    deptogglePanel (event) {
      event || (event = window.event)
      event.stopPropagation ? event.stopPropagation() : (event.cancelBubble = true)
      this.showTree ? this.tableHide() : this.tableShow()
    },
    tableShow() {
      this.showTree = true
      document.addEventListener('click', this.tableHideList, false)
    },
    tableHide() {
      this.showTree = false
      document.addEventListener('click', this.tableHideList, false)
    },
    tableHideList(e) {
      if (this.$refs.tableList&& !this.$refs.tableList.contains(e.target)) {
        this.tableHide()
      }
    },
    // 点击table节点
    handleRegionNodeClick (data) {
      this.selectTableId = data.id
      this.showTree = false
      this.$refs.verification.resetFields();
      this.selectData.userName = data.userName // 用户名字
      this.$emit('getUserName',this.selectData.userName)
    },
    dolNandleSizeChange(val) {
      this.formData.rows = val;
      this.formData.page = 1;
      this.getTableData()
    },
    dolHandleCurrentChange(val) {
      this.formData.page = val;
      this.getTableData()
    },
    // 手动输入
    changeTab(val) {
      this.$emit('getUserName',val)
    },
    // 表单验证
    submitForm() {
      this.$refs.verification.validate((valid) => {
        if (valid) {
          return valid
        } else {
          return false;
        }
      });
    },
  }
}
<style scoped lang="less">
.select-table {
  position: relative;
}
.treeDiv{
  width: 100%;
  margin-left: 80px;
  position:absolute;
  top: 50px;
  z-index: 999;
  background-color: #FFFFFF;
  border: 1px solid #e5e5e5;
  border-radius: 4px;
  padding: 10px;
  .el-table{
    border: 1px solid #ccc;
    border-radius: 6px;
  }
  .el-table /deep/ td{
    padding: 4px 0;
  }
}
</style>
作为一款前端MVVM框架,Vue能够方便地创建复杂的UI组件。在Vue的丰富生态中,有许多可用的扩展组件库,可以大大减轻开发者的开发难度。其中,一个非常实用的组件下拉表格组件,也称为combo grid。在这里,我们介绍一个基于Vue下拉表格组件el-combo-grid。 简介 el-combo-grid是一个基于Vue下拉表格组件,它可以方便地实现下拉选择和表格展示的功能。使用el-combo-grid,我们可以将表格数据作为下拉列表的选项,用户可以通过下拉列表选择一行数据,也可以通过表格展示更多的数据信息。同时,el-combo-grid还支持简单的分页和过滤功能,可以更好地展示大量数据。 特性 - 支持下拉选择和表格展示两种模式 - 支持分页和过滤功能 - 支持自定义模板和样式 - 支持异步数据加载 安装 el-combo-grid可以通过npm安装: npm install el-combo-grid 引入 在vue组件中引入el-combo-grid: import ElComboGrid from 'el-combo-grid'; Vue.component('el-combo-grid', ElComboGrid); 使用 el-combo-grid的使用非常简单,只需要将数据作为props传入即可。以下是一个简单的例子: <template> <div> <el-combo-grid v-model="selected" :data="data" :columns="columns"></el-combo-grid> </div> </template> <script> export default { data() { return { selected: {}, data: [ {id: 1, name: 'apple', price: 5.99}, {id: 2, name: 'banana', price: 2.99}, {id: 3, name: 'orange', price: 3.99}, {id: 4, name: 'pear', price: 4.99}, ], columns: [ {field: 'id', title: 'ID'}, {field: 'name', title: 'Name'}, {field: 'price', title: 'Price'}, ], }; }, }; </script> 在这个例子中,我们将一个包含4行数据的数组作为数据传入el-combo-grid组件中。同时,我们定义了3列字段,用于展示id、name、price三个属性。在页面上,我们可以通过下拉列表选择一行数据,也可以通过表格展示所有的数据。当用户选择数据时,会将选择的数据绑定到selected变量中。 总结 el-combo-grid是一个非常实用的下拉表格组件,可以方便地实现下拉选择和表格展示的功能。它支持分页和过滤功能,也支持自定义模板和样式。如果你需要在Vue项目中使用下拉表格组件,不妨试试el-combo-grid。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值