欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

el-table實(shí)現(xiàn)嵌套表格的展示功能(完整代碼)

 更新時(shí)間:2024年02月21日 11:35:37   作者:小阮的學(xué)習(xí)筆記  
el-table中在嵌套一個(gè)el-table,這樣數(shù)據(jù)格式就沒(méi)問(wèn)題了,主要就是樣式,將共同的列放到一列中,通過(guò)渲染自定義表頭render-header,將表頭按照合適的寬度渲染出來(lái),本文給大家分享el-table實(shí)現(xiàn)嵌套表格的展示功能,感興趣的朋友一起看看吧

需求

一個(gè)表單中存在子表

列表返回格式

在這里插入圖片描述

實(shí)現(xiàn)

實(shí)現(xiàn)思路

el-table中在嵌套一個(gè)el-table,這樣數(shù)據(jù)格式就沒(méi)問(wèn)題了,主要就是樣式

將共同的列放到一列中,通過(guò)渲染自定義表頭render-header,將表頭按照合適的寬度渲染出來(lái)

 <el-table-column
   prop="table"
   label="子表"
   class-name="has-child"
   :render-header="renderHeader"
   :width="childColumn.length * 120 + 2 + 'px'"
 >
   <template slot-scope="scope">
     <el-table
       border
       :data="scope.row.details"
       class="child-table"
       :show-header="false"
     >
       <el-table-column
         prop="startDate"
         align="center"
         label="起始日期"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="endDate"
         align="center"
         label="結(jié)束日期"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="applyDay"
         align="center"
         label="申請(qǐng)?zhí)鞌?shù)"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="destination"
         align="center"
         label="目的地"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="transportation"
         align="center"
         label="交通方式"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="businessTripReason"
         align="center"
         label="出差事由"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="returnDate"
         align="center"
         label="返程日期"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="actualDay"
         align="center"
         label="實(shí)際出差天數(shù)"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="subsidyDay"
         align="center"
         label="差補(bǔ)天數(shù)"
         width="120px"
       ></el-table-column>
       <el-table-column
         prop="remark"
         align="center"
         label="備注"
         width="120px"
       ></el-table-column>
     </el-table>
   </template>
 </el-table-column>

根據(jù)數(shù)據(jù)渲染表頭

      childColumn: [
        {
          label: "起始日期",
          width: "120px",
        },
        {
          label: "結(jié)束日期",
          width: "120px",
        },
        {
          label: "申請(qǐng)?zhí)鞌?shù)",
          width: "120px",
        },
        {
          label: "目的地",
          width: "120px",
        },
        {
          label: "交通方式",
          width: "120px",
        },
        {
          label: "出差事由",
          width: "120px",
        },
        {
          label: "返程日期",
          width: "120px",
        },
        {
          label: "實(shí)際出差天數(shù)",
          width: "120px",
        },
        {
          label: "差補(bǔ)天數(shù)",
          width: "120px",
        },
        {
          label: "備注",
          width: "120px",
        },
      ],
    /**
     * @description 渲染子表
     */
    renderHeader(h, { column, $index }) {
      const childTable = this.childColumn.map((item) => {
        return h(
          "div",
          {
            style: {
              width: item.width,
              padding: "0 10px",
              textAlign: "center",
              flexShrink: 0,
              flexGrow: 0,
            },
          },
          item.label
        );
      });
      return h(
        "div",
        {
          class: ["child-head"],
        },
        childTable
      );
    },

調(diào)樣式,慢慢調(diào)到合適就行

.has-child {
  padding: 0px !important;
  // display: none;
  & > .cell {
    padding: 0 !important;
  }
  ::before {
    height: 0;
  }
  .child-table {
    background-color: transparent;
    .cell{
      line-height: 34px;
    }
  }
  .el-table--enable-row-hover .el-table__body tr:hover > td.el-table__cell {
    background-color: transparent;
  }
  .el-table__body tr.current-row > td.el-table__cell,
  .el-table__body tr.selection-row > td.el-table__cell {
    background-color: transparent;
  }
  tr {
    background-color: transparent;
  }
  .child-head {
    display: flex;
  }
}

完整代碼

<template>
  <div>
    <Search :config="searchConfig" @search="search">
      <el-button type="primary" @click="addItem" icon="el-icon-plus"
        >新增</el-button
      >
    </Search>
    <el-table
      border
      :data="tableData"
      v-loading="loading"
      class="el-child-table"
    >
      <el-table-column
        prop="applyDate"
        label="申請(qǐng)日期"
        align="center"
        width="120px"
      >
      </el-table-column>
      <el-table-column
        prop="nickName"
        label="申請(qǐng)人"
        align="center"
        width="140px"
      >
      </el-table-column>
      <el-table-column
        prop="deptName"
        label="申請(qǐng)部門"
        align="center"
        width="120px"
      >
      </el-table-column>
      <el-table-column
        prop="table"
        label="子表"
        class-name="has-child"
        :render-header="renderHeader"
        :width="childColumn.length * 120 + 2 + 'px'"
      >
        <template slot-scope="scope">
          <el-table
            border
            :data="scope.row.details"
            class="child-table"
            :show-header="false"
          >
            <el-table-column
              prop="startDate"
              align="center"
              label="起始日期"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="endDate"
              align="center"
              label="結(jié)束日期"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="applyDay"
              align="center"
              label="申請(qǐng)?zhí)鞌?shù)"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="destination"
              align="center"
              label="目的地"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="transportation"
              align="center"
              label="交通方式"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="businessTripReason"
              align="center"
              label="出差事由"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="returnDate"
              align="center"
              label="返程日期"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="actualDay"
              align="center"
              label="實(shí)際出差天數(shù)"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="subsidyDay"
              align="center"
              label="差補(bǔ)天數(shù)"
              width="120px"
            ></el-table-column>
            <el-table-column
              prop="remark"
              align="center"
              label="備注"
              width="120px"
            ></el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column
        prop="processStatusName"
        width="120px"
        label="狀態(tài)"
        align="center"
      >
      </el-table-column>
      <el-table-column label="操作" align="center" width="100px" fixed="right">
        <template slot-scope="{ row }">
          <!-- 1、狀態(tài)為被退回  2、申請(qǐng)人為當(dāng)前登陸人 -->
          <el-button
            v-if="row.approveJurisdiction == 1"
            type="text"
            @click="approval(row)"
            >審批</el-button
          >
          <el-button
            type="text"
            @click="check(row)"
            v-if="row.checkJurisdiction == 1"
            >核定</el-button
          >
          <el-button
            v-if="
              row.processStatusName == '被退回' &&
              row.nickName === $store.state.user.nickName
            "
            type="text"
            @click="editItem(row)"
            >修改</el-button
          >
          <el-button type="text" @click="viewItem(row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="pageInfo.total"
      :page.sync="pageInfo.pageNum"
      :limit.sync="pageInfo.pageSize"
      @pagination="getList"
    />
    <DialogForm ref="dialogFormRef" @success="submitSuccess"></DialogForm>
  </div>
</template>
<script>
import Search from "@/components/Search/index.vue";
import DialogForm from "./components/form.vue";
import { checkRole } from "@/utils/permission";
import {
  apiGetBusinessTripList,
  apiGetStatusOption,
} from "@/api/businessTrip/index";
export default {
  name: "BusinessTrip",
  components: {
    Search,
    DialogForm,
  },
  data() {
    return {
      searchConfig: [
        {
          label: "申請(qǐng)日期",
          prop: "publishTime",
          type: "daterange",
        },
        {
          type: "select",
          label: "狀態(tài)",
          prop: "processStatus",
          option: [],
        },
        {
          type: "input",
          label: "模糊查詢",
          prop: "queryCondition",
        },
      ],
      pageInfo: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      tableData: [],
      childColumn: [
        {
          label: "起始日期",
          width: "120px",
        },
        {
          label: "結(jié)束日期",
          width: "120px",
        },
        {
          label: "申請(qǐng)?zhí)鞌?shù)",
          width: "120px",
        },
        {
          label: "目的地",
          width: "120px",
        },
        {
          label: "交通方式",
          width: "120px",
        },
        {
          label: "出差事由",
          width: "120px",
        },
        {
          label: "返程日期",
          width: "120px",
        },
        {
          label: "實(shí)際出差天數(shù)",
          width: "120px",
        },
        {
          label: "差補(bǔ)天數(shù)",
          width: "120px",
        },
        {
          label: "備注",
          width: "120px",
        },
      ],
      disabled: true,
      currentItem: {},
      searchForm: {},
      loading: false,
    };
  },
  mounted() {
    this.getStatusOption();
    this.toApproval();
  },
  activated() {
    this.getList();
    this.toApproval();
  },
  methods: {
    checkRole,
    /**
     * @description 從首頁(yè)過(guò)來(lái)自動(dòng)打開(kāi)彈窗
     */
    toApproval() {
      const id = this.$route.query.approvalId;
      const jumpType = this.$route.query.jumpType;
      this.$nextTick(() => {
        if (jumpType == 21) {
          this.$refs.dialogFormRef.open("審批", id);
        } else if (jumpType == 22) {
          this.$refs.dialogFormRef.open("核定", id);
        }
      });
    },
    search(form) {
      this.searchForm = form;
      this.getList();
    },
    getList() {
      this.loading = true;
      const params = {
        ...this.searchForm,
        ...this.pageInfo,
        startApplyDate:
          this.searchForm.publishTime && this.searchForm.publishTime[0],
        endApplyDate:
          this.searchForm.publishTime && this.searchForm.publishTime[1],
      };
      Reflect.deleteProperty(params, "publishTime");
      apiGetBusinessTripList(params)
        .then((response) => {
          this.tableData = response.data.records;
          this.pageInfo.total = response.data.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /**
     * @description 獲取流程狀態(tài)下拉
     */
    getStatusOption() {
      apiGetStatusOption().then((response) => {
        this.searchConfig[1].option = response.data.map((item) => {
          return {
            label: item.name,
            value: item.id,
          };
        });
      });
    },
    addItem() {
      this.$refs.dialogFormRef.open("新增");
    },
    approval(row) {
      this.$refs.dialogFormRef.open("審批", row.id);
    },
    check(row) {
      this.$refs.dialogFormRef.open("核定", row.id);
    },
    editItem(row) {
      this.$refs.dialogFormRef.open("修改", row.id);
    },
    viewItem(row) {
      this.$refs.dialogFormRef.open("詳情", row.id);
    },
    /**
     * @description 渲染子表
     */
    renderHeader(h, { column, $index }) {
      const childTable = this.childColumn.map((item) => {
        return h(
          "div",
          {
            style: {
              width: item.width,
              padding: "0 10px",
              textAlign: "center",
              flexShrink: 0,
              flexGrow: 0,
            },
          },
          item.label
        );
      });
      return h(
        "div",
        {
          class: ["child-head"],
        },
        childTable
      );
    },
    submitSuccess() {
      this.$router.replace({ path: "/businessTrip", query: {} });
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped></style>

到此這篇關(guān)于el-table實(shí)現(xiàn)嵌套表格的展示的文章就介紹到這了,更多相關(guān)el-table嵌套表格的展示內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue3數(shù)據(jù)可視化實(shí)現(xiàn)數(shù)字滾動(dòng)特效代碼

    vue3數(shù)據(jù)可視化實(shí)現(xiàn)數(shù)字滾動(dòng)特效代碼

    這篇文章主要介紹了vue3數(shù)據(jù)可視化實(shí)現(xiàn)數(shù)字滾動(dòng)特效,實(shí)現(xiàn)思路是使用Vue.component定義公共組件,使用window.requestAnimationFrame(首選,次選setTimeout)來(lái)循環(huán)數(shù)字動(dòng)畫,詳細(xì)代碼跟隨小編一起看看吧
    2022-09-09
  • Vue插件之滑動(dòng)驗(yàn)證碼用法詳解

    Vue插件之滑動(dòng)驗(yàn)證碼用法詳解

    這篇文章主要介紹了Vue插件之滑動(dòng)驗(yàn)證碼用法,結(jié)合實(shí)例形式詳細(xì)分析了Vue滑動(dòng)驗(yàn)證碼插件相關(guān)使用方法與操作注意事項(xiàng),需要的朋友可以參考下
    2020-04-04
  • vue-cli如何添加less 以及sass

    vue-cli如何添加less 以及sass

    本篇文章主要介紹了vue-cli如何添加less 以及sass,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-07-07
  • vue3如何通過(guò)ref獲取元素離頂部的距離

    vue3如何通過(guò)ref獲取元素離頂部的距離

    這篇文章主要給大家介紹了關(guān)于vue3如何通過(guò)ref獲取元素離頂部的距離,文中通過(guò)代碼以及圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue3具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-10-10
  • 八種vue實(shí)現(xiàn)組建通信的方式

    八種vue實(shí)現(xiàn)組建通信的方式

    這篇文章主要介紹是八種vue實(shí)現(xiàn)組建通信的方式,包括、props 父組件與子組件通信、$emit 子組件父組件傳遞、$emit與props結(jié)合 兄弟組件傳值等等,想具體了解的朋友可以參考下面文章的具體內(nèi)容
    2021-09-09
  • Vue中使用Element UI的Table組件實(shí)現(xiàn)嵌套表格功能

    Vue中使用Element UI的Table組件實(shí)現(xiàn)嵌套表格功能

    這篇文章主要介紹了Vue中使用Element UI的Table組件實(shí)現(xiàn)嵌套表格功能,演示如何在Vue中使用Element UI的Table組件實(shí)現(xiàn)嵌套表格,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-01-01
  • 前端vue如何通過(guò)URL訪問(wèn)存儲(chǔ)在服務(wù)器或磁盤的圖片

    前端vue如何通過(guò)URL訪問(wèn)存儲(chǔ)在服務(wù)器或磁盤的圖片

    在Vue中,通常需要將圖片存儲(chǔ)在服務(wù)器端,并通過(guò)url地址來(lái)訪問(wèn),下面這篇文章主要給大家介紹了前端vue如何通過(guò)URL訪問(wèn)存儲(chǔ)在服務(wù)器或磁盤的圖片的相關(guān)資料,需要的朋友可以參考下
    2024-02-02
  • Vue3+Element-Plus?實(shí)現(xiàn)點(diǎn)擊左側(cè)菜單時(shí)顯示不同內(nèi)容組件展示在Main區(qū)域功能

    Vue3+Element-Plus?實(shí)現(xiàn)點(diǎn)擊左側(cè)菜單時(shí)顯示不同內(nèi)容組件展示在Main區(qū)域功能

    這篇文章主要介紹了Vue3+Element-Plus?實(shí)現(xiàn)點(diǎn)擊左側(cè)菜單時(shí)顯示不同內(nèi)容組件展示在Main區(qū)域功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-01-01
  • vue使用Split封裝通用拖拽滑動(dòng)分隔面板組件

    vue使用Split封裝通用拖拽滑動(dòng)分隔面板組件

    這篇文章主要介紹了vue使用Split封裝通用拖拽滑動(dòng)分隔面板組件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Vue3指令之搜索框輸入防抖功能實(shí)現(xiàn)

    Vue3指令之搜索框輸入防抖功能實(shí)現(xiàn)

    在Vue開(kāi)發(fā)中遇到了搜索框輸入防抖處理,算是防抖的使用場(chǎng)景之一吧,這篇文章主要給大家介紹了關(guān)于Vue3指令之搜索框輸入防抖功能實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2022-12-12

最新評(píng)論