index.js 3.7 KB

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