<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="year">
                <el-date-picker
                  v-model="params.year"
                  placeholder="选择年"
                  type="year"
                  value-format="yyyy"
                >
                </el-date-picker>
              </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 ndsbMenu from '@/api/examination/ndsbMenu.js'

export default {
  name: 'warning',
  data() {
    return {
      title: '',
      roomList: [],
      typeList: [],
      visible: false,
      params: {
        year: ''
      },
      rules: {
        year: [
          {
            required: true,
            message: '请选择年份',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    add(val) {
      this.visible = true
      this.title = '新增'
    },
    edit(val) {
      this.params = val
      this.title = '修改'
      this.visible = true
    },
    //保存
    goInfo() {
      this.$refs.formInfo.validate(valid => {
        if (valid) {
          if (this.title === '新增') {
            ndsbMenu.addReport(this.params, response => {
              if (response.state) {
                this.$notify({
                  type: 'success',
                  message: '保存成功',
                  duration: 2000
                })
                this.handleClose()
                this.$parent.loadData(1)
              } else {
              }
            })
          } else if (this.title === '修改') {
            ndsbMenu.editReport(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 = {
        year: ''
      }
    }
  }
}
</script>

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