<template>
  <div class="addUserBtn">
    <VaButton preset="secondary" size="small" :round="false" @click="showModal = true"> 新增部门 </VaButton>
    <VaModal :modelValue="showModal" :noDismiss="true" blur @ok="submit" @cancel="showModal = false" ok-text="提交" cancelText="取消">
      <h3 class="va-h3">部门信息</h3>
      <orgForm ref="orgForm"></orgForm>
    </VaModal>
  </div>
</template>

<script>
  import orgForm from './orgForm.vue'
  export default {
    components: {
      orgForm,
    },
    props: {
      parentId: {
        default: 0,
      },
    },
    methods: {
      submit() {
        let params = { ...this.$refs.orgForm.form, parentId: this.parentId }
        this.$api.addOrg(params).then((res) => {
          this.$toast.success({ message: res.message })
          this.showModal = false
          this.$emit('after-op')
        })
      },
    },
    name: 'addOrgBtn',
    data() {
      return {
        showModal: false,
      }
    },
  }
</script>

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