<template>
  <div>
    <el-dialog
      :before-close="handleClose"
      :close-on-click-modal="false"
      :title="title + '考场信息'"
      :visible="visible"
      custom-class="bbsl-location-dialog"
      width="50%"
    >
      <div>
        <el-form
          ref="formInfo"
          :model="this.params"
          :rules="rules"
          label-position="top"
          label-width="150px"
        >
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="考试编码" prop="code">
                <el-input
                  v-model="params.code"
                  clearable
                  placeholder="请输入考试编码"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="考场名称" prop="name">
                <el-input
                  v-model="params.name"
                  clearable
                  placeholder="请输入考场名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="考场状态" prop="roomStatus">
                <el-select
                  v-model="params.roomStatus"
                  clearable
                  placeholder="请选择控件类型"
                >
                  <el-option
                    v-for="item in roomStatusList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="考场位置" prop="roomPlace">
                <el-input
                  v-model="params.roomPlace"
                  clearable
                  placeholder="请输入考场位置"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="备注" prop="memo">
                <el-input
                  v-model="params.memo"
                  :rows="2"
                  clearable
                  placeholder="请输入备注"
                  type="textarea"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="goInfo">确认</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import dictUtils from '@/components/dict/DictSelectUtils.js'
import roomMenu from '@/api/examination/roomMenu.js'

export default {
  name: 'warning',
  data() {
    return {
      visible: false,
      title: '',
      params: {
        code: '',
        name: '',
        roomStatus: '',
        roomPlace: '',
        memo: ''
      },
      rules: {
        code: [
          {
            required: true,
            message: '请输入考试编码',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入考场名称',
            trigger: 'blur'
          }
        ],
        roomStatus: [
          {
            required: true,
            message: '请选择考场状态',
            trigger: 'blur'
          }
        ],
        roomPlace: [
          {
            required: true,
            message: '请输入考场位置',
            trigger: 'blur'
          }
        ]
      },
      roomStatusList: []
    }
  },
  created() {
    this.roomStatusList = dictUtils.getDictItemsFromCache('kczt')
  },
  mounted() {},
  methods: {
    add() {
      this.visible = true
      this.title = '新增'
      this.params.roomStatus = this.roomStatusList[0].value
    },
    edit(row) {
      this.visible = true
      this.title = '修改'
      roomMenu.detailId(row.id, res => {
        this.params = res
      })
    },
    //保存
    goInfo() {
      this.$refs.formInfo.validate(valid => {
        if (valid) {
          if (this.title === '新增') {
            roomMenu.addData(this.params, response => {
              if (response.state) {
                this.$notify({
                  type: 'success',
                  message: '保存成功',
                  duration: 2000
                })
                this.handleClose()
                this.$parent.loadData(1)
              } else {
              }
            })
          }
          if (this.title === '修改') {
            roomMenu.editData(this.params, response => {
              if (response.state) {
                this.$notify({
                  type: 'success',
                  message: '修改成功',
                  duration: 2000
                })
                this.handleClose()
                this.$parent.loadData(1)
              } else {
              }
            })
          }
        } else {
          return false
        }
      })
    },
    // 关闭新增人员窗口
    handleClose() {
      this.visible = false
      this.params = {
        code: '',
        name: '',
        roomStatus: '',
        roomPlace: '',
        memo: ''
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
