123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- const app = getApp()
- var util = require('../../utils/util.js');
- Page({
- data: {
- loadMore: true,
- classification: {
- tabs: [],
- activeIndex: 0
- }
- },
- pageNum: 1,
- onLoad: function(options) {
- this.gid = options.gid || '';
- let name = options.name || '';
- name && wx.setNavigationBarTitle({
- title: name
- })
- this._doRefreshMasonry();
- },
- onShow: function() {
- util.check_login_new().then((res) => {
- this.setData({
- needAuth: !res
- });
- })
- },
- noLogin: function() {
- this.setData({
- needAuth: true,
- showAuthModal: true
- })
- },
- /**
- * 授权成功回调
- */
- authSuccess: function() {
- const that = this;
- this.pageNum = 1;
- this.setData({
- loadMore: true,
- showEmpty: 0,
- needAuth: false,
- showAuthModal: false
- }, () => {
- that._doRefreshMasonry()
- })
- },
- authModal: function() {
- if (this.data.needAuth) {
- this.setData({
- showAuthModal: !this.data.showAuthModal
- });
- return false;
- }
- return true;
- },
- onPullDownRefresh: function() {
- const that = this;
- this.pageNum = 1;
- this.setData({
- loadMore: true,
- showEmpty: 0
- }, () => {
- that.getInfo();
- that._doRefreshMasonry()
- })
- },
- onReachBottom: function() {
- this.data.loadMore && this._doAppendMasonry()
- },
- _doRefreshMasonry() {
- let that = this;
- this.masonryListComponent = this.selectComponent('#masonry');
- this.getData().then(res => {
- that.masonryListComponent.start(res).then(() => {})
- }).catch(() => {
- that.masonryListComponent.start([]).then(() => {})
- })
- },
- _doAppendMasonry() {
- let that = this;
- this.masonryListComponent = this.selectComponent('#masonry')
- // 获取接口数据后使用瀑布流组件append方法,当append完成后调用then,是否可触底价在的标志位可以在这里处理
- this.getData().then(res => {
- that.masonryListComponent.append(res).then(() => {
- console.log('refresh completed')
- })
- }).catch(() => {
- console.log('没有更多了')
- })
- },
- /**
- * 获取列表
- */
- getData: function() {
- return new Promise((resolve, reject) => {
- let that = this;
- let token = wx.getStorageSync('token');
- let gid = that.gid;
- wx.showLoading();
- app.util.request({
- 'url': 'entry/wxapp/index',
- 'data': {
- controller: 'recipe.get_recipe_list',
- token: token,
- gid,
- pageNum: this.pageNum
- },
- dataType: 'json',
- success: function(res) {
- wx.stopPullDownRefresh();
- if (res.data.code == 0) {
- let list = res.data.data;
- that.pageNum++;
- resolve(list);
- } else {
- // 无数据
- let h = {
- loadMore: false
- }
- if (that.pageNum == 1) h.showEmpty = 1;
- that.setData(h);
- reject('');
- }
- wx.hideLoading();
- }
- })
- })
- }
- })
|