properties: {
list: Array
},
data: {
spList: [],
spArr_lf: [],
lfHieight: 0,
spArr_rt: [],
rtHieight: 100,
},
observers: {
'list': function (list) {
if (list.length != 0) {
this.setData({
spList: list,
spArr_lf: [],
lfHieight: 0,
spArr_rt: [],
rtHieight: 100,
})
this.spImgW_H()
}
}
},
methods: {
spImgW_H() {
let that=this
let list = this.data.spList
list.forEach((value, i) => {
let img = value.picUrl
let num = i
wx.getImageInfo({
src: img,
success(res) {
list[num].width = res.width
list[num].height = res.height
that.setData({
spList: list
})
if (num == parseInt(list.length) - 1) {
that.spArr()
}
}
})
});
},
//瀑布流计算
spArr() {
let that=this
console.log(2)
let spArr_lf = this.data.spArr_lf
let lfHieight = this.data.lfHieight
let spArr_rt = this.data.spArr_rt
let rtHieight = this.data.rtHieight
let list = this.data.spList
list.forEach((value, i) => {
let height
if (value.width) {
height = 175.6 / parseInt(value.width) * parseInt(value.height);
} else {
height = 150 ;
}
console.log('height:',height)
if (lfHieight <= rtHieight) {
spArr_lf.push(value)
lfHieight = lfHieight + height
} else if (lfHieight > rtHieight) {
spArr_rt.push(value)
rtHieight = rtHieight + height
}
})
console.log('lfHieight:',lfHieight+'++++','rtHieight:',rtHieight)
this.setData({
spArr_lf: spArr_lf,
lfHieight: lfHieight,
spArr_rt: spArr_rt,
rtHieight: rtHieight,
})
},