// index.js // 获取应用实例 const app = getApp() const $request = require('../../utils/request.js'); const $util = require('../../utils/util.js'); Page({ data: { currentIndex: 0, keyword: "", // tab tabData: [ { text: "全部", value: "all" }, { text: "我关注的", value: "my1" }, ], currentTab: "all", // 更多tab moreTabOption: [], moreTab: "gengduo", moreTitle: "更多", // list数据加载 // list块加载 listLoading: false, // item行加载 itemLoading: false, // 数据是否加载完成 isFinished: false, listData: [], page: 1, size: 10, total: 0, // 是否加载数据,true加载,false不加载 onRefresh: true, }, onLoad() { this.setData({ listLoading: true, }) // 获取分类 this.getAllType(); }, toggleMore() { this.selectComponent('#item').toggle(); }, // 搜索框输入同步值 bindKeyInput: function (e) { this.setData({ keyword: e.detail.value }) }, // 点击搜索 toSearch(e) { console.log(this.data.keyword) this.setData({ listData: [], onRefresh: true, isFinished: false, listLoading: true, page: 1, }) this.getListData(); }, // tab切换 tabChange(e) { let dataset = e.currentTarget.dataset; // if(dataset.value == 'my1'){ // console.log(this.selectComponent('#shouquan')); // return // } // 如果实在加载中点击无效 if (this.data.listLoading) { return } // 如果当前tab是选中直接点击无效 if (this.data.currentTab == dataset.value) { return } this.setData({ currentTab: dataset.value, moreTitle: "更多", moreTab: "gengduo" }) this.toSearch(); }, // 更多tab切换 moreTabChange(e) { // 如果实在加载中点击无效 if (this.data.listLoading) { return } // 如果当前tab是选中直接点击无效 if (this.data.moreTab == e.detail) { return } let moreTitle = ""; this.data.moreTabOption.forEach(el => { if (el.value == e.detail) { moreTitle = el.text; } }) this.setData({ currentTab: "more", moreTab: e.detail, moreTitle }) this.toSearch(); }, // 进入详情 goDetails(e) { wx.navigateTo({ url: '/pages/index/components/listDetails/Details', success: function (res) { // 通过eventChannel向被打开页面传送数据 res.eventChannel.emit('acceptDataFromOpenerPage', { listDetail: e.detail }) } }) }, // 获取tab数据 getAllType() { $request.get('/businessCommunicationType/getAllType.action').then(res => { if (res.status == 0) { let { tabData, moreTabOption } = this.data; let datas = res.data; datas.forEach(el => { if (tabData.length < 5) { tabData.push({ text: el.typeName, value: el.typeName }) } else { moreTabOption.push({ text: el.typeName, value: el.typeName }) } }) this.setData({ tabData, moreTabOption }) this.getListData(); } }).catch(error => { console.log(error, 'error appletLogin') }) }, // 获取list数据 getListData() { let { page, size, keyword, currentTab, moreTab } = this.data; let type = currentTab; if (currentTab == 'more') { type = moreTab; } if (type == 'all') { type = ""; } $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action', { page, size, keyword, type, isInterest: 0 } ).then(res => { // console.log(res); this.setData({ listLoading: false }) let tempListData = this.data.listData; if (res.status == 0) { let datas = res.data; // 先push数据 tempListData.push(...datas.demandList); tempListData.forEach(el => { el.createdOn = $util.formatTime(new Date(el.createdOn), true); if (typeof el.type == 'string') { el.type = el.type.split(','); } }) // 设置总数 this.setData({ listData: tempListData, total: res.data.total, }) // 如果数据大于了返回的总数 if (tempListData.length >= this.data.total) { // 停止累加数据 this.setData({ onRefresh: false, itemLoading: false, isFinished: true, }) } else { this.setData({ onRefresh: true, itemLoading: false, isFinished: false, page: page + 1 }) } } }).catch(error => { console.log(error, 'error appletLogin') }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if (this.data.onRefresh) { this.setData({ itemLoading: true }) this.getListData(); } }, goLogin() { app.goLogin(); }, })