// packageB/mycomponent/videoList.js Component({ /** * 组件的属性列表 */ properties: { goodsData: { type: null, }, cardid: { type: null, }, }, lifetimes: { attached: function () { // 在组件实例进入页面节点树时执行 }, }, /** * 组件的初始数据 */ data: { activitys1: [], activitys2: [], showLoading: true, imgCount: 0, colOneHeight:0, colTwoHeight: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) / 12); if (this.data.cardid) { wx.navigateTo({ url: "/packageC/video_goods/VideoDetail/VideoDetail?vid=" + item.id + "&page=" + page + "&from=card" + "&card_id=" + this.data.cardid, }); } else { wx.navigateTo({ url: "/packageC/video_goods/VideoDetail/VideoDetail?vid=" + item.id, }); } }, /** * 图片加载函数 * 图片加载完成后,根据图片的高度,依次往第一列和第二列中推入数据 */ onImageLoad(options) { // console.log(options,'aaaaaaaaaa') this.setData({ showLoading: false, }); // console.log(this.data.showLoading,'aaaaaaaaaa') 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; for (let i = 0; i < activitys.length; i++) { if (activitys[i].id == currentId) { activityObj = activitys[i]; break; } } let {colTwoHeight,colOneHeight} = this.data; this.data.imgCount += 1; let activitys1 = this.data.activitys1; let activitys2 = this.data.activitys2; if (colOneHeight <= colTwoHeight) { this.data.colOneHeight += 176 / scle + 60; activitys1.push(activityObj); } else { this.data.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); }, }, });