index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const dateF = require('../../../utils/date')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. list: null
  10. },
  11. async getBehaviorLog(id) {
  12. let BehaviorLog = new Parse.Query('BehaviorLog')
  13. BehaviorLog.equalTo('company', company)
  14. BehaviorLog.equalTo('user', id)
  15. BehaviorLog.descending('createdAt')
  16. BehaviorLog.include('targetObject')
  17. let behaviorLog = await BehaviorLog.find()
  18. let listJSON = []
  19. if (behaviorLog && behaviorLog.length > 0) {
  20. behaviorLog.forEach(behaviorLog => {
  21. let b = behaviorLog.toJSON()
  22. b.joinTime = dateF.formatTime("YYYY-mm-dd HH:MM:SS", b.createdAt)
  23. listJSON.push(b)
  24. })
  25. this.setData({ list: listJSON })
  26. }
  27. console.log(this.data.list);
  28. },
  29. lesson(e) {
  30. let id = e.currentTarget.dataset.item.targetObject[0].objectId
  31. console.log(id);
  32. wx.navigateTo({
  33. url: '/nova-lesson/pages/lesson-detail/lesson-detail?id=' + id
  34. })
  35. },
  36. goods(e) {
  37. let id = e.currentTarget.dataset.item.targetObject[0].objectId
  38. console.log(id);
  39. wx.navigateTo({
  40. url: '/nova-shop/pages/shop-goods/goods-detail/index?id=' + id
  41. })
  42. },
  43. async collection(e) {
  44. console.log(e.currentTarget.dataset.item);
  45. // if (schemaName == "ShopGoods") {
  46. // let name = e.currentTarget.dataset.item.targetObject[0].name
  47. // }
  48. // if (schemaName == "Lesson") {
  49. // let name = e.currentTarget.dataset.item.targetObject[0].title
  50. // }
  51. let collectId = e.currentTarget.dataset.item.targetObject[0].objectId
  52. let schemaName = e.currentTarget.dataset.item.targetClassName
  53. let image = e.currentTarget.dataset.item.targetObject[0].image
  54. console.log(collectId, schemaName, image);
  55. let Collecti = new Parse.Query('Collect')
  56. Collecti.equalTo('company', company)
  57. Collecti.equalTo('user', Parse.User.current().id)
  58. Collecti.equalTo('collectId', collectId)
  59. let res = await Collecti.first()
  60. if (res && res.id) {
  61. wx.showToast({
  62. title: '您已收藏该课程',
  63. icon: 'none'
  64. })
  65. return
  66. }
  67. let collect
  68. let Collect = Parse.Object.extend("Collect")
  69. collect = new Collect()
  70. collect.set("company", {
  71. __type: "Pointer",
  72. className: "Company",
  73. objectId: company
  74. })
  75. collect.set("user", {
  76. __type: "Pointer",
  77. className: "_User",
  78. objectId: Parse.User.current().id
  79. })
  80. if (schemaName == "ShopGoods") {
  81. collect.set("collectTarget", [{
  82. __type: "Pointer",
  83. className: "ShopGoods",
  84. objectId: collectId
  85. }])
  86. collect.set("name", e.currentTarget.dataset.item.targetObject[0].name)
  87. collect.set("type", "goods")
  88. }
  89. if (schemaName == "Lesson") {
  90. collect.set("collectTarget", [{
  91. __type: "Pointer",
  92. className: "Lesson",
  93. objectId: collectId
  94. }])
  95. collect.set("name", e.currentTarget.dataset.item.targetObject[0].title)
  96. collect.set("type", "lesson")
  97. }
  98. // if (schemaName == "Lesson") {
  99. // collect.set("collectTarget", [{
  100. // __type: "Pointer",
  101. // className: "Lesson",
  102. // objectId: collectId
  103. // }])
  104. // }
  105. collect.set("collectId", collectId)
  106. collect.set("schemaName", schemaName)
  107. collect.set("image", image)
  108. collect.save().then(a => {
  109. console.log(a)
  110. wx.showToast({
  111. title: '收藏成功',
  112. icon: 'none'
  113. })
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面加载
  118. */
  119. onLoad: function(options) {
  120. let id = Parse.User.current().id
  121. console.log(id);
  122. this.getBehaviorLog(id)
  123. },
  124. /**
  125. * 生命周期函数--监听页面初次渲染完成
  126. */
  127. onReady: function() {
  128. },
  129. /**
  130. * 生命周期函数--监听页面显示
  131. */
  132. onShow: function() {
  133. },
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function() {
  138. },
  139. /**
  140. * 生命周期函数--监听页面卸载
  141. */
  142. onUnload: function() {
  143. },
  144. /**
  145. * 页面相关事件处理函数--监听用户下拉动作
  146. */
  147. onPullDownRefresh: function() {
  148. },
  149. /**
  150. * 页面上拉触底事件的处理函数
  151. */
  152. onReachBottom: function() {
  153. },
  154. /**
  155. * 用户点击右上角分享
  156. */
  157. onShareAppMessage: function() {
  158. }
  159. })