<!-- 搜索表单 -->
<template>
  <a-space :size="10" style="flex-wrap: wrap">
    <!--    <SelectMerchantDown-->
    <!--      :placeholder="`选择场馆`"-->
    <!--      class="input-item"-->
    <!--      v-model:value="where.merchantCode"-->
    <!--      @change="search"-->
    <!--    />-->
    <a-input-search
      allow-clear
      v-model:value="where.keywords"
      placeholder="请输入关键词"
      @search="search"
      @pressEnter="search"
    />
    <!--    <a-button @click="getCode">生成支付二维码</a-button>-->
    <a-button @click="reset">重置</a-button>
  </a-space>
  <ele-modal
    :width="500"
    :visible="showQrcode"
    :maskClosable="false"
    title="使用微信扫一扫完成支付"
    :body-style="{ paddingBottom: '28px' }"
    @cancel="closeQrcode"
    @ok="closeQrcode"
  >
    <div class="qrcode">
      <ele-qr-code-svg v-if="text" :value="text" :size="200" />
      <div class="ele-text-secondary">使用微信扫一扫完成支付</div>
    </div>
  </ele-modal>
</template>

<script lang="ts" setup>
  import { ref, watch } from 'vue';
  import useSearch from '@/utils/use-search';
  import { OrderParam } from '@/api/shop/order/model';
  import { getNativeCode } from '@/api/system/payment';

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

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

  // 表单数据
  const { where, resetFields } = useSearch<OrderParam>({
    keywords: ''
  });

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

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

  // 二维码内容
  const text = ref('');
  const showQrcode = ref(false);

  const closeQrcode = () => {
    showQrcode.value = !showQrcode.value;
  };

  const getCode = () => {
    getNativeCode({}).then((data) => {
      text.value = String(data);
      showQrcode.value = true;
    });
  };

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

<style lang="less" scoped>
  .qrcode {
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    padding: 40px 0;
  }
</style>
