invoice.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="page">
  3. <view class="block">
  4. <view
  5. class="flex-align-center"
  6. :style="{ marginTop: index === 0 ? 0 : '40rpx' }"
  7. v-for="(item, index) in list"
  8. :key="index"
  9. >
  10. <view class="fs-32 lh-48 color-999" style="width: 192rpx">{{
  11. item.label
  12. }}</view>
  13. <view class="fs-28 lh-48 color-000" v-if="index === 7">
  14. <text style="color: rgba(255, 153, 0, 1)">{{ item.value }}</text>
  15. <text style="margin-left: 2px">元</text>
  16. </view>
  17. <view class="fs-28 lh-48 color-000" v-else>{{ item.value }}</view>
  18. </view>
  19. </view>
  20. <view class="block pt-40 pb-40 pl-30 pr-30 flex mt-30" v-if="email">
  21. <view class="fs-32 lh-48 color-999" style="width: 192rpx">电子邮箱</view>
  22. <view class="fs-28 lh-48 color-000">{{ email }}</view>
  23. </view>
  24. <view class="block pt-40 pb-40 pl-30 pr-30 flex mt-30">
  25. <view class="fs-32 lh-48 color-999" style="width: 192rpx">电子发票</view>
  26. <view class="fs-28 color-theme" @click="openInvoice('pdf')" v-if="pdfUrl">PDF版</view>
  27. <view class="fs-28 color-999" v-else>暂无</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script setup lang="ts">
  32. import { fetchInvoiceList, fetchInvoicePDF } from "@/api";
  33. import { onLoad } from "@dcloudio/uni-app";
  34. import { ref } from "vue";
  35. const openInvoiceId = ref();
  36. const email = ref();
  37. const pdfUrl = ref("");
  38. const list = ref([
  39. { label: "公司名称", value: "" },
  40. { label: "公司税号", value: "" },
  41. { label: "注册地址", value: "" },
  42. { label: "注册电话", value: "" },
  43. { label: "开户银行", value: "" },
  44. { label: "银行账号", value: "" },
  45. { label: "备注", value: "" },
  46. { label: "发票金额", value: "" },
  47. { label: "申请时间", value: "" },
  48. ]);
  49. onLoad((options: any) => {
  50. uni.showLoading({ title: "加载中" });
  51. fetchInvoiceList()
  52. .then((res) => {
  53. uni.hideLoading();
  54. const fd = res.findIndex((item: any) => {
  55. if (item.orderDetails && item.orderDetails.length) {
  56. return item.orderDetails.some(
  57. (order: any) => order.startChargeSeq === options.id
  58. );
  59. }
  60. return false;
  61. });
  62. if (fd >= 0) {
  63. list.value[0].value = res[fd].invoiceTitle || "-";
  64. list.value[1].value = res[fd].taxId || "-";
  65. list.value[2].value = res[fd].address || "-";
  66. list.value[3].value = res[fd].phone || res[fd].telephone || "-";
  67. list.value[4].value = res[fd].bankName || "-";
  68. list.value[5].value = res[fd].bankAccount || "-";
  69. list.value[6].value = res[fd].remark || "-";
  70. list.value[7].value = `${(Number(res[fd].invoiceAmount) / 100).toFixed(2)}`;
  71. list.value[8].value = res[fd].createTime || "-";
  72. openInvoiceId.value = res[fd].id;
  73. email.value = res[fd].email || "";
  74. return;
  75. }
  76. return Promise.reject({ errMsg: "找不到发票数据" });
  77. })
  78. .catch((err) => {
  79. uni.hideLoading();
  80. uni.showModal({ content: `${err.errMsg},请重试` });
  81. });
  82. });
  83. const openInvoice = (type: string) => {
  84. uni.showLoading({ title: "加载中" });
  85. fetchInvoicePDF(openInvoiceId.value)
  86. .then((res: any) => {
  87. uni.hideLoading();
  88. const urls = res.downloadUrls || res;
  89. const fileUrl = type === "pdf" ? (urls.invoiceUrl || urls.downloadUrl) : urls.ofdUrl;
  90. if (!fileUrl) {
  91. uni.showToast({ title: "暂无发票文件", icon: "none" });
  92. return;
  93. }
  94. uni.downloadFile({
  95. url: fileUrl,
  96. success: (downloadRes) => {
  97. uni.openDocument({
  98. filePath: downloadRes.tempFilePath,
  99. showMenu: true,
  100. fail(err: any) {
  101. uni.showModal({ content: `打开失败: ${err.errMsg}` });
  102. },
  103. });
  104. },
  105. fail(err: any) {
  106. uni.showModal({ content: `下载失败: ${err.errMsg}` });
  107. },
  108. });
  109. })
  110. .catch(() => {
  111. uni.hideLoading();
  112. uni.showToast({ title: "获取发票失败", icon: "none" });
  113. });
  114. };
  115. </script>
  116. <style lang="scss">
  117. .page {
  118. min-height: 100vh;
  119. background-color: #f6f7fa;
  120. padding: 20rpx;
  121. }
  122. .block {
  123. border-radius: 20rpx;
  124. background: #fff;
  125. padding: 30rpx;
  126. }
  127. </style>