index.js 4.0 KB

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