<template>
  <div class="home">
    <div class="part-box part-box-pad part-box-flex">
      <div></div>
      <div>
        <el-button type="primary" icon="el-icon-refresh" @click="toAdd"
          >新增标准题卡</el-button
        >
        <el-button type="success" icon="el-icon-refresh" @click="toFreeAdd"
          >新增自由题卡</el-button
        >
      </div>
    </div>
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="cards">
        <el-table-column type="index" label="序号" width="70"></el-table-column>
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column class-name="action-column" label="操作" width="200px">
          <template slot-scope="scope">
            <el-button
              class="btn-primary"
              type="text"
              @click="toEdit(scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="total,prev, pager, next"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "home",
  data() {
    return {
      current: 1,
      size: 10,
      total: 10,
      cards: []
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.cards = [
        {
          id: "1111",
          name: "题卡001"
        },
        {
          id: "2222",
          name: "题卡002"
        }
      ];
      this.total = this.cards.length;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toEdit(row) {
      this.$ls.set("prepareTcPCard", {
        examTaskId: "1111",
        courseCode: "数学",
        courseName: "sx001",
        makeMethod: "SELF",
        cardRuleId: "1"
      });
      this.$router.push({
        name: "CardFreeEdit",
        params: {
          cardId: row.id
        }
      });
    },
    toAdd() {
      this.$ls.set("prepareTcPCard", {
        examTaskId: "1111",
        courseCode: "数学",
        courseName: "sx001",
        makeMethod: "SELF",
        cardRuleId: "1"
      });
      this.$router.push({
        name: "CardEdit"
      });
    },
    toFreeAdd() {
      this.$ls.set("prepareTcPCard", {
        examTaskId: "1111",
        courseCode: "数学",
        courseName: "sx001",
        makeMethod: "SELF",
        cardRuleId: "1"
      });
      this.$router.push({
        name: "CardFreeEdit"
      });
    }
  }
};
</script>

<style scoped>
.home {
  background: #eff0f5;
  padding: 20px;
}
</style>