<template>
  <ele-modal
    :width="400"
    :visible="visible"
    :maskClosable="false"
    :title="`指派人员`"
    :body-style="{ paddingBottom: '28px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <SelectStaff
      :placeholder="`选择指派人员`"
      v-model:value="form.nickname"
      :type="`task`"
      @done="chooseUser"
    />
  </ele-modal>
</template>
<script lang="ts" setup>
  import { User } from '@/api/system/user/model';
  import { reactive } from 'vue';

  defineProps<{
    // 弹窗是否打开
    visible: boolean;
  }>();

  const emit = defineEmits<{
    (e: 'done', user: User): void;
    (e: 'update:visible', visible: boolean): void;
  }>();

  /* 更新visible */
  const updateVisible = (value: boolean) => {
    emit('update:visible', value);
  };

  // 用户信息
  const form = reactive<User>({
    userId: undefined,
    nickname: undefined,
    roles: undefined
  });

  const chooseUser = (item: User) => {
    form.userId = item.userId;
    form.nickname = item.nickname;
  };

  const save = () => {
    emit('done', form);
  };
</script>
<style scoped lang="less"></style>
