<template>
  <div>
    <a-input-group compact>
      <a-input
        disabled
        style="width: calc(100% - 32px)"
        v-model:value="value"
        :placeholder="placeholder"
      />
      <a-button @click="openEdit">
        <template #icon><BulbOutlined class="ele-text-warning" /></template>
      </a-button>
    </a-input-group>
    <!-- 选择弹窗 -->
    <SelectData
      v-model:visible="showEdit"
      :data="order"
      :title="placeholder"
      @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 { ThinkSite } from '@/api/think/thinkSite/model';
  import { ThinkOrder } from '@/api/think/thinkOrder/model';

  withDefaults(
    defineProps<{
      value?: any;
      order?: ThinkOrder;
      placeholder?: string;
    }>(),
    {
      placeholder: '请选择开票信息'
    }
  );

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

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

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

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