纸通宝小程序
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.
 

169 lines
5.6 KiB

// pages/message/index.js
import { getInformationList } from "../../../api/moment"
const event = require('../../../utils/event')
const util = require('../../../utils/util')
const math = require('../../../utils/math')
const app = getApp()
const list = [ '推荐', '关注', '全部' , '行情']
var params = {byQueryType: 2, pageNum: 1}
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 },
safeBottom: { type: Number, value: 0 },
customWidth: { type: Number, value: 0 }
},
/**
* 页面的初始数据
*/
data: {
firstShow: false,
noticeList: [],
tabList: [ '推荐', '关注', '全部' , '行情'],
tabIndex: 0,
mHeight: 0,
},
lifetimes: {
attached: function () {
event.on('EventMessage', this, this.onEvent)
},
detached: function () {
event.remove('EventMessage', this)
}
},
methods: {
onRestart: function () {
if(!this.data.firstShow){
setTimeout(() => {
this.setData({ tabIndex: this.data.tabIndex, tabList: list, mHeight: this.data.height - 87 - this.data.customHeight })
}, 100)
params.date = util.formatDate(new Date(), 'Y-M-D')
}
this.data.firstShow = true
if(!this.data.noticeList.length){
this.fetchNoticeList()
}
this.onResume()
},
onEvent: function (message) {
if(!this.data.firstShow){
return
}
console.log('moment>>fragment>>onEvent', 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)
}
fragment = this.selectComponent('#theall')
if(fragment && fragment.calendarChange){
fragment.calendarChange(date)
}
},
chooseCity: function(){
wx.navigateTo({url: `/pages/home/city-select/index?type=1` })
},
feedback: function(){
if(this.data.tabIndex == 3){
util.navigateTo('/pages/article/list/index')
} else {
util.navigateTo('/pages/article/feedback/index')
}
},
postMoment: function () {
util.navigateTo('/pages/article/publish/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
getInformationList(params).then(result => {
this.data.loopRequesting = false
this.data.noticeList = []
if(result.data && result.data.records.length){
for (let index = 0; index < result.data.records.length; index++) {
this.handResult(result.data.records[index])
}
if(this.data.noticeList.length > 0){
this.data.mHeight = this.data.height - 167 - this.data.customHeight
} else {
this.data.mHeight = this.data.height - 87 - this.data.customHeight
}
this.setData({noticeList: this.data.noticeList, mHeight: this.data.mHeight})
}
}).catch(err => {
this.setData({noticeList: this.data.noticeList, mHeight: this.data.height - 87 - this.data.customHeight})
this.data.loopRequesting = false
})
},
handResult: function(record){
console.log(params.data)
if(record.latestQuoteTime.indexOf(params.date) < 0){
return
}
if(util.isEmpty(record.typicalFloatingQuotedPrice) || record.typicalFloatingQuotedPrice == 0){
return
}
if(record.typicalFloatingQuotedPrice > 0){
record.content = record.paperMillName + '上涨' + math.times(record.typicalFloatingQuotedPrice, 1000) + '元/吨'
} else if(record.typicalFloatingQuotedPrice < 0){
record.content = record.paperMillName + '下降' + math.times(-record.typicalFloatingQuotedPrice, 1000) + '元/吨'
} else if(record.typicalFloatingQuotedPrice == 0){
record.content = record.paperMillName + '最新收购价格:' + math.times(record.typicalFloatingQuotedPrice, 1000) + '元/吨'
}
this.data.noticeList.push(record)
},
toNotice: function(e){
var item = this.data.noticeList[e.currentTarget.dataset.index]
util.navigateTo('/pages/agent/factory/index?id=' + item.paperMillId)
},
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()
}
}
}
})