import {
|
collectLikePage
|
} from '../../api/index'
|
import {
|
eventBus
|
} from '../../utils/eventBus'
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
activeTabs: 'product_intro',
|
|
dataList: [],
|
total: 0,
|
pageNum: 1,
|
pageSize: 10,
|
},
|
onLoad(options) {
|
this.getList()
|
},
|
onShow() {
|
const dataList = this.data.dataList
|
eventBus.once('caseDeBack', (info) => {
|
const temp = dataList.filter(item => {
|
if (item.id === info.id) {
|
item.isCollection = info.isCollection
|
item.viewCount++
|
}
|
if(item.isCollection) return item
|
})
|
this.setData({ dataList: temp})
|
})
|
eventBus.once('productDeBack', (info) => {
|
const temp = dataList.filter(item => {
|
if (item.id === info.id) {
|
item.isCollection = info.isCollection
|
item.viewCount++
|
}
|
if(item.isCollection) return item
|
})
|
this.setData({ dataList: temp})
|
})
|
eventBus.once('realpicDeBack', (info) => {
|
const temp = dataList.filter(item => {
|
if (item.id === info.id) {
|
item.isCollection = info.isCollection
|
item.viewCount++
|
}
|
if(item.isCollection) return item
|
})
|
this.setData({ dataList: temp})
|
})
|
},
|
onPullDownRefresh: function () {
|
console.log('下拉刷新');
|
this.setData({ dataList: [], pageNum: 1, total: 0 })
|
wx.stopPullDownRefresh()
|
this.getList()
|
},
|
onReachBottom() {
|
console.log('触底事件');
|
const { total, dataList, pageNum } = this.data
|
if(total > dataList.length){
|
this.setData({ pageNum: pageNum + 1 })
|
this.getList()
|
}else{
|
wx.showToast({
|
title: '暂无更多数据',
|
icon: 'none'
|
})
|
}
|
},
|
tabsChange(e) {
|
const activeTabs = e.currentTarget.dataset.val
|
this.setData({
|
activeTabs,
|
dataList: [],total: 0,pageNum: 1
|
})
|
this.getList()
|
},
|
handleDetail(e) {
|
const id = e.currentTarget.dataset.id
|
const { activeTabs } = this.data
|
let url = ''
|
if(activeTabs == 'product_intro'){
|
url = '/pages/detailDis/product'
|
}else if(activeTabs == 'whole_case'){
|
url = '/pages/detailDis/case'
|
}else{
|
url = '/pages/detailDis/realpic'
|
}
|
wx.navigateTo({
|
url: `${url}?id=${id}`,
|
})
|
},
|
getList() {
|
const {
|
pageSize,
|
pageNum,
|
activeTabs
|
} = this.data
|
collectLikePage({
|
businessCategory: 'like',
|
businessType: activeTabs,
|
pageSize,
|
pageNum
|
}).then(res => {
|
if (res.data) {
|
this.setData({
|
dataList: [...this.data.dataList, ...res.data.records || []],
|
total: res.data.total
|
})
|
}
|
})
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady() {
|
|
},
|
onHide() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload() {
|
|
},
|
onShareAppMessage() {
|
|
}
|
})
|