<template>
  <div class="common-table">
    <el-table :data="tableData" stripe>
      <el-table-column
        show-overflow-tooltip

        v-for="item in tableLabel"
        :key="item.prop"
        :label="item.label"
        :min-width="item.width ? item.width : 125"
        :formatter="formatter"
        :prop="item.prop"
        :fixed="item.position"
      >
        <!-- <template slot-scope="scope">
          <span  style="margin-left: 10px">{{ scope.row[item.prop] }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="操作" min-width="150" fixed="right">
        <template slot-scope="scope">
         
          <el-dropdown type="primary">
        <el-button type="primary">
            更多<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown" >
            <el-dropdown-item v-for="item in tableDropdown" :key="item.name" @click.native="handle(scope.row, item.name)">{{ item.name }}</el-dropdown-item>
            
        </el-dropdown-menu>
        </el-dropdown>
      
        </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,
    tableDropdown: 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) {
      //object的处理
      if (column.label == "状态") {
        return this.doc.status_dict[row.status];
      }
      //object的处理
      if (column.label == "关联") {
        return "ID:"+row.parking_lot_index.id+"-LOT:"+row.parking_lot_index.parking_lot
      }
      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/CommonTableDropdown.vue";
html 中
<common-table
        :tableData="tableData"
        :tableLabel="tableLabel"
        :tableDropdown="tableDropdown"
        @edit="editUser"
        @del="delUser"
      ></common-table>


data中
tableDropdown: [
       {id:1,name:'测试1'},
        {id:2,name:'测试2'},
        {id:3,desc:'测试3'}
      ],


tableLabel: [
        {
          prop: "name",
          label: "账户名字",
          width: 100,
        },
       
        {
          prop: "status",
          label: "状态",
          width: 200,
        },
      ],

tableData: [{
  name:"测试",
  status:1
}],

method中
@edit=是必须要的
editUser(row,methods) {
      console.log(row,methods)
    },









