<template>
  <div>
    <vxe-modal
      :value="isShow"
      show-footer
      transfer
      :z-index="zIndex"
      resize
      show-zoom
      title="会议室"
      show-confirm-button
      :width="defaultModalSize.sWidth"
      :height="defaultModalSize.sHeight"
      esc-closable
      :fullscreen="$store.getters.device === 'mobile'"
      @input="e => $emit('update:isShow',e)"
    >
      <el-form ref="elForm" :model="form" :rules="rules" label-position="top" label-width="100">
        <el-form-item label="名字" prop="name">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="排序" prop="myindex">
          <el-input-number v-model="form.myindex" controls-position="right" :precision="0" />
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button type="primary" :loading="loading" @click="submit">确认</el-button>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
import { save } from '@/api/meetingRoom'
import { defaultModalSize } from "@/settings";
import { PopupManager } from 'element-ui/lib/utils/popup'

export default {
  props: {
    isShow: {
      type: Boolean,
      default: false,
      required: true
    }
  },
  data() {
    return {
      defaultModalSize,
      loading: false,
      zIndex: PopupManager.nextZIndex(),
      form: {
        name: '',
        myindex: 0
      },
      rules: {}
    }
  },
  computed: {},
  methods: {
    submit() {
      this.$refs['elForm'].validate(async valid => {
        if (valid) {
          this.loading = true
          try {
            await save(this.form)
            this.$message.success('新增成功')
            this.$emit('refresh')
            this.$emit('update:isShow', false)
            this.loading = false
            this.$refs['elForm'].resetFields()
          } catch (err) {
            this.loading = false
          }
        }
      })
    }
  },
  watch: {
    isShow(newVal) {
      if (newVal) {
        this.zIndex = PopupManager.nextZIndex()
      }
    }
  }
}
</script>

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