invoice.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. import { fenToYuan } from "@/utils/money";
  36. const openInvoiceId = ref();
  37. const email = ref();
  38. const pdfUrl = ref("");
  39. const list = ref([
  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. { label: "申请时间", value: "" },
  49. ]);
  50. onLoad((options: any) => {
  51. uni.showLoading({ title: "加载中" });
  52. fetchInvoiceList()
  53. .then((res) => {
  54. uni.hideLoading();
  55. const fd = res.findIndex((item: any) => {
  56. if (item.orderDetails && item.orderDetails.length) {
  57. return item.orderDetails.some(
  58. (order: any) => order.startChargeSeq === options.id
  59. );
  60. }
  61. return false;
  62. });
  63. if (fd >= 0) {
  64. list.value[0].value = res[fd].invoiceTitle || "-";
  65. list.value[1].value = res[fd].taxId || "-";
  66. list.value[2].value = res[fd].address || "-";
  67. list.value[3].value = res[fd].phone || res[fd].telephone || "-";
  68. list.value[4].value = res[fd].bankName || "-";
  69. list.value[5].value = res[fd].bankAccount || "-";
  70. list.value[6].value = res[fd].remark || "-";
  71. list.value[7].value = `${fenToYuan(res[fd].invoiceAmount)}`;
  72. list.value[8].value = res[fd].createTime || "-";
  73. openInvoiceId.value = res[fd].id;
  74. email.value = res[fd].email || "";
  75. return;
  76. }
  77. return Promise.reject({ errMsg: "找不到发票数据" });
  78. })
  79. .catch((err) => {
  80. uni.hideLoading();
  81. uni.showModal({ content: `${err.errMsg},请重试` });
  82. });
  83. });
  84. const openInvoice = (type: string) => {
  85. uni.showLoading({ title: "加载中" });
  86. fetchInvoicePDF(openInvoiceId.value)
  87. .then((res: any) => {
  88. uni.hideLoading();
  89. const urls = res.downloadUrls || res;
  90. const fileUrl = type === "pdf" ? (urls.invoiceUrl || urls.downloadUrl) : urls.ofdUrl;
  91. if (!fileUrl) {
  92. uni.showToast({ title: "暂无发票文件", icon: "none" });
  93. return;
  94. }
  95. uni.downloadFile({
  96. url: fileUrl,
  97. success: (downloadRes) => {
  98. uni.openDocument({
  99. filePath: downloadRes.tempFilePath,
  100. showMenu: true,
  101. fail(err: any) {
  102. uni.showModal({ content: `打开失败: ${err.errMsg}` });
  103. },
  104. });
  105. },
  106. fail(err: any) {
  107. uni.showModal({ content: `下载失败: ${err.errMsg}` });
  108. },
  109. });
  110. })
  111. .catch(() => {
  112. uni.hideLoading();
  113. uni.showToast({ title: "获取发票失败", icon: "none" });
  114. });
  115. };
  116. </script>
  117. <style lang="scss">
  118. .page {
  119. min-height: 100vh;
  120. background-color: #f6f7fa;
  121. padding: 20rpx;
  122. }
  123. .block {
  124. border-radius: 20rpx;
  125. background: #fff;
  126. padding: 30rpx;
  127. }
  128. </style>