myFile.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { documentList, createQRcode } from "../../api/document";
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. qrcodeDialog: false,
  8. currentPage: 1,
  9. hasNext: false,
  10. fileList: [],
  11. baseStr: 'data:image/jpg;base64,',
  12. QRCodeBase64: ''
  13. },
  14. /**
  15. * 生命周期函数--监听页面显示
  16. */
  17. onShow() {
  18. this.getDocumentList()
  19. },
  20. // 获取档案列表
  21. getDocumentList () {
  22. var data = {
  23. currentPage: this.data.currentPage
  24. }
  25. wx.showLoading({
  26. title: '加载中...',
  27. mask: true
  28. })
  29. documentList(data).then(res => {
  30. wx.hideLoading()
  31. var response = res.data.vos
  32. response.map(item => {
  33. item.birthDay = item.birthday.split(' ')[0]
  34. })
  35. this.setData({
  36. hasNext: res.data.hasNext,
  37. fileList: response
  38. })
  39. }).catch(e => {
  40. wx.hideLoading()
  41. wx.showModal({
  42. content: e,
  43. confirmColor: '#333',
  44. showCancel: false
  45. })
  46. })
  47. },
  48. onReachBottom () {
  49. if (this.data.hasNext) {
  50. var _currentPag = this.data.currentPage + 1
  51. this.setData({
  52. currentPage: _currentPag
  53. })
  54. this.getDocumentList()
  55. }
  56. },
  57. /**
  58. * 新建档案
  59. */
  60. handleAddFile() {
  61. wx.navigateTo({
  62. url: '/pages/createFile/createFile?from=myFile'
  63. })
  64. },
  65. /**
  66. * 管理档案
  67. */
  68. handleFile() {
  69. if (this.data.fileList.length !== 0) {
  70. wx.navigateTo({
  71. url: '/pages/handleFile/handleFile',
  72. })
  73. } else {
  74. wx.showToast({
  75. title: '暂无档案',
  76. icon: 'error'
  77. })
  78. }
  79. },
  80. handleShowQRCode (e) {
  81. var that = this
  82. var id = e.currentTarget.dataset.id
  83. wx.showLoading({
  84. title: '生成中...'
  85. })
  86. createQRcode({ documentId: id }).then(res => {
  87. wx.hideLoading()
  88. that.setData({
  89. QRCodeBase64: that.data.baseStr + res.data,
  90. qrcodeDialog: true
  91. })
  92. }).catch(e => {
  93. wx.hideLoading()
  94. wx.showModal({
  95. content: e,
  96. confirmColor: '#333',
  97. showCancel: false
  98. })
  99. })
  100. },
  101. handleCloseQRCode () {
  102. this.setData({
  103. qrcodeDialog: false,
  104. QRCodeBase64: ''
  105. })
  106. }
  107. })