index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // pages/zzdy/components/index/index.js
  2. import {
  3. getInvoice
  4. } from "../../../../api/zzdy"
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. uuid: {
  11. type: String,
  12. value: ""
  13. }
  14. },
  15. /**
  16. * 组件的初始数据
  17. */
  18. data: {
  19. menus: [{
  20. name: "从微信上传",
  21. introduce: "支持以下文档格式:",
  22. text: "pdf、docx、xlsx、pptx",
  23. bg: "../../../../icon/zzdy/wxsc.png",
  24. path: "./pages/wxsc/wxsc"
  25. },
  26. {
  27. name: "从相册上传",
  28. introduce: "支持以下文档格式:",
  29. text: "jpg、png、gif",
  30. bg: "../../../../icon/zzdy/xcsc.png",
  31. path: "./pages/xcsc/xcsc"
  32. },
  33. {
  34. name: "从卡包上传",
  35. introduce: "将会从微信卡包选择",
  36. text: "您要打印的票据",
  37. bg: "../../../../icon/zzdy/kbsc.png",
  38. path: "kb"
  39. }
  40. ]
  41. },
  42. /**
  43. * 组件的方法列表
  44. */
  45. methods: {
  46. // 菜单点击
  47. menuBtn(e) {
  48. let that = this
  49. var path = e.currentTarget.dataset.item.path
  50. if (this.data.uuid.length > 0) {
  51. if (path == 'kb') {
  52. wx.chooseInvoice({
  53. success: res => {
  54. var fpInfo = JSON.parse(res.invoiceInfo)
  55. let newInfo = []
  56. fpInfo.map(item => {
  57. var obj = {
  58. cardId: item.card_id,
  59. encryptCode: item.encrypt_code
  60. }
  61. newInfo.push(obj)
  62. })
  63. that.getFpPDF(newInfo)
  64. }
  65. })
  66. } else {
  67. wx.navigateTo({
  68. url: path + '?uuid=' + that.data.uuid,
  69. })
  70. }
  71. } else {
  72. wx.showModal({
  73. title: '提示',
  74. content: '请扫描自助机上的二维码进入后再上传文件。',
  75. showCancel: false
  76. })
  77. }
  78. },
  79. // 获取pdf文件
  80. async getFpPDF(e) {
  81. wx.showLoading({
  82. title: '正在获取发票pdf文件....',
  83. })
  84. let that = this
  85. let pdfList = []
  86. for (let i = 0; i < e.length; i++) {
  87. let pdf = await that.getPdf(e[i])
  88. pdfList.push(pdf)
  89. }
  90. that.getFpFiles(pdfList)
  91. wx.hideLoading()
  92. },
  93. getPdf(e) {
  94. let that = this
  95. return new Promise((resolve, reject) => {
  96. getInvoice(e).then(res => {
  97. if (res.code == 200) {
  98. resolve(res.url)
  99. } else {
  100. reject()
  101. }
  102. })
  103. })
  104. },
  105. // 获取发票文件
  106. getFpFiles(e) {
  107. let that = this
  108. wx.setStorage({
  109. key: "FPLIST",
  110. data: e
  111. })
  112. wx.navigateTo({
  113. url: './pages/scList/scList?uuid=' + that.data.uuid,
  114. })
  115. }
  116. }
  117. })