123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- const getReq = require('./../../config.js').getReq;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- special_datas: {},
- summery: [],
- hasmore:false,
- curpage:1,
- brand_id : '',
- hot_id:'',
- keyword:''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.setNavigationBarTitle({
- title: options.title ? options.title : "熊猫美妆"
- })
- wx.showLoading({
- title: '加载中',
- });
- const brand_id = options.brand_id ? options.brand_id : '';
- const hot_id = options.hot_id ? options.hot_id : '';
- const keyword = options.keyword ? options.keyword : '';
- const curpage = this.data.curpage;
- this.setData({
- hot_id,
- brand_id,
- keyword
- })
- let self = this;
- getReq({
- act: 'search',
- op: 'index',
- brand_id,
- hot_id,
- keyword,
- curpage
- }, function (res) {
- if (res.code == 200) {
- self.setData({
- special_datas: res.datas,
- summery: res.datas.summary,
- hasmore: res.datas.mobile_page.hasmore
- });
- wx.hideLoading();
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- if(this.data.hasmore) {
- wx.showLoading({
- title: '加载中',
- });
- let self = this;
- getReq({
- act: 'search',
- op: 'index',
- brand_id: this.data.brand_id,
- hot_id: this.data.hot_id,
- keyword: this.data.keyword,
- curpage: this.data.curpage+1
- }, function (res) {
- if (res.code == 200) {
- let newDatas = res.datas;
- let newSummery = res.datas.summary;
- let oldDatas = self.data.special_datas;
- let oldSummery = self.data.summery;
-
- let buildDatas = (function(){
- let buildDatas = {};
- for (let i in oldDatas) {
- if (oldDatas[i] instanceof Array) {
- buildDatas[i] = oldDatas[i].concat(newDatas[i]);
- }
- }
- return buildDatas;
- })();
- let buildSummery = (function(){
- let buildDatas = [];
- buildDatas = oldSummery.concat(newSummery);
- return buildDatas;
- })();
- self.setData({
- curpage: self.data.curpage+1,
- special_datas: buildDatas,
- summery: buildSummery,
- hasmore: res.datas.mobile_page.hasmore
- });
- wx.hideLoading();
- }
- })
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|