// pages/search/index.js import utils from "../../utils/util"; import {queryFollowspace,queryAllspace,followRoom,unfollowRoom} from "../../requests/api"; import Toast from '../../vant-weapp/dist/toast/toast'; const app = getApp(); Page({ /** * 页面的初始数据 */ data: { spaceName:'', listContent:[], alllistContent:[], activeTab:0, projectId:"", tenantId:"", userId:"", currtPage:1, allListnum:0, seachValue:'', seachTimes:1, imgShow:false, noSpace:false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(wx.getStorageSync('logined')){ this.setData({currtPage:1}); this.setData({projectId:app.globalData.projectId}); this.setData({tenantId:app.globalData.tenantId}); this.setData({userId:app.globalData.userId}); this.getFollowlist(); } }, onShow(){ this.setData({currtPage:1}); }, // 查询关注空间 async getFollowlist(){ const data={ "criteria": { "userId":this.data.userId, "projectId": this.data.projectId, "tenantId": this.data.tenantId } } this.setData({listContent:[]}); // this.setData({imgShow:false}) let res = await queryFollowspace(data); // setTimer = setTimeout(()=>{this.setData({imgShow:true})},800); if(res.count){ res.content.map(item=>{ item.picInit=utils.picInit(item.roomFuncType); }) this.setData({noSpace:false}); this.setData({listContent:res.content}); }else{ this.setData({noSpace:true}); } }, async getallList(value){ if(!wx.getStorageSync('logined')){ return } const data={ "criteria": { "userId":this.data.userId, "projectId": this.data.projectId, "tenantId": this.data.tenantId }, page:this.data.currtPage, size:15, orders:[ { column:"localName", asc:"true" } ] } if(value&&this.data.seachTimes==1){ this.setData({currtPage:1}); this.setData({seachTimes:2}); data.page=1; data.criteria.localName={$like: `%${value}%`} } if(this.data.seachValue&&!value){ data.criteria.localName={$like: `%${this.data.seachValue}%`} } let res; if(data.page!==1){ res =await queryAllspace(data); }else{ res =await queryAllspace(data); } this.setData({allListnum:res.count}); if(res.count&&res.content){ res.content.map(item=>{ item.picInit=utils.picInit(item.roomFuncType); }) this.setData({alllistContent:this.data.alllistContent.concat(res.content)}); }else{ Toast('暂无更多') } }, tabChange(e){ if(e.detail.index==1&&this.data.activeTab==0){ // if(){ this.setData({currtPage:1}); this.setData({alllistContent:[]}); this.getallList(); // } }else if(e.detail.index==0){ this.getFollowlist(); } this.setData({activeTab:e.detail.index}) }, // 搜索 spaceSearch(e){ this.setData({seachValue:e.detail}); this.setData({seachTimes:1}) this.setData({activeTab:1}); this.setData({alllistContent:[]}); this.getallList(e.detail); }, listClick(e){ let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。 let prevPage = pages[ pages.length - 2 ]; prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。 popswiperDate:e.detail.cardDate, fromFollowpage:true, }) wx.navigateBack({ delta: 1 // 返回上一级页面。 }) }, starClick(e){ let checked=e.detail.checked; let spaceId=e.detail.spaceId; const data = { "userId":this.data.userId,//用户id "projectId":this.data.projectId,//项目id "spaceId":spaceId//空间id } if(checked){ followRoom(data) }else{ unfollowRoom(data) } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if(this.data.activeTab==1&&this.data.allListnum!=this.data.alllistContent.length){ this.setData({currtPage:this.data.currtPage+1}) this.getallList(); }else{ Toast('暂无更多') } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })