<template>
  <div class="opBtn">
    <VaButton color="info" :round="false" size="small" class="mr-6 mb-2" icon="edit" @click="getOrgDetial">
      修改部门信息
    </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 {
    name: 'editOrgBtn',
    components: {
      orgForm,
    },
    props: {
      params: {
        default: () => {},
      },
    },
    methods: {
      getOrgDetial() {
        let params = { id: this.params.id }
        this.$api.getOrgDetial(params).then((res) => {
          this.showModal = true
          this.$nextTick(() => {
            this.$refs.orgForm.setData(res.result)
          })
        })
      },
      submit() {
        let params = { id: this.params.id, ...this.$refs.orgForm.form }
        this.$api.editOrg(params).then((res) => {
          this.$toast.success({ message: res.message })
          this.$emit('after-op', res.result)
          this.showModal = false
        })
      },
    },
    data() {
      return {
        showModal: false,
      }
    },
  }
</script>

<style scoped></style>
