viewBill.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view>
  3. <u-navbar title="查看票据"></u-navbar>
  4. <view class="bill" v-if="billInfo.invoiceUrl != null">
  5. <view class="img">
  6. <img :src="billInfo.invoiceUrl" alt="">
  7. </view>
  8. <view class="options">
  9. <view class="key">
  10. {{billInfo.invoiceTitle}}
  11. </view>
  12. <view class="btn">
  13. <!-- <button class="download" @click="downloadBill">下载票据</button> -->
  14. <button class="print" @click="toPrintBill">打印票据</button>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import * as courseApi from '@/apis/youth/course.js'
  22. export default {
  23. data() {
  24. return {
  25. buyId: '',
  26. billInfo: {}
  27. }
  28. },
  29. onLoad(op) {
  30. if (op.id) {
  31. this.buyId = op.id;
  32. this.getBillInfo();
  33. }
  34. },
  35. methods: {
  36. downloadBill() {
  37. let _self = this;
  38. var token = _self.carhelp.getToken()
  39. // 1 选择保存图片到本地
  40. uni.showActionSheet({
  41. itemList: ["保存图片到本地"],
  42. success: (res) => {
  43. if (res.tapIndex == 0) {
  44. // 2 提示保存中
  45. uni.showLoading({
  46. title: "图片保存中..."
  47. })
  48. // 3 下载到本地
  49. uni.downloadFile({
  50. url: _self.billInfo.invoiceUrl,
  51. success: (result) => {
  52. var tempFilePath = result.tempFilePath;
  53. // 4 保存到本地
  54. uni.saveImageToPhotosAlbum({
  55. filePath: tempFilePath,
  56. success: () => {
  57. // 5 提示保存成功
  58. uni.showToast({
  59. title: "保存成功",
  60. duration: 2000
  61. })
  62. },
  63. fail: () => {
  64. // 6 失败关闭提示信息!!!
  65. console.log("saveImageToPhotosAlbum 失败");
  66. uni.hideLoading();
  67. },
  68. complete: function() {
  69. // 7 隐藏提示
  70. uni.hideLoading();
  71. }
  72. })
  73. },
  74. fail: () => {
  75. console.log("downloadFile 失败");
  76. }
  77. })
  78. }
  79. },
  80. fail: () => {
  81. console.log("showActionSheet 失败");
  82. }
  83. })
  84. },
  85. getBillInfo() {
  86. uni.showLoading({
  87. title: "加载中",
  88. mask: true,
  89. })
  90. courseApi.getBuyInvoiceInfo({
  91. buyId: this.buyId
  92. }).then((res) => {
  93. uni.hideLoading();
  94. this.billInfo = res.data;
  95. }).catch(error => {
  96. uni.showToast({
  97. title: error,
  98. icon: "none"
  99. })
  100. })
  101. },
  102. toPrintBill() {
  103. uni.navigateTo({
  104. url: '/pages/youth/course/printBill?id=' + this.billInfo.buyId
  105. })
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. .bill {
  112. margin: 24rpx 32rpx;
  113. border-radius: 4px;
  114. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.15);
  115. .img {
  116. width: 100%;
  117. height: 398rpx;
  118. img {
  119. width: 100%;
  120. height: 100%;
  121. }
  122. }
  123. .options {
  124. display: flex;
  125. justify-content: space-between;
  126. align-items: center;
  127. border-radius: 0px 0px 4px 4px;
  128. background-color: #000000;
  129. opacity: 0.4;
  130. padding: 24rpx;
  131. .key {
  132. color: rgba(255, 255, 255, 1);
  133. font-size: 16px;
  134. }
  135. .btn {
  136. display: flex;
  137. uni-button {
  138. width: 160rpx;
  139. height: 64rpx;
  140. line-height: 64rpx;
  141. text-align: center;
  142. border-radius: 4px;
  143. font-size: 28rpx;
  144. padding: 0;
  145. }
  146. .download {
  147. background-color: rgba(255, 255, 255, 1);
  148. color: #333333;
  149. }
  150. .print {
  151. background-color: #0DBAC7;
  152. color: rgba(255, 255, 255, 1);
  153. margin-left: 20rpx;
  154. }
  155. }
  156. }
  157. }
  158. </style>