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

<script>
  import userForm from './userForm.vue'
  export default {
    name: 'addUserBtn',
    components: {
      userForm,
    },
    methods: {
      openAdd() {
        if (this.orgId == 0) {
          this.$toast.warning({ message: '请选择对应部门' })
          return
        } else {
          this.showModal = true
        }
      },
      submit() {
        let params = { ...this.$refs.userForm.getData(), orgId: this.orgId }
        this.$api.addUser(params).then((res) => {
          this.$toast.success({ message: res.message })
          this.showModal =false
          this.$emit('after-op')
        })
      },
    },
    data() {
      return {
        showModal: false,
        orgId: 0,
      }
    },
  }
</script>

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