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.
119 lines
3.7 KiB
119 lines
3.7 KiB
// pages/message/index.js
|
|
import { getInformationList } from "../../../api/moment"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
properties: {
|
|
height: { type: Number, value: 0 }
|
|
},
|
|
data: {
|
|
form: {
|
|
byQueryType: 0,
|
|
pageNum: 1,
|
|
pageSize: 10
|
|
},
|
|
loading: false,
|
|
requesting: false,
|
|
token: true,
|
|
finished: false,
|
|
dataIndex: 0,
|
|
orderList: []
|
|
},
|
|
lifetimes: {
|
|
attached: function () {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if(!this.firstShow){
|
|
var min = new Date()
|
|
min.setHours(0, 0, 0)
|
|
this.data.token = app.globalData.userInfo ? true : false
|
|
this.data.form.date = util.formatDate(min, 'Y-M-D')
|
|
if(app.nowCity){
|
|
this.data.form.cityId = app.nowCity.cityCode
|
|
}
|
|
this.fetchList()
|
|
}
|
|
this.firstShow = true
|
|
},
|
|
onEvent: function (message) {
|
|
if(message.what == 888){
|
|
this.setData({ token: app.globalData.userInfo ? true : false })
|
|
} else if(message.what == 444 && this.firstShow){
|
|
this.data.form.cityId = app.nowCity.cityCode
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
calendarChange: function(date){
|
|
this.data.form.date = date
|
|
this.onRefreshList()
|
|
},
|
|
onRefreshList: function(){
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.data.dataIndex = 0
|
|
this.setData({ orderList: [], ['form.pageNum']: 1, finished: false, loading: true })
|
|
this.fetchList()
|
|
},
|
|
fetchList: function(){
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.data.requesting = true
|
|
getInformationList(this.data.form).then(result => {
|
|
if (result.data && result.data.records.length) {
|
|
var respList = result.data.records
|
|
var lastTime = null
|
|
if(this.data.dataIndex < 2){
|
|
// 对返回的消息列表进行处理,将同一天的消息显示在一起
|
|
var qrtime = new Date(this.data.form.date).getTime()
|
|
for (let i = 0; i < respList.length; i++) {
|
|
if(this.data.dataIndex == 2){
|
|
continue
|
|
}
|
|
lastTime = respList[i].latestQuoteTime
|
|
if (lastTime.length > 10) {
|
|
lastTime = lastTime.substring(0, 10)
|
|
}
|
|
var itemtime = new Date(lastTime).getTime()
|
|
if(this.data.dataIndex == 0){
|
|
if(itemtime > qrtime){
|
|
this.data.dataIndex = 1
|
|
respList[i].tipsTime = lastTime
|
|
} else {
|
|
this.data.dataIndex = 2
|
|
respList[i].tipsTime = this.data.form.date
|
|
}
|
|
} else if(this.data.dataIndex == 1 && itemtime <= qrtime){
|
|
this.data.dataIndex = 2
|
|
respList[i].tipsTime = this.data.form.date
|
|
}
|
|
}
|
|
}
|
|
let nowList = `orderList[${this.data.orderList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false, token: this.data.token })
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false, token: this.data.token })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false, token: this.data.token })
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|