<!-- 选择下拉框 -->
<template>
  <a-select
    :allow-clear="true"
    :show-search="true"
    optionFilterProp="label"
    :options="options"
    :value="value"
    :placeholder="placeholder"
    @update:value="updateValue"
    :style="`width: 200px`"
    @blur="onBlur"
  />
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { SelectProps } from 'ant-design-vue';

  const emit = defineEmits<{
    (e: 'update:value', value: string, item: any): void;
    (e: 'blur'): void;
  }>();

  const props = withDefaults(
    defineProps<{
      value?: any;
      type?: any;
      placeholder?: string;
      dictCode?: string;
    }>(),
    {
      placeholder: '请选择支付方式'
    }
  );

  // 字典数据
  const options = ref<SelectProps['options']>([
    {
      value: 0,
      label: '余额支付',
      key: 'balancePay',
      icon: 'PayCircleOutlined'
    },
    { value: 1, label: '微信支付', key: 'wxPay', icon: 'WechatOutlined' },
    {
      value: 2,
      label: '支付宝',
      key: 'aliPay',
      icon: 'AlipayCircleOutlined'
    },
    {
      value: 3,
      label: '银联支付',
      key: 'unionPay',
      icon: 'IdcardOutlined'
    },
    {
      value: 4,
      label: '现金支付',
      key: 'cashPayment',
      icon: 'PayCircleOutlined'
    },
    {
      value: 5,
      label: 'POS机支付',
      key: 'posPay',
      icon: 'IdcardOutlined'
    },
    {
      value: 6,
      label: '免费',
      key: 'freePay',
      icon: 'IdcardOutlined'
    },
    {
      value: 7,
      label: '积分支付',
      key: 'pointsPay',
      icon: 'IdcardOutlined'
    },
    {
      value: 8,
      label: '货到付款',
      key: 'codPay',
      icon: 'IdcardOutlined'
    },
    {
      value: 9,
      label: '线下付款',
      key: 'offlinePay',
      icon: 'IdcardOutlined'
    }
  ]);

  /* 更新选中数据 */
  const updateValue = (value: string) => {
    const item = options.value?.find((d) => d.value == value);
    console.log(item);
    emit('update:value', value, item);
  };
  /* 失去焦点 */
  const onBlur = () => {
    emit('blur');
  };
</script>
