<template>
  <div style="width: 100%">
    <el-main>
      <div class="tou">
        <span>五育融合</span>
      </div>
      <div class="pb_content_body">
        <div class="student_head">
          <div>
            <el-button type="primary" @click="dialogVisible = true"
              >添加</el-button
            >
          </div>
        </div>
        <div class="student_table">
          <el-table
            ref="table"
            :data="tableData"
            border
            :height="tableHeight"
            :fit="true"
            style="width: 100%"
            :header-cell-style="{ background: '#f1f1f1' }"
            :row-class-name="tableRowClassName"
            v-loading="loading"
          >
            <el-table-column prop="title" label="五育" min-width="40">
            </el-table-column>
            <el-table-column label="操作" min-width="10">
              <template slot-scope="scope">
                <el-button
                  @click="goTo('/five/fiveDetail')"
                  type="text"
                  size="small"
                  >点击查看</el-button
                >
                <el-button
                  @click="getNotice(scope.row.id)"
                  type="text"
                  size="small"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="student_page">
          <el-pagination
            background
            layout="prev, pager, next"
            :page-size="10"
            :total="total"
            @current-change="handleCurrentChange"
          >
          </el-pagination>
        </div>
      </div>
    </el-main>
    <el-dialog
      title="添加"
      :visible.sync="dialogVisible"
      :append-to-body="true"
      width="450px"
      :before-close="handleClose"
      class="dialog_diy"
    >
      <el-form>
        <el-form-item label="五育" :label-width="formLabelWidth">
          <el-input
            v-model="name"
            auto-complete="off"
            placeholder="请输入..."
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableHeight: 50,
      name: "",
      formLabelWidth: "100px",
      dialogVisible: false,
      loading: false,
      tableData: [
        { title: "以劳树德", id: 1 },
        { title: "以劳强体", id: 2 },
        { title: "以劳育美", id: 3 },
        { title: "以劳增智", id: 4 },
      ],
      page: 1,
      total: 0,
      res: [],
    };
  },
  mounted() {
    this.$nextTick(function () {
      this.tableHeight =
        window.innerHeight - this.$refs.table.$el.offsetTop - 200;
      if (this.tableHeight <= 530) {
        this.tableHeight = 530;
      }
      // 监听窗口大小变化
      let self = this;
      window.onresize = function () {
        self.tableHeight =
          window.innerHeight - self.$refs.table.$el.offsetTop - 200;
        if (self.tableHeight <= 530) {
          self.tableHeight = 530;
        }
      };
    });
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if ((rowIndex + 1) % 2 === 0) {
        return "even_row";
      } else {
        return "";
      }
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getNews();
      console.log(`当前页: ${val}`);
    },
    handleClose(done) {
      done();
    },
    goTo(path) {
      this.$router.push(path);
    },
  },
};
</script>

<style scoped>
.dialog_diy >>> .el-dialog__header {
  background: #3d67bc !important;
  padding: 15px 20px;
}
.dialog_diy >>> .el-dialog__title {
  color: #fff;
}
.dialog_diy >>> .el-dialog__headerbtn {
  top: 19px;
}
.dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
.dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  color: #fff;
}
.student_head >>> .el-button--primary {
  background-color: #2268bc;
  border: none;
}
.student_head {
  display: flex;
  justify-content: flex-end;
}
.student_table {
  margin: 20px 0;
}

.el-table >>> .even_row {
  background-color: #f1f1f1;
}
.el-table >>> .cell {
  white-space: nowrap;
}
</style>
