/* 
  等级列表
  author: zsy
  date: 2024-6-9
*/
<template>
  <div class="level-list">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index"> </el-table-column>
      <el-table-column prop="jrid" label="等级ID"> </el-table-column>
      <el-table-column prop="levelname" label="等级名称"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.row)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getLevel, delLevel } from "@/api/level";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    /* 获取等级列表 */
    getLevelList() {
      getLevel().then((res) => {
        console.log(res.data);
        this.tableData = res.data;
      });
    },
    /* 删除等级 */
    deleteRow(row) {
      console.log(row);
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delLevel({
            levelid: row.jrid
          })
            .then((res) => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getLevelList()
            })
            .catch((err) => {
              this.$message.error("删除失败");
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  created() {
    this.getLevelList();
  },
};
</script>

<style scoped>
.level-list {
  width: 60%;
  margin: 130px auto 0;
}
</style>