<template>
  <div>
    <a @click="openEdit">换场</a>
    <!-- 选择弹窗 -->
    <SelectData
      v-model:visible="showEdit"
      :data="current"
      :merchantId="merchantId"
      :timePeriod="timePeriod"
      :week="week"
      :id="id"
      :title="placeholder"
      :customer-type="customerType"
      @done="onChange"
    />
  </div>
</template>

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

  withDefaults(
    defineProps<{
      value?: any;
      customerType?: string;
      placeholder?: string;
      merchantId?: number;
      timePeriod?: string;
      week?: string;
      orderId?: number;
      id?: number;
    }>(),
    {
      placeholder: '请选择要更换的场地'
    }
  );

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

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

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

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