123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- keyword: ['','',''],
- tab: 0,
- url:['portal/articles/index','activity/activity/index','activity/activity_review/index'],
- is_first: [true,true,true],
- list: [[],[],[]],
- no_more:[false,false,false],
- page:[1,1,1],
- custombar: app.globalData.CustomBar,
- nav_top: 0,
- nav_fixed: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options.tab) {
- this.setData({tab:options.tab});
- }
- if (options.keyword) {
- let keyword = this.data.keyword;
- keyword[this.data.tab] = options.keyword;
- this.setData({keyword:keyword});
- }
- //获取导航栏top
- let query = wx.createSelectorQuery()
- query.select('#nav').boundingClientRect( (rect) => {
- this.setData({nav_top:rect.top - this.data.custombar});
- }).exec()
- //获取数据
- let is_first = this.data.is_first;
- is_first[this.data.tab] = false;
- this.setData({is_first:is_first});
- this.getList();
- },
- //tab切换
- tabSelect(e) {
- let tab = e.currentTarget.dataset.tab;
- this.setData({tab:tab});
- let is_first = this.data.is_first;
- if (is_first[tab]) {
- is_first[tab] = false;
- this.setData({is_first:is_first});
- this.getList();
- }
- },
- //搜索
- bindInput(e) {
- let keyword = this.data.keyword;
- keyword[this.data.tab] = e.detail.value;
- this.setData({keyword:keyword});
- },
- bindSearch(){
- this.resetParam();
- this.getList();
- },
- //获取数据
- getList() {
- let self = this;
- let tab = this.data.tab;
- let no_more = this.data.no_more;
- let url = this.data.url;
- //没有下一页
- if (no_more[tab]) {
- return false;
- }
- //获取数据
- app.post(url[tab],{
- page:self.data.page[tab],
- keyword:self.data.keyword[tab],
- },function(res){
- if (res.length < 10) {
- no_more[tab] = true;
- self.setData({no_more:no_more});
- }
- let list = self.data.list;
- list[tab] = list[tab].concat(res);
- let page = self.data.page;
- page[tab]++;
- self.setData({list:list,page:page});
- })
- },
- //重置参数
- resetParam() {
- let tab = this.data.tab;
- let list = this.data.list;
- list[tab] = [];
- let no_more = this.data.no_more;
- no_more[tab] = false;
- let page = this.data.page;
- page[tab] = 1;
- this.setData({list:list,no_more:no_more,page:page});
- },
- resetKeyword() {
- let keyword = this.data.keyword;
- keyword[this.data.tab] = '';
- this.setData({keyword:keyword});
- },
- //滚动事件
- onPageScroll(e) {
- if (e.scrollTop >= this.data.nav_top) {
- if (!this.data.nav_fixed) {
- this.setData({nav_fixed: true});
- }
- } else {
- if (this.data.nav_fixed) {
- this.setData({nav_fixed:false});
- }
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.resetParam();
- this.resetKeyword();
- this.getList();
- wx.stopPullDownRefresh();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- this.getList();
- },
- //跳转
- toRcs() {
- wx.navigateTo({
- url: '/pages/webview/rcs/rcs',
- })
- },
- toRecuperate() {
- wx.navigateTo({
- url: '/pages/webview/recuperate/recuperate',
- })
- },
- toBusiness() {
- wx.navigateTo({
- url: '/pages/business/home/home',
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: "晋爱人才",
- path: "/pages/home/home/home",
- };
- },
- })
|