index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. const Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. pageIndex: 0,
  9. loadLen: 10,
  10. logs: []
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: async function(options) {
  16. await this.getLog()
  17. },
  18. async getLog() {
  19. let uid = Parse.User.current().id
  20. let BehaviorLog = new Parse.Query('BehaviorLog')
  21. BehaviorLog.equalTo('company', company)
  22. BehaviorLog.equalTo('user', uid)
  23. BehaviorLog.include('targetObject')
  24. BehaviorLog.limit(this.data.loadLen)
  25. BehaviorLog.descending('createdAt')
  26. BehaviorLog.skip(this.data.pageIndex * this.data.loadLen)
  27. let logs = await BehaviorLog.find()
  28. console.log(logs)
  29. if (logs && logs.length > 0) {
  30. let logsJSON = []
  31. logs.forEach(log => {
  32. logsJSON.push(log.toJSON())
  33. })
  34. let newLogs = this.data.logs.concat(logsJSON)
  35. this.setData({
  36. logs: newLogs
  37. })
  38. }
  39. },
  40. toDetail(e) {
  41. console.log(e)
  42. let item = e.currentTarget.dataset.item
  43. if (item.targetClassName == 'ShopGoods') {
  44. wx.navigateTo({
  45. url: '/nova-shop/pages/shop-goods/goods-detail/index?id=' + item.targetId
  46. })
  47. } else if (item.targetClassName == 'Article') {
  48. wx.navigateTo({
  49. url: '/common-page/pages/cates/article-detail/index?aid=' + item.targetId + "&title=" + item.name
  50. })
  51. } else if (item.targetClassName == 'Lesson') {
  52. wx.navigateTo({
  53. url: '/nova-lesson/pages/lesson-detail/index?id=' + item.collectId
  54. })
  55. } else if (item.targetClassName == 'Activity') {
  56. wx.navigateTo({
  57. url: '/nova-activity/pages/activity-detail/index?aid=' + item.targetId
  58. })
  59. }
  60. },
  61. onClose(event) {
  62. console.log(event);
  63. let that = this
  64. let id = event.currentTarget.dataset.id
  65. let index = event.currentTarget.dataset.index
  66. console.log(id, index)
  67. const {
  68. position,
  69. instance
  70. } = event.detail;
  71. switch (position) {
  72. case 'right':
  73. instance.close();
  74. break;
  75. }
  76. wx.showModal({
  77. title: '确认删除',
  78. content: '确定删除该记录?',
  79. success: function(res) {
  80. if (res.confirm) {
  81. that.deleteCollect(id, index)
  82. }
  83. }
  84. })
  85. },
  86. async deleteCollect(id, index) {
  87. let that = this
  88. let BehaviorLog = new Parse.Query('BehaviorLog')
  89. let behaviorLog = await BehaviorLog.get(id)
  90. if (behaviorLog && behaviorLog.id)(
  91. behaviorLog.destroy().then(res => {
  92. console.log(res)
  93. if (res && res.id) {
  94. console.log(id, index)
  95. let logs = that.data.logs
  96. collectList.splice(index, 1)
  97. that.setData({
  98. logs: logs
  99. })
  100. }
  101. })
  102. )
  103. },
  104. /**
  105. * 生命周期函数--监听页面初次渲染完成
  106. */
  107. onReady: function() {
  108. },
  109. /**
  110. * 生命周期函数--监听页面显示
  111. */
  112. onShow: function() {
  113. },
  114. /**
  115. * 生命周期函数--监听页面隐藏
  116. */
  117. onHide: function() {
  118. },
  119. /**
  120. * 生命周期函数--监听页面卸载
  121. */
  122. onUnload: function() {
  123. },
  124. /**
  125. * 页面相关事件处理函数--监听用户下拉动作
  126. */
  127. onPullDownRefresh: function() {
  128. },
  129. /**
  130. * 页面上拉触底事件的处理函数
  131. */
  132. onReachBottom: async function() {
  133. this.setData({
  134. pageIndex: this.data.pageIndex + 1
  135. })
  136. await this.getLog()
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage: function() {
  142. }
  143. })