<template>
  <div class="exam_plan_room_view pg-main">
    <div class="pg-title">
      <a href="javascript:void(0)" @click="goback" style="float: right"
        ><i class="fa fa-reply" aria-hidden="true"></i>返回</a
      >
      <span>查看考场数据</span>
    </div>
    <div class="pg-select-infos">
      <div style="margin-bottom: 15px">
        <span style="margin-right: 15px">共计导入</span>
        <Badge
          :count="placeList.length"
          overflow-count="1000000"
          class-name="demo-badge-alone"
        ></Badge
        >个考点，<Badge
          :count="roomList.length"
          class-name="demo-badge-alone"
          overflow-count="1000000"
        ></Badge
        >个考场
      </div>
      <Form ref="room_query_form" :label-width="80" inline>
        <Row :gutter="20">
          <Col span="8">
            <FormItem label="请选择考点" style="width: 100%">
              <Select v-model="query.placeCode">
                <Option value="">全部</Option>
                <Option
                  v-for="item in placeList"
                  :value="item.value"
                  :key="item.value"
                  >{{ item.name }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="4">
            <Button @click="doQuery" type="primary" icon="md-search"
              >查询</Button
            >
          </Col>
        </Row>
      </Form>
    </div>
    <div class="pg-body">
      <Table
        ref="room_table"
        :columns="columns"
        :border="true"
        :data="list"
      ></Table>
      <Page
        placement="top"
        :current="query.pageNo"
        :loading="true"
        :page-size="query.pageSize"
        :total="query.totalElements"
        show-total
        show-sizer
        @on-change="changePageNo"
        @on-page-size-change="changePageSize"
      ></Page>
    </div>
  </div>
</template>

<script>
import { axios } from "../../libs/http";
export default {
  name: "exam_plan_room_view",
  data() {
    return {
      last: "",
      query: {
        pageNo: 1,
        pageSize: 10,
        totalElements: 0,
        totalPages: 0,
        placeCode: "",
        examCode: "",
        attachmentId: "",
      },
      placeList: [],
      roomList: [],
      columns: [
        {
          type: "index_seq",
          title: "序号",
          align: "center",
          width: 65,
          render: (h, params) => {
            let a =
              (this.query.pageNo - 1) * this.query.pageSize + params.index + 1;
            return h("span", a);
          },
        },
        {
          title: "考场代码",
          key: "roomCode",
          minWidth: 150,
          align: "center",
        },
        {
          title: "考场名称",
          width: 150,
          key: "roomName",
          align: "center",
        },
        {
          title: "所属考点代码",
          key: "placeCode",
          minWidth: 150,
          align: "center",
        },
        {
          title: "所属考点名称",
          key: "placeName",
          minWidth: 150,
          maxWidth: 400,
          align: "center",
        },
        {
          title: "监考账号",
          key: "jkTeacher",
          minWidth: 150,
          align: "center",
        },
        {
          title: "监考密码",
          key: "jkPassword",
          minWidth: 150,
          align: "center",
        },
      ],
      list: [],
    };
  },
  computed: {
    avatorImage() {
      return localStorage.avatorImgPath;
    },
  },
  created() {
    this.query.examCode = this.$route.query.examCode;
    this.last = this.$route.query.last;
    if (
      this.query.attachmentId &&
      this.query.attachmentId != this.$route.query.attachmentId
    ) {
      this.query.pageNo = 1;
    }
    this.query.attachmentId = this.$route.query.attachmentId;
    if (!this.query.examCode || !this.query.attachmentId) {
      this.$Notice.error({
        title: "系统提示",
        desc: "<p>由于缺少考试识别码或者文件标识导致页面初始化失败</p>",
      });
      return;
    }
    axios.post("/system/examPlan/findAllPlace", this.query).then((response) => {
      let data = response.data.data;
      if (data) {
        this.placeList = data;
      }
    });
    axios.post("/system/examPlan/findAllRoom", this.query).then((response) => {
      let data = response.data.data;
      if (data) {
        this.roomList = data;
      }
    });
    this.load();
  },
  methods: {
    goback() {
      this.$router.push({ name: this.last, query: { _r: true } });
    },
    load() {
      axios
        .post("/system/examPlan/roomPageQuery", this.query)
        .then((response) => {
          let data = response.data.data;
          if (data) {
            this.list = data.content || [];
            this.query.totalElements = data.totalElements;
            this.query.totalPages = data.totalPages;
          }
        });
    },
    doQuery() {
      this.query.pageNo = 1;
      this.load();
    },
    changePageNo(p) {
      //切换页码
      this.query.pageNo = p;
      this.load();
    },
    changePageSize(pageSize) {
      //切换每一页显示多少条
      this.query.pageSize = pageSize;
      this.load();
    },
  },
};
</script>
