//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) {
|
|
var pageCode=options.pageCode;
|
if(pageCode){
|
this.getAdNodes(pageCode);
|
}else{
|
wx.showToast({
|
title: '页面加载失败',
|
});
|
}
|
},
|
|
|
|
|
|
|
onShow: function() {
|
|
|
},
|
|
getAdNodes: function(pageCode) {
|
console.log('加载广告');
|
var _this = this;
|
util.request({
|
method: 'POST',
|
api: api.ad.getAdPage,
|
data: {
|
"pageCode": pageCode,
|
},
|
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) {
|
|
},
|
|
|
|
})
|