|
- const Http = require("../../utils/HttpBasics");
- const config = require("../../config/config");
- let app = getApp();
- Page({
- data: {
- market: app.globalData.market,
- list: [],
- swiperCurrent: 0,
- scrollTop: 0,
- page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
- },
- swiperChange: function(e) {
- this.setData({
- swiperCurrent: e.detail.current
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onLoad: function(options) {
- var that = this;
- var scene = decodeURIComponent(options.scene);
- },
-
- onShow:function(){
- let that = this;
- if (app.globalData.token && app.globalData.token != null) {
- } else {
- wx.login({
- success: ({ code }) => {
- console.log(code);
- Http.post({
- url: config.api.login,
- data: {
- appId: config.weapp.AppId,
- code: code,
- sceneAddress: app.globalData.sceneAddress
- }
- }).then(res => {
- //banner渲染
- app.globalData.token = res.data.token;
- Http.setToken(res.data.token);
- if (res.code == 200) {
- Http.get({
- url: config.api.bannerlist,
- data: {
- pageNum: 1,
- pageSize: 10
- }
- }).then(res => {
- that.setData({
- list: res.data.list
- });
- });
- }
- });
- }
- });
- }
- },
-
- onGetCode: function(e) {
- //子组件传递给父组件的值
- this.setData({
- code: e.detail.val,
- page: e.detail.pageNum
- });
- },
-
-
- //下拉加载更多
- onReachBottom: function() {
- let that = this;
- console.info("before++ " + that.data.page);
- that.data.page++;
- console.info("after++ " + that.data.page);
- that.setData({
- page: that.data.page
- });
- //父组件获得子组件的方法
- //如果code == 0
- if (that.data.code == 0 || that.data.code == undefined) {
- that.selectComponent("#lists").getList(0, that.data.page);
- } else {
- that.selectComponent("#lists").getList(that.data.code, that.data.page);
- }
- },
- // 用户点击右上角分享
- onShareAppMessage: function() {
- return {
- title: "富茂链客",
- desc: "分享个小程序,希望你喜欢",
- success: function(res) {
- wx.showToast({
- title: "分享成功",
- duration: 1000,
- icon: "success"
- });
- }
- };
- }
- });
|