<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <!--    <a-button type="primary" class="ele-btn-icon">-->
    <!--      <template #icon>-->
    <!--        <PlusOutlined />-->
    <!--      </template>-->
    <!--      <span>添加</span>-->
    <!--    </a-button>-->
    <a-button @click="reset">全部</a-button>
    <DictRadio
      dict-code="userPlan"
      type="button"
      placeholder="解锁功能"
      v-model:value="where.planName"
      @change="search"
    />
    <a-input-search
      allow-clear
      placeholder="请输入会员昵称|手机号码"
      v-model:value="where.keywords"
      @pressEnter="search"
      @search="search"
      style="width: 300px"
    />
  </a-space>
</template>

<script lang="ts" setup>
  import { ref, watch } from 'vue';
  import useSearch from '@/utils/use-search';
  import { UserPlanEquityParam } from '@/api/love/plan-equity/model';
  import { UserPlan } from '@/api/love/plan/model';
  import { listUserPlan } from '@/api/love/plan';

  const props = withDefaults(
    defineProps<{
      // 选中的角色
      selection?: [];
    }>(),
    {}
  );

  const emit = defineEmits<{
    (e: 'search', where?: UserPlanEquityParam): void;
    (e: 'add'): void;
    (e: 'remove'): void;
    (e: 'advanced'): void;
  }>();

  // 表单数据
  const { where, resetFields } = useSearch<UserPlanEquityParam>({
    planEquityId: undefined,
    type: undefined,
    keywords: undefined
  });

  const planList = ref<UserPlan[]>([]);

  /* 搜索 */
  const search = () => {
    emit('search', {
      ...where
    });
  };

  const reload = () => {
    listUserPlan({ type: 0 }).then((data) => {
      planList.value = data;
    });
  };

  /*  重置 */
  const reset = () => {
    resetFields();
    search();
  };

  reload();

  watch(
    () => props.selection,
    () => {}
  );
</script>
