<template>
  <div class="print-room-manage">
    <div class="part-box part-box-filter part-box-flex">
      <div></div>
      <div class="part-box-action">
        <el-button
          type="primary"
          icon="el-icon-circle-plus-outline"
          @click="toAdd"
          >新增印刷室</el-button
        >
      </div>
    </div>
    <div class="part-box">
      <el-table ref="TableList" :data="dataList" border stripe>
        <el-table-column prop="name" label="印刷室名称"></el-table-column>
        <el-table-column prop="code" label="印刷室编码"></el-table-column>
        <el-table-column prop="campus" label="所属校区"></el-table-column>
        <el-table-column label="操作" align="center" width="120px">
          <template slot-scope="scope">
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-edit"
              @click="toEdit(scope.row)"
              title="编辑"
            ></el-button>
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-delete"
              @click="toDelete(scope.row)"
              title="删除"
            ></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>

    <modify-print-room
      :instance="curRow"
      @modified="getList"
      ref="ModifyPrintRoom"
    ></modify-print-room>
  </div>
</template>

<script>
import { printRoomQuery, deletePrintRoom } from "../api";
import ModifyPrintRoom from "../components/ModifyPrintRoom";

export default {
  name: "print-room-manage",
  components: { ModifyPrintRoom },
  data() {
    return {
      dataList: [],
      curRow: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      this.dataList = await printRoomQuery();
    },
    toAdd() {
      this.curRow = {};
      this.$refs.ModifyPrintRoom.open();
    },
    toEdit(row) {
      this.curRow = row;
      this.$refs.ModifyPrintRoom.open();
    },
    toDelete(row) {
      this.$confirm(`确定要删除印刷室【${row.name}】吗?`, "提示", {
        cancelButtonClass: "el-button--danger is-plain",
        confirmButtonClass: "el-button--primary",
        type: "warning"
      })
        .then(async () => {
          await deletePrintRoom(row.id);
          this.$message.success("删除成功！");
          this.deletePageLastItem();
        })
        .catch(() => {});
    }
  }
};
</script>
