<template>
  <div>
    <a-button @click="openEdit">
      <template #icon
        ><BulbOutlined
          v-if="value > 20"
          class="ele-text-heading" /><BulbOutlined
          v-else
          class="ele-text-danger"
      /></template>
    </a-button>
    <!-- 选择弹窗 -->
    <SelectData
      v-model:visible="showEdit"
      :data="current"
      :title="placeholder"
      :customer-type="customerType"
      @done="onChange"
    />
  </div>
</template>

<script lang="ts" setup>
  import { BulbOutlined } from '@ant-design/icons-vue';
  import { ref } from 'vue';
  import SelectData from './components/select-data.vue';
  import { User } from '@/api/system/user/model';

  const props = withDefaults(
    defineProps<{
      value?: any;
      customerType?: string;
      placeholder?: string;
    }>(),
    {
      placeholder: '请选择数据'
    }
  );

  const emit = defineEmits<{
    (e: 'done', data: User): void;
    (e: 'clear'): void;
  }>();

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

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

  const onChange = (row: User) => {
    emit('done', row);
  };
</script>
