index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // nova-werun/components/circle/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. //屏幕高度
  15. statusBarHeight: 0, // 状态栏高度
  16. screenHeight: 0, // 屏幕高度
  17. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  18. bottomNavHeight: 0, // 底部导航栏高度
  19. contentHeight: 0, // 可用内容高度
  20. contentpadding: 0, //顶部padding高度
  21. //朋友圈
  22. cardList: [],
  23. loadedItems: 0, // 已加载的商品数量
  24. pageSize: 6, // 每次加载的商品数量
  25. noMoreItems: false, // 是否还有更多商品
  26. },
  27. lifetimes: {
  28. detached: function () {
  29. // 在组件实例被从页面节点树移除时执行
  30. },
  31. attached: async function () {
  32. // 在组件实例进入页面节点树时执行
  33. // 计算
  34. const systemInfo = wx.getSystemInfoSync();
  35. const statusBarHeight = systemInfo.statusBarHeight || 0;
  36. const screenHeight = systemInfo.screenHeight || 0;
  37. const custom = wx.getMenuButtonBoundingClientRect();
  38. const customHeight = custom.height + 10 + 2 || 0;
  39. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  40. const contentHeight = (screenHeight - 50 - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  41. this.setData({
  42. statusBarHeight,
  43. screenHeight,
  44. customHeight,
  45. bottomNavHeight,
  46. contentHeight
  47. });
  48. // console.log('123', contentHeight);
  49. this.getcircle()
  50. },
  51. },
  52. /**
  53. * 组件的方法列表
  54. */
  55. methods: {
  56. //查全部朋友圈
  57. async getcircle() {
  58. const currentUser = Parse.User.current();
  59. let Profilequery2 = new Parse.Query('Profile');
  60. Profilequery2.equalTo('company', company);
  61. Profilequery2.equalTo('user', currentUser.id);
  62. Profilequery2.equalTo('isCheck', true);
  63. Profilequery2.notEqualTo('isDeleted', true)
  64. let P2 = await Profilequery2.find();
  65. let profile1List2 = P2.map(item => item.toJSON());
  66. // console.log(profile1List2);
  67. const department = profile1List2[0].department.objectId
  68. // console.log(department);
  69. let queryWhere = {
  70. where: {
  71. profile: {
  72. $inQuery: {
  73. where: {
  74. department: department
  75. },
  76. className: 'Profile',
  77. },
  78. }
  79. }
  80. }
  81. let Profilequery = Parse.Query.fromJSON('AIMoment', queryWhere);
  82. Profilequery.equalTo('company', company);
  83. Profilequery.equalTo('isVisible', true);
  84. Profilequery.notEqualTo('isDeleted', true)
  85. Profilequery.descending('createdAt');
  86. // 设置查询的限制和偏移
  87. Profilequery.limit(this.data.pageSize);
  88. Profilequery.skip(this.data.loadedItems);
  89. let P = await Profilequery.find();
  90. let profile1List = P.map(item => item.toJSON());
  91. // 检查是否还有更多商品
  92. if (profile1List.length < this.data.pageSize) {
  93. this.setData({
  94. noMoreItems: true
  95. });
  96. } else {
  97. this.setData({
  98. noMoreItems: false
  99. });
  100. }
  101. this.setData({
  102. cardList: this.data.cardList.concat(profile1List),
  103. loadedItems: this.data.loadedItems + profile1List.length,
  104. })
  105. console.log(this.data.cardList);
  106. },
  107. loadMoreData: async function () {
  108. // 触底时加载更多数据
  109. if (!this.data.noMoreItems) {
  110. await this.getcircle();
  111. }
  112. },
  113. getcircle2() {
  114. this.setData({
  115. cardList: [],
  116. loadedItems:0,
  117. noMoreItems:false
  118. })
  119. console.log('运行了');
  120. this.getcircle()
  121. },
  122. //跳转
  123. gourl(e) {
  124. const url = e.currentTarget.dataset.url
  125. wx.navigateTo({
  126. url: `${url}` // 目标页面的路径
  127. });
  128. },
  129. }
  130. })