invoicePreview.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view >
  3. <ujp-navbar title="发票预览"></ujp-navbar>
  4. <view style="margin: 10px 0;">
  5. <H2>长按发票图片保存至本地</H2>
  6. </view>
  7. <view class="img-box" v-for="(item,i) in imagesz" :key="i">
  8. <img :src="item" alt="">
  9. </view>
  10. <view class="btn">
  11. <!-- <u-button shape="circle" v-if="imagesz.length" @click="down('1')" style="color: #00b962;">下载图片</u-button>
  12. --> <u-button shape="circle" v-if="invoiceInfo.pdf" @click="down('2')" type="success">下载PDF</u-button>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import * as API from '@/apis/invoiceApi.js'
  18. export default {
  19. data() {
  20. return {
  21. id: '',
  22. imagesz:[],
  23. invoiceInfo:{},
  24. }
  25. },
  26. onLoad(op) {
  27. if(op.id) {
  28. this.id = op.id;
  29. this.invoiceDetail();
  30. }
  31. },
  32. methods: {
  33. down(type){
  34. uni.showLoading({
  35. title: "加载中",
  36. mask: true,
  37. })
  38. var url=[];
  39. if(type==1){
  40. url=this.imagesz
  41. }else{
  42. url.push(this.invoiceInfo.pdf)
  43. }
  44. for(var i in url){
  45. var obj=url[i]
  46. window.location.href = obj;
  47. }
  48. setTimeout(()=>{
  49. uni.hideLoading()
  50. },2000)
  51. },
  52. view(){
  53. uni.navigateTo({
  54. url:"/pages/MyInvoice/invoicePreview?id="+this.invoiceInfo.id
  55. })
  56. },
  57. invoiceDetail() {
  58. uni.showLoading({
  59. title: "加载中",
  60. mask: true,
  61. })
  62. API.invoiceDetail({
  63. invoiceId:this.id
  64. }).then((res) => {
  65. uni.hideLoading();
  66. this.invoiceInfo=res.data.invoiceInfo;
  67. if(this.invoiceInfo.image){
  68. this.imagesz=this.invoiceInfo.image.split(',')
  69. }
  70. }).catch(error => {
  71. uni.showToast({
  72. title: error,
  73. icon: "none"
  74. })
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. page{
  82. background-color: #fff;
  83. }
  84. .img-box{
  85. margin-bottom: 20px;
  86. width: 100%;
  87. height: 238px;
  88. img{
  89. width: 100%;
  90. height: 100%;
  91. }
  92. }
  93. .btn{
  94. margin: 0 40px;
  95. display: flex;
  96. .u-btn{
  97. width: 37.8vw;
  98. line-height: 44px;
  99. }
  100. }
  101. </style>