You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.0 KiB
83 lines
2.0 KiB
5 years ago
|
Component({
|
||
|
data: {
|
||
|
selectBarLeft: 0,
|
||
|
newsCategoryId: ''
|
||
|
},
|
||
|
properties: {
|
||
|
newsCategoryList: {
|
||
|
type: Array,
|
||
|
value: [],
|
||
|
observer: function (value) {
|
||
|
if (value.length > 0) {
|
||
|
const _this = this
|
||
|
const query = wx.createSelectorQuery().in(this)
|
||
|
query.select('#item1').boundingClientRect()
|
||
|
query.exec(function(res){
|
||
|
_this.setData({
|
||
|
selectBarLeft: res[0].width/2
|
||
|
})
|
||
|
console.log(_this.data.selectBarLeft)
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
newsList: {
|
||
|
type: Array,
|
||
|
value: []
|
||
|
},
|
||
|
preloadVisible: {
|
||
|
type: Boolean,
|
||
|
value: true
|
||
|
}
|
||
|
},
|
||
|
lifetimes: {
|
||
|
created () {
|
||
|
console.log('组件实例创建--created')
|
||
|
},
|
||
|
attached () {
|
||
|
|
||
|
},
|
||
|
detached () {
|
||
|
console.log('从父组件中移除-detached')
|
||
|
}
|
||
|
},
|
||
|
pageLifetimes: {
|
||
|
show () {
|
||
|
|
||
|
},
|
||
|
hide () {
|
||
|
console.log('页面隐藏')
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
// 分类导航切换
|
||
|
onChangeClassifyTab (e) {
|
||
|
this.data.newsCategoryList.forEach((item, index) => {
|
||
|
if (index === e.currentTarget.dataset.tab) {
|
||
|
this.data.newsCategoryId = item.value
|
||
|
item.select = true
|
||
|
const _this = this
|
||
|
const query = wx.createSelectorQuery().in(this)
|
||
|
query.select(`#item${index + 1}`).boundingClientRect()
|
||
|
query.exec(function(res){
|
||
|
_this.setData({
|
||
|
selectBarLeft: res[0].width/2
|
||
|
})
|
||
|
console.log(_this.data.selectBarLeft)
|
||
|
})
|
||
|
} else {
|
||
|
item.select = false
|
||
|
}
|
||
|
})
|
||
|
this.setData({
|
||
|
newsCategoryList: this.data.newsCategoryList
|
||
|
})
|
||
|
this.triggerEvent('newsCategoryCallback', { newsCategoryId: this.data.newsCategoryId })
|
||
|
},
|
||
|
toDetail (e) {
|
||
|
wx.navigateTo({
|
||
|
url: `/subpages/oneKeyService/pages/noticeDetail/noticeDetail?id=${e.currentTarget.dataset.id}&title=${e.currentTarget.dataset.title}`
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|