<template>
  <div>
    <el-form :model="form" inline>
      <!-- <el-form-item v-if="$store.state.user.orgId === null" label="机构">
        <OrgSelect v-model="form.orgId"></OrgSelect>
      </el-form-item> -->
      <el-form-item label="角色">
        <RoleSelect v-model="form.roleCode"></RoleSelect>
      </el-form-item>
      <el-form-item label="登录名">
        <el-input v-model.trim="form.loginName"></el-input>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model.trim="form.name"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <StateSelect v-model="form.enableState"></StateSelect>
      </el-form-item>
      <el-button @click="searchForm">查询</el-button>
      <el-button @click="add">新增</el-button>
      <!-- <el-button>导入</el-button> -->
    </el-form>

    <el-table :data="tableData" stripe style="width: 100%;">
      <!-- <el-table-column type="selection" width="42" />
      <el-table-column width="100" label="ID">
        <span slot-scope="scope">{{ scope.row.id }}</span>
      </el-table-column> -->
      <el-table-column width="200" label="考场编码">
        <span slot-scope="scope">{{ scope.row.roomCode }}</span>
      </el-table-column>
      <el-table-column label="考场名称">
        <span slot-scope="scope">{{ scope.row.roomName }}</span>
      </el-table-column>
      <el-table-column width="220" label="监考老师">
        <span slot-scope="scope">{{ scope.row.name }}</span>
      </el-table-column>
      <el-table-column :context="_self" label="操作" width="210">
        <div slot-scope="scope">
          <el-button size="mini" type="primary" plain @click="edit(scope.row)">
            编辑
          </el-button>
        </div>
      </el-table-column>
    </el-table>
    <div class="page float-right">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :page-sizes="[10, 20, 50, 100, 200, 300]"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      />
    </div>

    <InvigilateManagementDialog
      ref="theDialog"
      :user="selectedUser"
      @reload="searchForm"
    />
  </div>
</template>

<script>
import RoleSelect from "@/components/RoleSelect.vue";
import StateSelect from "@/components/StateSelect";
import InvigilateManagementDialog from "./InvigilateManagementDialog";
import { searchInvigilators } from "@/api/examwork-invigilate";

export default {
  name: "InvigilateManagement",
  components: {
    RoleSelect,
    StateSelect,
    // OrgSelect,
    InvigilateManagementDialog,
  },
  data() {
    return {
      form: {
        orgId: "",
        roleCode: "",
        loginName: "",
        name: "",
        enableState: null,
      },
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10,
      selectedUser: {},
    };
  },
  async created() {},
  methods: {
    async searchForm() {
      const res = await searchInvigilators({
        orgId: this.form.orgId,
        role: this.form.roleCode,
        enable: this.form.enableState,
        loginName: this.form.loginName,
        name: this.form.name,
        pageNumber: this.currentPage,
        pageSize: this.pageSize,
      });
      this.tableData = res.data.data.records.records;
      this.total = res.data.data.records.total;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.searchForm();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.searchForm();
    },
    add() {
      this.selectedUser = {};
      this.$refs.theDialog.openDialog();
    },
    edit(user) {
      this.selectedUser = user;
      this.$refs.theDialog.openDialog();
    },
  },
};
</script>

<style></style>
