123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- // pages/list/list.js
- var utils = require('../../utils/util.js');
- Page({
- data: {
- id:0,
- page: 1,
- dataList:[],
- hidden: true,
- },
- onLoad: function (options) {
- var that = this;
- that.setData({ id: options.id});
- if(that.data.id == 0){
- var obj = { 'is_hot': 0, 'is_new': 1 };
- utils.initList(that, obj, '', that.data.page);
- }else{
- initCate(that, '', that.data.page);
- }
- },
- onPullDownRefresh: function () {
- //下拉
- console.log(123)
- var that = this;
- if (that.data.id == 0) {
- var obj = { 'is_hot': 0, 'is_new': 1 };
- utils.initList(that, obj, 'top', that.data.page);
- } else {
- initCate(that, 'top', ++that.data.page);
- }
- },
- onReachBottom: function () {
- //上拉
- console.log('text')
- var that = this;
- if (that.data.id == 0) {
- var obj = { 'is_hot': 0, 'is_new': 1 };
- utils.initList(that, obj, '', that.data.page);
- } else {
- initCate(that, '', ++that.data.page);
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
- // 请求列表数据
- var initCate = function (that, orient, page) {
- that.setData({ hidden: false });
- var list = [];
- if (page == 1) {
- list = [];
- } else {
- list = that.data.dataList
- }
- wx.request({
- url: 'http://m.henhaojie.com/user/product/getInfoByCat',
- method: "POST",
- data: { id: that.data.id, page: page},
- success: function (res) {
- var data = res.data.rst.data;
- if (res.data.errno == '0') {
- that.data.hasNext = res.data.rst.pageinfo.hasNext
- console.log(that.data.hasNext)
- for (var i = 0; i < data.length; i++) {
- if (orient == 'top') {
- list.unshift(data[i]);
- } else {
- list.push(data[i]);
- }
- }
- that.setData({ dataList: list });
- }
- },
- complete: function () {
- // complete
- that.setData({ hidden: true });//加载成功
- wx.stopPullDownRefresh() //停止下拉刷新
- }
- });
- }
|