element-ui el-table动态多级表头

<template>
  <div class="table_class">
    <el-table :data="tableData2" style="width: 98%;">
      <el-table-column
        prop="orgName"
        label="机构名称"
        align="center"
        width="150"
      ></el-table-column>
      <el-table-column
        v-for="(item, index) in tableHeaders"
        :key="index"
        :label="item.label"
        :prop="item.prop"
        align="center"
      >
        <el-table-column label="人均" align="center">
          <template slot-scope="scope">
            <!-- <span>{{ scope.row.regList[index].need }}</span> -->
            <el-input
              v-model="scope.row.regList[index].province"
              @change="handleEdit(scope.$index, scope.row.regList[index])"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column label="人数" align="center">
          <template slot-scope="scope">
            <!-- <span>{{ scope.row.regList[index].reply }}</span> -->
            <el-input
              v-model="scope.row.regList[index].reply"
              @change="handleEdit(scope.$index, scope.row.regList[index])"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column label="总金额" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.regList[index].total }}</span>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 响应数据
      data: {
        records: [
          {
            orgName: "机构A",
            regList: [
              { province: "100", reply: "2", total: "50", regName: "事件A" },
              { province: "60", reply: "20", total: "50", regName: "事件A" },
              {
                province: "5000",
                reply: "5000",
                total: "50",
                regName: "事件A"
              },
              {
                province: "3000",
                reply: "3000",
                total: "50",
                regName: "事件C"
              },
              {
                province: "6000",
                reply: "5000",
                total: "50",
                regName: "事件C/事件B"
              }
            ]
          },
          {
            orgName: "机构B",
            regList: [
              { province: "10", reply: "5", total: "50", regName: "事件A" },
              {
                province: "10000",
                reply: "9000",
                total: "50",
                regName: "事件C"
              },
              {
                province: "10000",
                reply: "8000",
                total: "50",
                regName: "事件A"
              },
              {
                province: "8000",
                reply: "7000",
                total: "50",
                regName: "事件A"
              },
              { province: "8000", reply: "7000", total: "50", regName: "事件B" }
            ]
          },
          {
            orgName: "机构C",
            regList: [
              {
                province: "10000",
                reply: "9000",
                total: "50",
                regName: "事件A"
              },
              {
                province: "10000",
                reply: "9000",
                total: "50",
                regName: "事件C"
              },
              {
                province: "10000",
                reply: "8000",
                total: "50",
                regName: "事件A"
              },
              {
                province: "8000",
                reply: "7000",
                total: "50",
                regName: "事件A"
              },
              { province: "8000", reply: "7000", total: "50", regName: "事件B" }
            ]
          }
        ]
      },
      tableHeaders: [],
      tableData2: []
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.tableHeaders = [];
      for (let i of this.data.records[0].regList) {
        let obj = {
          label: i.regName,
          prop: ""
        };
        this.tableHeaders.push(obj);
        // this.tableData2 = this.data.records;
      }
      this.tableData2 = this.data.records;
    },
    handleEdit(a, B) {
      console.log(a, B);
      B.total = Number(B.province) * Number(B.reply);
    },
    handleEdit2(a, B) {
      console.log(a, Number(B));
      B.total = Number(B.province) * Number(B.reply);
    }
  }
};
</script>

<style>
.table_class {
  margin: 20px;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值