95 lines
2.4 KiB
JavaScript
95 lines
2.4 KiB
JavaScript
// packageB/mycomponent/videoList.js
|
|
var colOneHeight = 0;
|
|
var colTwoHeight = 0;
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
goodsData: {
|
|
type: null
|
|
},
|
|
cardid:{
|
|
type: null
|
|
}
|
|
},
|
|
lifetimes: {
|
|
attached: function () {
|
|
// 在组件实例进入页面节点树时执行
|
|
colOneHeight = 0;
|
|
colTwoHeight = 0;
|
|
},
|
|
},
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
activitys1: [],
|
|
activitys2: [],
|
|
showLoading: false,
|
|
imgCount: 0
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
toVideo(e) {
|
|
let item = e.currentTarget.dataset.item;
|
|
let page = this.data.goodsData.findIndex((value, index, arr) => {
|
|
return value.id === item.id;
|
|
});
|
|
page = Math.ceil((page + 1) / 15);
|
|
wx.navigateTo({
|
|
url: '/packageC/video_goods/VideoDetail/VideoDetail?vid=' + item.id + '&page=' + page + "&from=card"+'&card_id='+this.data.cardid
|
|
});
|
|
},
|
|
/**
|
|
* 图片加载函数
|
|
* 图片加载完成后,根据图片的高度,依次往第一列和第二列中推入数据
|
|
*/
|
|
onImageLoad(options) {
|
|
console.log(options);
|
|
console.log(this.data);
|
|
let currentId = options.currentTarget.id;
|
|
let imageWidth = options.detail.width; // 图片宽度
|
|
let imageHeight = options.detail.height; // 图片高度
|
|
|
|
let activitys = this.data.goodsData; // 获取所有的数据资源
|
|
let activityObj = null;
|
|
let scle = (imageWidth / imageHeight);
|
|
console.log(this.data.allData);
|
|
for (let i = 0; i < activitys.length; i++) {
|
|
if (activitys[i].id == currentId) {
|
|
activityObj = activitys[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
this.data.imgCount += 1;
|
|
let activitys1 = this.data.activitys1;
|
|
let activitys2 = this.data.activitys2;
|
|
|
|
if (colOneHeight <= colTwoHeight) {
|
|
colOneHeight += (176 / scle) + 60;
|
|
activitys1.push(activityObj);
|
|
} else {
|
|
colTwoHeight += (176 / scle) + 60;
|
|
activitys2.push(activityObj);
|
|
}
|
|
|
|
let data = {
|
|
activitys1: activitys1,
|
|
activitys2: activitys2
|
|
};
|
|
console.log(this.data.imgCount, this.data.goodsData.length);
|
|
if (this.data.imgCount >= this.data.goodsData.length) {
|
|
this.setData({
|
|
showLoading: true
|
|
});
|
|
}
|
|
|
|
this.setData(data);
|
|
},
|
|
}
|
|
}); |