<template>
  <div>
    <a @click="openEdit">变更绑定</a>
    <!-- 选择弹窗 -->
    <select-data
      v-model:visible="showEdit"
      :data="current"
      :title="placeholder"
      :id="id"
      @done="onChange"
    />
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import SelectData from './components/select-data.vue';
  import { ThinkUsers } from '@/api/think/thinkUsers/model';

  withDefaults(
    defineProps<{
      value?: any;
      placeholder?: string;
      id?: number;
    }>(),
    {
      placeholder: '请选择'
    }
  );

  const emit = defineEmits<{
    (e: 'done', ThinkUsers, id: number): void;
    (e: 'clear'): void;
  }>();

  // 是否显示编辑弹窗
  const showEdit = ref(false);
  // 当前编辑数据
  const current = ref<ThinkUsers | null>(null);

  /* 打开编辑弹窗 */
  const openEdit = (row?: ThinkUsers) => {
    current.value = row ?? null;
    showEdit.value = true;
  };

  const onChange = (row?: ThinkUsers, id?: number) => {
    emit('done', row, Number(id));
  };
  // 查询租户列表
  // const appList = ref<App[] | undefined>([]);
</script>
