el-table高度适应外围容器,ag-gride高度适应外围容器

1.1 el-table

<template>
  <div class="organization_setting">
    <div class="header">
      <el-select
        filterable
        clearable
        size="mini"
        v-model="searchId"
        @change="change"
        placeholder="请选择机构"
      >
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <el-button size="mini" type="primary" @click="add">添加机构</el-button>
    </div>
    <div class="table">
      <div class="content" ref="organizationContainer">
        <el-table :height="height" :data="tableData" style="width: 100%" v-loading="tableLoading">
          <el-table-column
            prop="orgSname"
            label="机构名称"
            :formatter="emptyFormatter"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="orgName"
            label="机构全称"
            :formatter="emptyFormatter"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="orgContact"
            label="机构联系人"
            :formatter="emptyFormatter"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column prop="orgContactNo" label="联系方式" :formatter="emptyFormatter">
          </el-table-column>
          <el-table-column
            prop="orgEmail"
            label="公共邮箱"
            :formatter="emptyFormatter"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column prop="handle" label="操作" width="180">
            <template slot-scope="{ row }">
              <el-button size="mini" type="text" @click="edit(row)">编辑</el-button>
              <el-button size="mini" type="text" @click="deleteData(row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="page">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[50, 100, 200]"
          :page-size.sync="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <Create :visible.sync="visible" :title="title" :type="type" :row="row" @fresh="listOrgInfo" />
  </div>
</template>

<script>
import { listOrgInfo, delOrgInfoById, listOrgInfoCheckBox } from "@/pc/api/InternalEvaluate";
import Create from "./Create.vue";
import { __values } from "tslib";
export default {
  name: "organizationSetting",
  data() {
    return {
      height:200,
      title: "新增机构",
      visible: false,
      tableLoading: false,
      row: {},
      type: "add",
      searchId: "",
      options: [],
      tableData: [],
      pageSize: 100,
      currentPage: 1,
      total: 0
    };
  },
  components: {
    Create
  },
  methods: {
    emptyFormatter(row, colum, cellValue, index) {
      return cellValue == 0 || cellValue ? cellValue : "-";
    },
    listOrgInfo() {
      const data = { pageSize: this.pageSize, pageNo: this.currentPage, id: this.searchId };
      this.tableLoading = true;
      listOrgInfo(data)
        .then(res => {
          this.tableData = res.list;
          this.total = res.total;
          // 刷新筛选的列表
          this.listOrgInfoCheckBox();
        })
        .finally(() => {
          this.tableLoading = false;
        });
    },
    add() {
      this.title = "新增机构";
      this.type = "add";
      this.visible = true;
    },
    edit(row) {
      this.type = "edit";
      this.title = "修改机构";
      this.row = row;
      this.visible = true;
    },
    deleteData(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          delOrgInfoById({ id: row.id }).then(res => {
            this.$message.success("删除成功!");
            this.listOrgInfo();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    listOrgInfoCheckBox() {
      listOrgInfoCheckBox().then(res => {
        this.options = res;
      });
    },
    change(value) {
      this.searchId = value;
      this.listOrgInfo();
    },
    handleCurrentChange(value) {
      this.currentPage = value;
      this.listOrgInfo();
    },
    handleSizeChange(value) {
      this.pageSize = value;
      this.listOrgInfo();
    }
  },
  mounted() {
    this.$nextTick(() => {
      const rect = this.$refs.organizationContainer.getBoundingClientRect();
      this.height = rect.height;
    });
  },
  created() {
    this.listOrgInfo();
    this.listOrgInfoCheckBox();
  }
};
</script>

<style lang="less" scoped>
.organization_setting {
  height: 100%;
  display: flex;
  flex-direction: column;
  .header {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
  }
  .table {
    height: 100%;
    display: flex;
    flex: 1;
    flex-direction: column;
    .content {
      flex: 1;
    }
    .page {
      padding: 8px 0;
      text-align: right;
    }
  }
}
</style>

1.2 ag-gride适应外围容器

<template>
  <div class="conflict-deal">
    <div class="header">
      <div>
        <el-input
          prefix-icon="el-icon-search"
          size="mini"
          style="width:220px;margin-right:10px"
          placeholder="搜索用户名、拼音"
          clearable
          v-model="searchInfo.str"
        ></el-input>
        <el-select
          filterable
          clearable
          size="mini"
          v-model="searchInfo.searchId"
          @change="change"
          placeholder="请选择机构"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div>
        <OpenButton @click="openClick" />
        <el-button size="mini" type="primary" @click="exportData">导出</el-button>
      </div>
    </div>
    <div class="table">
      <div class="content">
        <ag-basic-table
          style="width: 100%;height: 100%"
          :tableData="tableData"
          :embedFullWidthRows="true"
          :isRowMaster="isRowMaster"
          :masterDetail="true"
          :detailCellRenderer="detailCellRenderer"
          :components="customComponents"
          :defaultColDef="defaultColDef"
          :detailRowAutoHeight="true"
          @grid-ready="onGridReady"
          :columns="getColumns()"
        />
      </div>
      <div class="page">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[50, 100, 200]"
          :page-size.sync="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import AgBasicTable from "@/pc/components/AgBasicTable.vue";
import OpenButton from "./OpenButton.vue";
import ConflictDetail from "./ConflictDetail.vue";
export default {
  name: "ConflictDeal",
  components: {
    AgBasicTable,
    OpenButton,
    // eslint-disable-next-line vue/no-unused-components
    ConflictDetail
  },
  data() {
    return {
      defaultColDef: { flex: 1 },
      gridApi: null,
      customComponents: { ConflictDetail: ConflictDetail },
      detailCellRenderer: "ConflictDetail",
      title: "新增机构",
      visible: false,
      tableLoading: false,
      searchInfo: {
        str: "",
        searchId: ""
      },
      row: {},
      options: [],
      tableData: [
        { name: "zhangsna", conflictTraderNum: 2 },
        { name: "zhangsna", conflictTraderNum: 0 }
      ],
      pageSize: 100,
      currentPage: 1,
      total: 0
    };
  },
  methods: {
    onGridReady(params) {
      this.gridApi = params.api;
    },
    isRowMaster(dataItem) {
      console.log("dataItem", dataItem);
      return dataItem ? true : false;
    },
    getColumns() {
      return [
        {
          prop: "name",
          label: "姓名"
        },
        {
          prop: "phoneCode",
          label: "手机号"
        },
        {
          prop: "conflictTraderNum",
          label: "冲突券商数量",
          cellStyle: () => ({
            display: "flex",
            "justify-content": "center"
          }),
          cellRenderer: "agGroupCellRenderer"
        },
        {
          prop: "handel",
          label: "操作",
          render: () => {
            return (
              <el-button type="text" size="mini">
                {" "}
                展开详情
              </el-button>
            );
          }
        }
      ];
    },
    openClick(flag) {
      console.log(flag);
    },
    exportData() {
      // 导出
    },
    change(value) {
      this.searchId = value;
    },
    handleCurrentChange(value) {
      this.currentPage = value;
    },
    handleSizeChange(value) {
      this.pageSize = value;
    }
  }
};
</script>

<style lang="less" scoped>
.conflict-deal {
  height: 100%;
  display: flex;
  flex-direction: column;
  .header {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
  }
  .table {
    height: 100%;
    display: flex;
    flex: 1;
    flex-direction: column;
    .content {
      flex: 1;
    }
    .page {
      padding: 8px 0;
      text-align: right;
    }
  }
}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

好喝的西北风

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

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

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

打赏作者

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

抵扣说明:

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

余额充值