index.js 3.9 KB

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