<template>
  <div class="table">
    <table>
      <thead>
        <tr>
          <td>成员</td>
          <td>操作</td>
        </tr>
      </thead>
      <tbody>
        <tr
          v-for="(obj, index) in tableData"
          :key="index"
          :class="{ table_gray: index % 2 === 0 }"
        >
          <td style="width: 50%">
            <p>{{ obj.dlrName }}</p>
          </td>
          <td style="width: 50%" class="operation">
            <span @click="showModal(index)">删除</span>
          </td>
        </tr>
      </tbody>
    </table>
    <DeleteModal
      @detlet_data="detletData"
      @hide_modal="closeModal"
      :modalFlag="deleteModalFlag"
    ></DeleteModal>
  </div>
</template>

<script>
import DeleteModal from "../DeleteModal";
export default {
  props: {
    // 表数据
    tableData: {
      type: Array,
      default: () => {
        return [];
      },
    },
    //  表格一页共有多少数据
    pageSize: {
      type: Number,
      default: 2,
    },
  },
  components: {
    DeleteModal,
  },
  data() {
    return {
      deleteModalFlag: false,
      index: 0,
      newName: "", // 编辑之后的值
    };
  },
  methods: {
    // 点击删除，展示模态框
    showModal: function (i) {
      this.deleteModalFlag = true;
      this.index = i;
    },
    // 模态框确认删除
    detletData: function () {
      this.deleteModalFlag = false;
      this.$emit("delet_data", this.index);
    },
    // 模态框取消
    closeModal: function () {
      this.deleteModalFlag = false;
    },
    mounted() {
    },
  },
};
</script>

<style scoped lang="less">
.table {
  background-color: #fff;
  width: 100%;
  margin-top: 10px;
  text-align: center;
  table {
    width: 100%;
    border-collapse: collapse;
    border: none;
    thead {
      td {
        background: #8d9092;
        height: 36px;
        color: #fff;
        border: 1px solid #ccc;
      }
    }
    tbody {
      td {
        height: 36px;
        border: 1px solid #ccc;
      }
      .operation {
        span {
          color: #00f;
          margin: 0 20px;
          &:hover {
            cursor: pointer;
          }
        }
      }
    }
  }
}
.table_gray {
    background: #f5f5f5
}
</style>
