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.
175 lines
5.8 KiB
175 lines
5.8 KiB
// pages/message/index.js
|
|
import { getMessageNumber, getBannerList } from "../../../api/ztb"
|
|
import { getCategoryType, getPreferList, getMomentList } from "../../../api/moment"
|
|
const event = require('../../../utils/event')
|
|
const storage = require('../../../utils/storage')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
var form = {sortBy: 0, pageNum: 10, pageSize: 1, categoryId: '', cityId: ''}
|
|
var typeList = []
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
properties:{
|
|
cityName: { type: String, value: '' },
|
|
height: { type: Number, value: 0 },
|
|
customHeight: { type: Number, value: 0 },
|
|
StatusBar: { type: Number, value: 0 },
|
|
customWidth: { type: Number, value: 0 }
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
firstShow: false,
|
|
bannerList: [],
|
|
momentList: [],
|
|
tabList: [],
|
|
tabIndex: 0,
|
|
requesting: true,
|
|
orderList: [],
|
|
popover: false,
|
|
sortList: [
|
|
{sort: 0, text: '更新时间'},
|
|
{sort: 1, text: '价格升序'},
|
|
{sort: 2, text: '价格降序'},
|
|
{sort: 3, text: '排队升序'},
|
|
{sort: 4, text: '排队降序'}
|
|
],
|
|
sortIndex: 0,
|
|
messageNumber: 0
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if(!this.data.firstShow){
|
|
getPreferList().then(result => {
|
|
this.setData({ momentList: result.data.records.slice(0, 3) })
|
|
})
|
|
getCategoryType().then(result => {
|
|
typeList = result.data
|
|
var tabList = []
|
|
for (let index = 0; index < typeList.length; index++) {
|
|
tabList.push(typeList[index].categoryName)
|
|
}
|
|
form.categoryId = typeList[0].categoryId
|
|
this.setData({ tabList })
|
|
})
|
|
}
|
|
this.initLogin()
|
|
this.data.firstShow = true
|
|
var bannerstring = storage.get('ztb-banner-list')
|
|
if(!util.isEmpty(bannerstring)){
|
|
this.setData({ bannerList: JSON.parse(bannerstring) })
|
|
}
|
|
if(!this.data.bannerList.length){
|
|
getBannerList(1).then(result => {
|
|
this.setData({ bannerList: result.data })
|
|
storage.put('ztb-banner-list', JSON.stringify(result.data))
|
|
})
|
|
}
|
|
},
|
|
onEvent: function (message) {
|
|
if(!this.data.firstShow){
|
|
return
|
|
}
|
|
console.log('mall>>fragment>>onEvent', message)
|
|
if(message.what == 888){
|
|
this.initLogin()
|
|
} else if(message.what == 444){
|
|
form.cityId = app.nowCity.cityCode
|
|
this.setData({ cityName: app.nowCity.cityName })
|
|
this.fetchAgentList()
|
|
}
|
|
},
|
|
initLogin: function(){
|
|
if(app.globalData.userInfo){
|
|
getMessageNumber().then(result => {
|
|
this.setData({ messageNumber: result.data.messageNumber + result.data.notificationNumber })
|
|
})
|
|
}
|
|
},
|
|
postInfo: function(e){
|
|
var item = this.data.momentList[e.currentTarget.dataset.index]
|
|
wx.navigateTo({ url: '/pages/article/detail/index?id=' + item.id })
|
|
},
|
|
gridTap: function(e){
|
|
if(e.currentTarget.id == 'agent'){
|
|
this.triggerEvent("click", { what: 2 })
|
|
} else if(e.currentTarget.id == 'trans'){
|
|
util.navigateTo('/submodel/pages/paper/index/index')
|
|
} else if(e.currentTarget.id == 'action'){
|
|
util.navigateTo(`/pages/agent/ability/index`)
|
|
} else if(e.currentTarget.id == 'moment'){
|
|
this.triggerEvent("click", { what: 1 })
|
|
} else if(e.currentTarget.id == 'info'){
|
|
this.triggerEvent("click", { what: 1, index: 3 })
|
|
event.emit('EventMessage', { what: 124, desc: 'morepost' })
|
|
} else if(e.currentTarget.id == 'city'){
|
|
wx.navigateTo({url: `/pages/home/city-select/index?type=1` })
|
|
} else if(e.currentTarget.id == 'message'){
|
|
util.navigateTo('/pages/html/message/index')
|
|
} else if(e.currentTarget.id == 'search'){
|
|
wx.navigateTo({url: `/pages/mall/search-list/index?tab=1` })
|
|
}
|
|
},
|
|
tapBanner: function(e){
|
|
var item = this.data.bannerList[e.currentTarget.dataset.index]
|
|
if(item.redirectInfo.targetView == 'showH5'){
|
|
util.navigateTo('/pages/html/html/index?link=' + item.redirectInfo.params.id + '?title=' + item.title)
|
|
return
|
|
}
|
|
util.navigateTarget(item.redirectInfo)
|
|
},
|
|
onTabChange: function({detail}){
|
|
if(this.data.tabIndex == Number(detail.index)){
|
|
return
|
|
}
|
|
this.data.tabIndex = Number(detail.index)
|
|
form.categoryId = typeList[Number(detail.index)].categoryId
|
|
this.fetchAgentList()
|
|
},
|
|
topBubble: function(e){
|
|
if(this.data.sortIndex == Number(e.currentTarget.dataset.index)){
|
|
this.setData({ popover: !this.data.popover })
|
|
return
|
|
}
|
|
if(!util.isEmpty(e.currentTarget.dataset.index)){
|
|
this.data.sortIndex = Number(e.currentTarget.dataset.index)
|
|
if(this.data.popover){
|
|
form.sortBy = this.data.sortIndex
|
|
this.fetchAgentList()
|
|
}
|
|
}
|
|
this.setData({ popover: !this.data.popover, sortIndex: this.data.sortIndex })
|
|
},
|
|
//*************************************************fetchAgentList************************************************//
|
|
fetchAgentList: function () {
|
|
if(util.isEmpty(form.categoryId)){
|
|
return
|
|
}
|
|
this.setData({ requesting: true, orderList: [] })
|
|
getMomentList(form).then(result => {
|
|
if (result.data.records.length) {
|
|
this.setData({ orderList: result.data.records, requesting: false })
|
|
} else {
|
|
this.setData({ requesting: false })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false })
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|