//index.js //获取应用实例 const app = getApp() var util = require('../../utils/util.js'); var api = require('../../utils/service-api.js'); var comReq = require('../../utils/common-request.js'); Page({ data: { adNodes: [], distance: 0, size: 30, step: 1, interval: 20, }, onLoad: function(options) { util.userLogin(function() { console.log("登录成功"); }); //获取首页所有的节点元素 this.getAdNodes(); //获取小程序码中的店铺id if (options.scene) { const shopId = decodeURIComponent(options.scene); //获取门店信息 util.request({ api: api.yuyue.findShopInfoById + "/" + shopId, callback: function (data) { app.shopInfo = data.mapInfo.shopInfo; wx.setNavigationBarTitle({ title: app.shopInfo.shopShortName }); }, checkLogin: true, }); } }, onShow: function() { wx.setNavigationBarTitle({ title: app.shopInfo.shopShortName }); }, changeShop() { wx.navigateTo({ url: "/pages/yuyue/choseShop", }); }, getAdNodes: function() { console.log('加载广告'); var _this = this; util.request({ method: 'POST', api: api.ad.getAdPage, data: { "pageCode": "index", }, callback: function(data) { let hasPmd = false; for (let i = 0; i < data.rows.length; i++) { let node = data.rows[i]; //处理属性节点 console.log(node.nodeAttribute); if (node.nodeAttribute != null) { node.nodeAttribute = JSON.parse(node.nodeAttribute); } if (node.nodeType == 5) { //处理跑马灯,一个页面只支持一个跑马灯 var length = node.nodeValue.length * _this.data.size; _this.setData({ length: length }); hasPmd = true; } } _this.setData({ adNodes: data.rows }); if (hasPmd) { _this.scrollling(); } } }); }, /** * 点击广告节点事件 */ clickAdnode(e) { var linkType = e.currentTarget.dataset.linktype; var linkUrl = e.currentTarget.dataset.linkurl; if (linkType == 1) { wx.switchTab({ url: linkUrl, fail: function(e) { console.log(e); }, }); } else if (linkType == 2) { wx.navigateTo({ url: linkUrl, }) } else if (linkType == 3) { wx.navigateTo({ url: "/pages/webView/webView?url=" + linkUrl, }) } }, scrollling: function() { var that = this; var interval = setInterval(function() { var maxscrollwidth = that.data.length; var left = that.data.distance; if (maxscrollwidth + left > 1) { that.setData({ distance: left - that.data.step }) } else { that.setData({ distance: 0 }); clearInterval(interval); that.scrollling(); } }, that.data.interval); }, setShopTitle() { wx.setNavigationBarTitle({ title: app.shopInfo.shopName }); }, //转发 onShareAppMessage(res) { }, })