<script setup lang="ts">
import { http } from '@af-mobile-client-vue3/utils/http'
import { showDialog, Loading as VanLoading } from 'vant'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'

// 获取url中的sellid参数
const route = useRoute()
const sellid = route.query.sellid
const showLoading = ref(true)

onMounted(async () => {
  if (sellid) {
    http.request({
      url: '/invoice/rs/logic/getInvoiceBySellId',
      method: 'post',
      data: {
        sellid,
      },
    }).then((_res: any) => {
      showLoading.value = false
      if (_res.type === 'success') {
        if (_res.url)
          window.open(_res.url)
      }
      else {
        showDialog({
          message: _res.msg,
          theme: 'round-button',
          showConfirmButton: false,
        }).then(() => {
          // on close
        })
      }
    })
  }
})
</script>

<template>
  <div class="invoiceShow">
    <VanLoading v-if="showLoading" type="spinner" color="#1989fa" vertical>
      正在努力获取发票信息，请稍后。。。
    </VanLoading>
  </div>
</template>

<style scoped lang="less">
.invoiceShow {
  width: 100vw !important;
  height: 100vh !important;
  overflow-y: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.invoiceShow > * {
  transform: scale(1.5);
}
</style>
