<template>
  <div class="opBtn">
    <VaButton color="info" :round="false" size="small" icon="edit" class="mr-6 mb-2" @click="getRoleDetial">
      角色编辑
    </VaButton>
    <VaModal
      :modelValue="showModal"
      :noDismiss="true"
      max-width="800px"
      @cancel="showModal = false"
      @ok="submit"
      ok-text="提交"
      cancelText="取消"
    >
      <h3 class="va-h3">用户列表</h3>
      <roleForm ref="roleForm"></roleForm>
    </VaModal>
  </div>
</template>

<script>
  import roleForm from './roleForm.vue'
  export default {
    name: 'editRoleBtn',
    components: {
      roleForm,
    },
    props: {
      params: {
        default: () => {},
      },
    },
    methods: {
      submit() {
        let params = { id: this.params.id, ...this.$refs.roleForm.form }
        this.$api.editRole(params).then((res) => {
          this.$toast.success({ message: res.message })
          this.showModal = false
          this.$emit('after-op')
        })
      },
      getRoleDetial() {
        let params = { id: this.params.id }
        this.$api.getRoleDetial(params).then((res) => {
          this.showModal = true
          this.$nextTick(() => {
            this.$refs.roleForm.setData(res.result)
          })
        })
      },
    },
    data() {
      return {
        showModal: false,
      }
    },
  }
</script>

<style scoped></style>
