<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      highlight-current-row
      element-loading-text="数据加载中..."
      @selection-change="handlerSelectChange"
      @select="handlerSelect"
      @select-all="handlerSelectAll"
    >
      <el-table-column
        label="序号"
        v-if="hasIndex"
        type="index"
        align="center"
        width="100"
      >
      </el-table-column>
      <el-table-column
        v-if="hasSelect"
        type="selection"
        width="38"
      ></el-table-column>
      <el-table-column v-if="hasExpand" type="expand" width="38">
        <template slot-scope="props">
          <my-form :formList="getList(props.row)"> </my-form>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item, index) in tableConfigArr"
        :key="index"
        :prop="item.prop"
        :label="item.label"
        align="center"
        :sortable="item.sortable"
      >
        <div slot-scope="scope">
          <slot v-if="item.slot" :name="item.slot" :row="scope.row"> </slot>
          <template v-else>
            <div>{{ scope.row[item.prop] }}</div>
          </template>
        </div>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: "my-form",
  props: {
    tableData: {
      type: Array,
      require: true,
      default: function () {
        return [];
      },
    },
    tableConfigArr: {
      type: Array,
      default: function () {
        return [];
      },
    },
    hasSelect: {
      type: Boolean,
      default: function () {
        return false;
      },
    },
    hasIndex: {
      type: Boolean,
      default: function () {
        return false;
      },
    },
    hasExpand: {
      type: Boolean,
      default: function () {
        return false;
      },
    },
  },

  data() {
    return {
      title: "变少",
      dialogFormVisible: false,
      
    };
  },
  computed: {
    getList() {
      return function (data) {
        let arr = [];
        for (let i in data) {
          let json = {};
          json[i] = data[i];
          json.type = "text";
          arr.push(json);
        }
        return arr;
      };
    },
  },

  methods: {
    handlerSelectAll(val) {
      this.$emit("handlerSelectAll", val);
    },
    handlerSelect(value, obj) {
      // 选中项
      this.$emit("handlerSelect", value);
    },
    handlerSelectChange(value) {
      this.$emit("handlerSelectChange", value);
    },
    edit(data) {
      console.log(data, "122122");
      this.dialogFormVisible = true;
    },
    deleteData(data) {
      console.log(data, "000000");
    },
    handleSumbit(data) {
      console.log(data, "我是子组件pop传来的");
      this.dialogFormVisible = data;
    },
  },

  mounted() {
    console.log(this.tableConfigArr);
  },
};
</script>

<style lang="scss" scoped>
</style>