index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // pages/search/index.js
  2. import utils from "../../utils/util";
  3. import {queryFollowspace,queryAllspace,followRoom,unfollowRoom} from "../../requests/api";
  4. import Toast from '../../vant-weapp/dist/toast/toast';
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. spaceName:'',
  12. listContent:[],
  13. alllistContent:[],
  14. activeTab:0,
  15. projectId:"",
  16. tenantId:"",
  17. userId:"",
  18. currtPage:1,
  19. allListnum:0,
  20. seachValue:'',
  21. seachTimes:1,
  22. imgShow:false,
  23. noSpace:false,
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. if(wx.getStorageSync('logined')){
  30. this.setData({currtPage:1});
  31. this.setData({projectId:app.globalData.projectId});
  32. this.setData({tenantId:app.globalData.tenantId});
  33. this.setData({userId:app.globalData.userId});
  34. this.getFollowlist();
  35. }
  36. },
  37. onShow(){
  38. this.setData({currtPage:1});
  39. },
  40. // 查询关注空间
  41. async getFollowlist(){
  42. const data={
  43. "criteria": {
  44. "userId":this.data.userId,
  45. "projectId": this.data.projectId,
  46. "tenantId": this.data.tenantId
  47. }
  48. }
  49. this.setData({listContent:[]});
  50. // this.setData({imgShow:false})
  51. let res = await queryFollowspace(data);
  52. // setTimer = setTimeout(()=>{this.setData({imgShow:true})},800);
  53. if(res.count){
  54. res.content.map(item=>{
  55. item.picInit=utils.picInit(item.roomFuncType);
  56. })
  57. this.setData({noSpace:false});
  58. this.setData({listContent:res.content});
  59. }else{
  60. this.setData({noSpace:true});
  61. }
  62. },
  63. async getallList(value){
  64. if(!wx.getStorageSync('logined')){
  65. return
  66. }
  67. const data={
  68. "criteria": {
  69. "userId":this.data.userId,
  70. "projectId": this.data.projectId,
  71. "tenantId": this.data.tenantId
  72. },
  73. page:this.data.currtPage,
  74. size:15,
  75. orders:[
  76. {
  77. column:"localName",
  78. asc:"true"
  79. }
  80. ]
  81. }
  82. if(value&&this.data.seachTimes==1){
  83. this.setData({currtPage:1});
  84. this.setData({seachTimes:2});
  85. data.page=1;
  86. data.criteria.localName={$like: `%${value}%`}
  87. }
  88. if(this.data.seachValue&&!value){
  89. data.criteria.localName={$like: `%${this.data.seachValue}%`}
  90. }
  91. let res;
  92. if(data.page!==1){
  93. res =await queryAllspace(data);
  94. }else{
  95. res =await queryAllspace(data);
  96. }
  97. this.setData({allListnum:res.count});
  98. if(res.count&&res.content){
  99. res.content.map(item=>{
  100. item.picInit=utils.picInit(item.roomFuncType);
  101. })
  102. this.setData({alllistContent:this.data.alllistContent.concat(res.content)});
  103. }else{
  104. Toast('暂无更多')
  105. }
  106. },
  107. tabChange(e){
  108. if(e.detail.index==1&&this.data.activeTab==0){
  109. // if(){
  110. this.setData({currtPage:1});
  111. this.setData({alllistContent:[]});
  112. this.getallList();
  113. // }
  114. }else if(e.detail.index==0){
  115. this.getFollowlist();
  116. }
  117. this.setData({activeTab:e.detail.index})
  118. },
  119. // 搜索
  120. spaceSearch(e){
  121. this.setData({seachValue:e.detail});
  122. this.setData({seachTimes:1})
  123. this.setData({activeTab:1});
  124. this.setData({alllistContent:[]});
  125. this.getallList(e.detail);
  126. },
  127. listClick(e){
  128. let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
  129. let prevPage = pages[ pages.length - 2 ];
  130. prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
  131. popswiperDate:e.detail.cardDate,
  132. fromFollowpage:true,
  133. })
  134. wx.navigateBack({
  135. delta: 1 // 返回上一级页面。
  136. })
  137. },
  138. starClick(e){
  139. let checked=e.detail.checked;
  140. let spaceId=e.detail.spaceId;
  141. const data = {
  142. "userId":this.data.userId,//用户id
  143. "projectId":this.data.projectId,//项目id
  144. "spaceId":spaceId//空间id
  145. }
  146. if(checked){
  147. followRoom(data)
  148. }else{
  149. unfollowRoom(data)
  150. }
  151. },
  152. /**
  153. * 页面相关事件处理函数--监听用户下拉动作
  154. */
  155. onPullDownRefresh: function () {
  156. },
  157. /**
  158. * 页面上拉触底事件的处理函数
  159. */
  160. onReachBottom: function () {
  161. if(this.data.activeTab==1&&this.data.allListnum!=this.data.alllistContent.length){
  162. this.setData({currtPage:this.data.currtPage+1})
  163. this.getallList();
  164. }else{
  165. Toast('暂无更多')
  166. }
  167. },
  168. /**
  169. * 用户点击右上角分享
  170. */
  171. onShareAppMessage: function () {
  172. }
  173. })