index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. properties: {
  4. disabled: Boolean
  5. },
  6. data: {
  7. show: false,
  8. sa_invoiceapplyid: 0,
  9. "content": {
  10. nocache: true,
  11. pageNumber: 1,
  12. pageTotal: 1,
  13. total: null,
  14. },
  15. actions: null
  16. },
  17. methods: {
  18. /* 获取发票列表 */
  19. getList(id, init) {
  20. let content = this.data.content;
  21. content.sa_invoiceapplyid = id;
  22. if (init) content.pageNumber = 1;
  23. _Http.basic({
  24. "id": "20221223153403",
  25. content
  26. }).then(res => {
  27. console.log("发票列表", res)
  28. if (res.msg != '成功') return wx.showToast({
  29. title: res.msg,
  30. icon: "none"
  31. })
  32. /* res.data = res.data.map(value => {
  33. if (value.attinfos.length != 0) {
  34. value.attinfos = file.fileList(value.attinfos)
  35. let image = value.attinfos.find(v => v.fileType == "image");
  36. value.cover = image ? image.cover : "";
  37. }
  38. return value;
  39. }) */
  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. })
  48. })
  49. },
  50. previewpdf(e) {
  51. let {
  52. pdfurl,
  53. paperpdfurl
  54. } = e.currentTarget.dataset.item;
  55. if (!pdfurl && !paperpdfurl) {
  56. wx.showToast({
  57. title: '暂无可预览文件',
  58. icon: "none"
  59. })
  60. } else if (pdfurl && paperpdfurl) {
  61. this.setData({
  62. actions: [{
  63. name: '查看发票',
  64. url: pdfurl
  65. },
  66. {
  67. name: '查看纸质发票',
  68. url: paperpdfurl
  69. }
  70. ],
  71. show: true
  72. })
  73. } else {
  74. this.handleOpen(pdfurl || paperpdfurl)
  75. }
  76. },
  77. onClose() {
  78. this.setData({
  79. show: false
  80. });
  81. },
  82. onSelect(event) {
  83. this.handleOpen(event.detail.url)
  84. },
  85. handleOpen(url) {
  86. wx.showLoading({
  87. title: '加载中...',
  88. mask: true
  89. })
  90. wx.downloadFile({
  91. url,
  92. success: function (res) {
  93. const filePath = res.tempFilePath
  94. wx.openDocument({
  95. filePath: filePath,
  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. })