// pages/message/index.js import { getFactoryPrice, 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, kg: app.globalData.kg, firstShow: false, noticeList: [], tabList: [ '推荐', '关注', '全部' , '资讯'], tabIndex: 0, }, lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 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, tabIndex: 0, firstShow: true }) this.fetchAgentList() } this.data.firstShow = true if(!this.data.noticeList.length){ this.fetchNoticeList() } }, onEvent: function (message) { console.log('mall>>index>>onEvent', message) if (message.what == 10 && app.globalData.isVIP == 1) { // this.setData({ token: app.globalData.token }) // this.onRefreshList() } else if(message.what == 1001){ this.setData({ kg: app.globalData.kg }) } else if(message.what == 888){ this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false }) this.fetchAgentList() } else if(message.what == 444){ this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false, cityName: app.nowLocation.cityName }) this.fetchAgentList() } }, chooseCity: function(){ wx.navigateTo({url: `/pages/home/city-select/index?type=1` }) }, searchList: function(){ }, postList: function(){ }, onTabChange: function({detail}){ if(this.data.tabIndex == Number(detail.index)){ return } this.fetchAgentList() }, 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 }) }, //*************************************************fetchAgentList************************************************// fetchAgentList: function () { if (this.data.requesting || this.data.finished) { return } if (this.data.loading) { this.data.requesting = true } else { this.setData({ requesting: true }) } getFactoryPrice(this.data.form).then(result => { if (result.data.records.length) { var respList = result.data.records let nowList = `orderList[${this.data.orderList.length}]` var num = result.data.current var finished = result.data.current >= result.data.pages this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false }) } else { this.setData({ requesting: false, finished: true, loading: false }) } }).catch(err => { //异常回调 this.setData({ requesting: false, finished: true, loading: false }) }) } } })