<template>
  <div class="editUserBtn opBtn">
    <VaButton color="info" :round="false" size="small" class="mr-6 mb-2" icon="edit" @click="getUserDetial">
      修改信息
    </VaButton>
    <VaModal :modelValue="showModal" @ok='submit' :noDismiss="true" blur 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: 'editUserBtn',
    props:{
      params:{
        default:()=>{}
      }
    },
    components: {
      userForm,
    },
    methods:{
      submit(){
        let params = {
          id:this.params.id,
          ...this.$refs.userForm.getData()
        }
        this.$api.editUser(params).then(res=>{
          this.$toast.success({message:res.message})
          this.showModal = false
          this.$emit('after-op')
        })
      },
      getUserDetial(){
        this.showModal = true
        this.$api.getUserDetial({id:this.params.id}).then(res=>{
          this.$refs.userForm.setData(res.result)
        })
      },
    },
    data() {
      return {
        showModal: false,
      }
    },
  }
</script>

<style scoped lang="less">
  .opBtn {
    display: inline-block;
  }
</style>
