<template>
  <el-dialog
    ref="dialog"
    title="考场监考管理"
    width="450px"
    :visible.sync="visible"
    @close="closeDialog"
  >
    <el-form
      :model="form"
      ref="form"
      :rules="rules"
      label-position="right"
      label-width="120px"
    >
      <el-row>
        <el-form-item label="考场">
          <ExamRoomSelect
            v-model="form.roomCode"
            style="width: 100%;"
          ></ExamRoomSelect>
        </el-form-item>
        <el-form-item label="考场">
          <InvigilatorSelect
            v-model="form.userIds"
            style="width: 100%;"
            multiple
          />
        </el-form-item>
      </el-row>

      <el-row class="d-flex justify-content-center">
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <el-button @click="closeDialog">取 消</el-button>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import { saveInvigilator } from "@/api/examwork-invigilate";
export default {
  name: "InvigilateManagementDialog",
  props: {
    user: Object,
  },
  watch: {
    user: {
      immediate: true,
      handler(val) {
        this.form.roomCode = val.roomCode;
        const u = val.userId || "";
        this.form.userIds = u.split(",");
      },
    },
  },
  data() {
    return {
      visible: false,
      form: {
        roomCode: "",
        userIds: [],
      },
      rules: {},
    };
  },
  methods: {
    openDialog() {
      this.visible = true;
    },
    closeDialog() {
      this.visible = false;
    },
    async submitForm() {
      let data = this.form;
      await saveInvigilator(data);
      this.$emit("reload");
      this.closeDialog();
    },
  },
};
</script>

<style></style>
