<template>
  <div class="exam_plan_room_uncoiling pg-main">
    <div class="pg-title">
      <span>开卷监控</span>
    </div>
    <div class="pg-select-infos">
      <Form ref="room_uncoiling_queryform_one" :label-width="80" inline>
        <Row :gutter="20">
          <Col span="10">
            <FormItem label="考试任务" style="width: 100%">
              <Select @on-change="selectExam" v-model="query.examCode">
                <Option value="">全部</Option>
                <Option
                  v-for="item in xldata.examCodeList"
                  :value="item.examCode"
                  :key="item.examCode"
                  >{{ item.name }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="10">
            <FormItem label="考点" style="width: 100%">
              <Select v-model="query.placeCode">
                <Option value="">全部</Option>
                <Option
                  v-for="item in xldata.placeCodeList"
                  :value="item.value"
                  :key="item.value"
                  >{{ item.name }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="10">
            <FormItem label="是否已开卷" style="width: 100%">
              <Select v-model="query.already">
                <Option value="">全部</Option>
                <Option
                  v-for="item in xzList"
                  :value="item.value"
                  :key="item.value"
                  >{{ item.name }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="10">
            <FormItem label="考点名称" style="width: 100%">
              <Input
                v-model="query.placeName"
                placeholder="考点名称模糊查询"
              ></Input>
            </FormItem>
          </Col>
          <Col span="2">
            <Button @click="doQuery" type="primary" icon="md-search"
              >查询</Button
            >
          </Col>
        </Row>
      </Form>
    </div>
    <div class="pg-body">
      <Table
        ref="room_uncoiling_table_data"
        :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";
import util from "../../libs/util";

export default {
  name: "exam_plan_room_uncoiling",
  data() {
    return {
      xldata: {
        examCodeList: [],
        placeCodeList: [],
      },
      list: [],
      xzList: [
        {
          value: "true",
          name: "是",
        },
        {
          value: "false",
          name: "否",
        },
      ],
      query: {
        examCode: "",
        placeCode: "",
        already: "",
        placeName: "",
        pageNo: 1,
        pageSize: 10,
        totalElements: 0,
        totalPages: 0,
      },
      columns: [
        {
          type: "index_seq",
          title: "序号",
          align: "center",
          width: 80,
          render: (h, params) => {
            let a =
              (this.query.pageNo - 1) * this.query.pageSize + params.index + 1;
            return h("span", a);
          },
        },
        {
          title: "考点",
          key: "placeName",
          align: "center",
        },
        {
          title: "考场",
          key: "roomName",
          align: "center",
        },
        {
          title: "是否已开卷",
          align: "center",
          render: (h, params) => {
            if (params.row.time) {
              return h("i", {
                props: {
                  "aria-hidden": true,
                },
                class: {
                  "fa fa-check": true,
                },
                style: {
                  fontSize: "16px",
                },
              });
            }
          },
        },
        {
          title: "开卷时间",
          key: "time",
          align: "center",
          render: (h, params) => {
            if (params.row.time) {
              return h("span", util.dateFormat(params.row.time));
            } else {
              return h("span", "");
            }
          },
        },
      ],
    };
  },
  created() {
    let a = this.query.examCode;
    this.xldata.examCodeList = [];
    axios.post("/system/kj/hz/getPlans", {}).then((response) => {
      let data = response.data.data;
      if (data) {
        this.xldata.examCodeList = data;
        this.query.examCode = a;
      }
    });
  },
  methods: {
    selectExam() {
      if (this.query.examCode && this.query.examCode.length > 0) {
        axios
          .post("/system/kj/hz/getPlaceByExamCode", this.query)
          .then((response) => {
            let data = response.data.data;
            if (data) {
              this.xldata.placeCodeList = [];
              this.xldata.placeCodeList = data;
            }
          });
      } else {
        this.xldata.placeCodeList = [];
      }
    },
    loadProgress() {
      this.query.type = "UNCOILING";
      axios
        .post("/system/kwProgress/pageQuery", 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() {
      if (!this.query.examCode) {
        this.$Notice.error({
          title: "系统提示",
          desc: "<p>请选择一个考试任务</p>",
        });
        return;
      }
      this.query.pageNo = 1;
      this.loadProgress();
    },
    changePageNo(p) {
      //切换页码
      this.query.pageNo = p;
      this.loadProgress();
    },
    changePageSize(pageSize) {
      //切换每一页显示多少条
      this.query.pageSize = pageSize;
      this.loadProgress();
    },
  },
};
</script>
