index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. navheight: 0, //nav栏高度
  22. //朋友圈
  23. cardList: [],
  24. loadedItems: 0, // 已加载的商品数量
  25. pageSize: 6, // 每次加载的商品数量
  26. noMoreItems: false, // 是否还有更多商品
  27. ActivityList: [],
  28. },
  29. lifetimes: {
  30. detached: function () {
  31. // 在组件实例被从页面节点树移除时执行
  32. },
  33. attached: async function () {
  34. // 在组件实例进入页面节点树时执行
  35. // 计算
  36. const systemInfo = wx.getSystemInfoSync();
  37. const statusBarHeight = systemInfo.statusBarHeight || 0;
  38. const screenHeight = systemInfo.screenHeight || 0;
  39. const custom = wx.getMenuButtonBoundingClientRect();
  40. const customHeight = custom.height + 10 + 2 || 0;
  41. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  42. const contentHeight = (screenHeight - 50 - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  43. const navheight = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  44. this.setData({
  45. statusBarHeight,
  46. screenHeight: (screenHeight - 50 - bottomNavHeight) * 750 / systemInfo.windowWidth,
  47. customHeight,
  48. bottomNavHeight,
  49. contentHeight,
  50. navheight
  51. });
  52. // console.log('123', contentHeight);
  53. // this.iddepe()
  54. this.getcircle()
  55. this.getact()
  56. },
  57. },
  58. /**
  59. * 组件的方法列表
  60. */
  61. methods: {
  62. //查全部朋友圈
  63. async getcircle() {
  64. let Profilequery = new Parse.Query('AIMoment');
  65. Profilequery.equalTo('company', company);
  66. Profilequery.equalTo('isVisible', true);
  67. Profilequery.notEqualTo('isDeleted', true)
  68. Profilequery.descending('createdAt');
  69. // 设置查询的限制和偏移
  70. Profilequery.limit(this.data.pageSize);
  71. Profilequery.skip(this.data.loadedItems);
  72. let P = await Profilequery.find();
  73. let profile1List = P.map(item => item.toJSON());
  74. // 检查是否还有更多商品
  75. if (profile1List.length < this.data.pageSize) {
  76. this.setData({
  77. noMoreItems: true
  78. });
  79. } else {
  80. this.setData({
  81. noMoreItems: false
  82. });
  83. }
  84. this.setData({
  85. cardList: this.data.cardList.concat(profile1List),
  86. loadedItems: this.data.loadedItems + profile1List.length,
  87. })
  88. console.log(this.data.cardList);
  89. },
  90. loadMoreData: async function () {
  91. // 触底时加载更多数据
  92. if (!this.data.noMoreItems) {
  93. await this.getcircle();
  94. }
  95. },
  96. getcircle2() {
  97. this.setData({
  98. cardList: [],
  99. loadedItems: 0,
  100. noMoreItems: false
  101. })
  102. console.log('运行了');
  103. this.getcircle()
  104. },
  105. //跳转
  106. gourl(e) {
  107. const url = e.currentTarget.dataset.url
  108. wx.navigateTo({
  109. url: `${url}` // 目标页面的路径
  110. });
  111. },
  112. //跳转活动
  113. goactivity(e) {
  114. const url = e.currentTarget.dataset.url
  115. const acid = e.currentTarget.dataset.acid
  116. wx.navigateTo({
  117. url: `${url}?id=` + acid // 目标页面的路径
  118. });
  119. },
  120. //判断是否有部门
  121. // async iddepe(){
  122. // const currentUser = Parse.User.current();
  123. // let Profilequery2 = new Parse.Query('Profile');
  124. // Profilequery2.equalTo('company', company);
  125. // Profilequery2.equalTo('user', currentUser.id);
  126. // Profilequery2.equalTo('isCheck', true);
  127. // Profilequery2.notEqualTo('isDeleted', true)
  128. // let P2 = await Profilequery2.first();
  129. // if(P2){
  130. // this.getcircle()
  131. // }else{
  132. // wx.navigateTo({
  133. // url: '../../pages/my/my-profile/index?type='+'资料认证'// 目标页面的路径
  134. // });
  135. // }
  136. // }
  137. //首页活动
  138. async getact() {
  139. let Activityquery = new Parse.Query('Activity');
  140. Activityquery.equalTo('company', company);
  141. Activityquery.notEqualTo('isDeleted', true);
  142. Activityquery.equalTo('isEnabled', true);
  143. Activityquery.ascending('index'); // 按index升序排序
  144. Activityquery.limit(4); // 限制结果为前四个
  145. let P = await Activityquery.find();
  146. let ActivityList = P.map(item => item.toJSON());
  147. this.setData({
  148. ActivityList,
  149. });
  150. },
  151. }
  152. })