<template>
  <div class="common-table">
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column
        show-overflow-tooltip
        v-for="item in tableLabel"
        :key="item.prop"
        :label="item.label"
        :width="item.width ? item.width : 125"
        :formatter="formatter"
        :prop="item.prop"
        :min-width="item.minWidth"
      >
        <!-- <template slot-scope="scope">
          <span  style="margin-left: 10px">{{ scope.row[item.prop] }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="操作" min-width="180">
        <template slot-scope="scope">
          <span v-for="item in tableButton" :key="item.name" style="margin: 5px">
            <el-button
              :size="item.size"
              :type="item.type"
              @click="handle(scope.row, item.name)"
              >{{ item.name }}</el-button
            >
          </span>
          <!-- <el-button size="mini" type="primary" @click="handle(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { Table } from 'element-ui'
/* eslint-disable */
export default {
  name: "CommonTable",
  props: {
    tableData: Array,
    tableLabel: Array,
    tableButton: Array,
  },
  data() {
    return {
      doc: {
        status_dict: {
          1: "正常",
          2: "禁用",
          3: "黑名单",
        },
      },
    };
  },
  methods: {
    handle(row, method) {
      this.$emit("edit", row, method);
    },
    handleDelete(row) {
      this.$emit("del", row);
    },
    formatter(row, column) {
      
      if (column.label == "状态") {
        return this.doc.status_dict[row.status];
      }
      let tempData = null
      let temp =this.tableLabel.map(element => {
        //标签
        if(element.label==column.label){
          tempData = row[element.prop]
          return 
        }
      })
      return tempData
      // return column;
    },
  },
  mounted() {
    //   console.log("tableData")
    //   console.log(this.tableData)
    //   console.log("tableLabel")
    //   console.log(this.tableLabel)
    //   console.log("config")
    //   console.log(this.config)
  },
};

/* eslint-disable */
</script>
<style lang="less" scoped>
.common-table {
  // 小bug 窗口大小有问题
  background-color: #fff;
  position: relative;
  .pager {
    position: absolute;
    bottom: 0;
    right: 20px;
  }
}
</style>
父组件
import CommonTable from "frontelementpackage/src/CommonTableButton.vue";
html 中
<common-table
        :tableData="tableData.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
        :tableLabel="tableLabel"
        :tableButton="tableButton"
        @edit="editUser"
        @del="delUser"
      ></common-table>


data中
tableButton: [
        {
          name: "11",
          type: "danger",
          size: "small",
        },
        {
          name: "15",
          type: "danger",
          size: "small",
        },
        {
          name: "11",
          type: "danger",
          size: "small",
        },
      ],


tableLabel: [
        {
          prop: "name",
          label: "账户名字",
          width: 200,
        },
        {
          prop: "email",
          label: "邮箱",
          width: 200,
        },
        {
          prop: "phone",
          label: "手机号",
          width: 200,
        },
        {
          prop: "garage_account_relevance_count",
          label: "子账户账号",
          reflect:0,
          width: 200,
        },
        {
          prop: "status",
          label: "状态",
          width: 200,
        },
      ],

tableData: [],

method中

editUser(row,methods) {
      console.log(row,methods)
    },









