// pages/message/index.js import { getSuccessNotices } from "../../../api/ztb" const event = require('../../../utils/event') const util = require('../../../utils/util') const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, properties:{ cityName: { //这个是可以自定义最外层的view的样式 type: String, value: '' } }, /** * 页面的初始数据 */ data: { height: app.globalData.safeFragmentHeight - 270, safeBottom: app.globalData.safeBottom, kg: app.globalData.kg, firstShow: false, noticeList: [], tabList: [ '推荐', '关注', '全部' , '资讯'], tabIndex: 0, }, lifetimes: { attached: function () { event.on('EventMessage', this, this.onEvent) }, detached: function () { event.remove('EventMessage', this) } }, methods: { onRestart: function () { if(!this.data.firstShow){ this.setData({ height: app.globalData.safeFragmentHeight - 270, StatusBar: app.globalData.StatusBar || 40, customHeight: app.globalData.customHeight, safeBottom: app.globalData.safeBottom, tabIndex: 0, firstShow: true }) } this.data.firstShow = true if(!this.data.noticeList.length){ this.fetchNoticeList() } this.onResume() }, onEvent: function (message) { if (message.what == 10 && app.globalData.isVIP == 1) { // this.setData({ token: app.globalData.token }) // this.onRefreshList() } else if(message.what == 888){ } else if(message.what == 444){ this.setData({ cityName: app.nowCity.cityName }) } else if(message.what == 124){ this.onTabChange({detail: { index: 3}}) } }, chooseCalendar: function(){ this.triggerEvent("picker", {type: 1}) }, onCalendarChange: function(date){ var fragment = this.selectComponent('#recommend') if(fragment && fragment.calendarChange){ fragment.calendarChange(date) } }, chooseCity: function(){ wx.navigateTo({url: `/pages/home/city-select/index?type=1` }) }, feedback: function(){ util.navigateTo('/pages/article/feedback/index') }, searchList: function(){ var tab = this.data.tabIndex == 3 ? 3 : 1 util.navigateTo(`/pages/mall/search-list/index?tab=${tab}`) }, onTabChange: function({detail}){ if(this.data.tabIndex == Number(detail.index)){ return } this.setData({ tabIndex: Number(detail.index) }) this.onResume() }, fetchNoticeList: function(){ if (this.data.loopRequesting) { return } this.data.loopRequesting = true getSuccessNotices().then(result => { this.data.loopRequesting = false this.data.noticeList = [] if(result.data && result.data.length){ for (let index = 0; index < result.data.length; index++) { this.data.noticeList.push(result.data[index].msg) } this.setData({noticeList: this.data.noticeList}) } }).catch(err => { this.data.loopRequesting = false }) }, toNotice: function(e){ var item = this.data.noticeList[e.currentTarget.dataset.index] console.log(item) }, onResume: function(){ var fragment = null if(this.data.tabIndex == 0){ fragment = this.selectComponent('#recommend') } else if(this.data.tabIndex == 1){ fragment = this.selectComponent('#attention') } else if(this.data.tabIndex == 2){ fragment = this.selectComponent('#theall') } else if(this.data.tabIndex == 3){ fragment = this.selectComponent('#information') } if (fragment && fragment.onRestart) { fragment.onRestart() } } } })