index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. properties: {
  4. disabled: {
  5. type: Boolean
  6. },
  7. apiId: {
  8. type: Number,
  9. value: 20221223153403
  10. }
  11. },
  12. data: {
  13. show: false,
  14. "content": {
  15. nocache: true,
  16. pageNumber: 1,
  17. pageTotal: 1,
  18. total: null,
  19. },
  20. actions: null
  21. },
  22. methods: {
  23. /* 获取发票列表 */
  24. getList(id, init) {
  25. let content = this.data.content;
  26. content.sa_invoiceapplyid = id;
  27. content.sa_orderid = id;
  28. if (init) content.pageNumber = 1;
  29. _Http.basic({
  30. id: this.data.apiId,
  31. content
  32. }).then(res => {
  33. console.log("发票列表", res)
  34. if (res.msg != '成功') return wx.showToast({
  35. title: res.msg,
  36. icon: "none"
  37. });
  38. /* res.data[0].paperpdfurl = "https://yostest2.obs.cn-east-2.myhuaweicloud.com:443/202302211676966719291B15c18260.pdf";
  39. res.data[0].pdfurl = "https://yostest2.obs.cn-east-2.myhuaweicloud.com:443/202302211676966719291B15c18260.pdf"; */
  40. this.setData({
  41. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  42. "content.pageNumber": res.pageNumber + 1,
  43. "content.pageSize": res.pageSize,
  44. "content.pageTotal": res.pageTotal,
  45. "content.total": res.total,
  46. sa_invoiceapplyid: id,
  47. sa_orderid: id
  48. })
  49. })
  50. },
  51. previewpdf(e) {
  52. let {
  53. pdfurl,
  54. paperpdfurl
  55. } = e.currentTarget.dataset.item;
  56. if (!pdfurl && !paperpdfurl) {
  57. wx.showToast({
  58. title: '暂无可预览文件',
  59. icon: "none"
  60. })
  61. } else if (pdfurl && paperpdfurl) {
  62. this.setData({
  63. actions: [{
  64. name: '查看发票',
  65. url: pdfurl
  66. },
  67. {
  68. name: '查看纸质发票',
  69. url: paperpdfurl
  70. }
  71. ],
  72. show: true
  73. })
  74. } else {
  75. this.handleOpen(pdfurl || paperpdfurl)
  76. }
  77. },
  78. onClose() {
  79. this.setData({
  80. show: false
  81. });
  82. },
  83. onSelect(event) {
  84. this.handleOpen(event.detail.url)
  85. },
  86. handleOpen(url) {
  87. wx.showLoading({
  88. title: '加载中...',
  89. mask: true
  90. })
  91. wx.downloadFile({
  92. url,
  93. success: function (res) {
  94. const filePath = res.tempFilePath
  95. wx.openDocument({
  96. filePath: filePath,
  97. showMenu: true,
  98. complete(res) {
  99. console.log("打开文档", res)
  100. wx.hideLoading()
  101. if (res.errMsg != 'openDocument:ok') wx.showToast({
  102. title: '打开失败',
  103. icon: "none"
  104. })
  105. }
  106. })
  107. },
  108. fail(err) {
  109. wx.hideLoading()
  110. wx.showToast({
  111. title: '打开失败',
  112. icon: "none"
  113. })
  114. }
  115. })
  116. },
  117. }
  118. })