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.
248 lines
8.7 KiB
248 lines
8.7 KiB
import { getFactoryPrice, getProxyOrderList } from "../../../api/ztb"
|
|
import { getPreferList, getInformationList } from "../../../api/moment"
|
|
const storage = require('../../../utils/storage')
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event')
|
|
const tdsdk = require('../../../libs/tdweapp.js')
|
|
const app = getApp()
|
|
const limit = 8
|
|
var rearchStringList = []
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.fragmentHeight - 100,
|
|
focus: true,
|
|
keyIndex: 0, // 0: 总数少于limit,不显示;1:总数大于limit,只显示limit个,箭头向下;2:总数大于limit,全部显示,箭头向上
|
|
searchList: [],
|
|
tabList: [ '交易', '行情', '订单' , '资讯'],
|
|
tabIndex: 0,
|
|
form: {
|
|
searchKey: '',
|
|
pageSize: 10,
|
|
pageNum: 1
|
|
},
|
|
loading: false,
|
|
requesting: false,
|
|
finished: false,
|
|
dataIndex: 0,
|
|
taskList: [],
|
|
visible: false
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if(options.tab) {
|
|
this.data.tabIndex = Number(options.tab)
|
|
}
|
|
var min = new Date()
|
|
min.setHours(0, 0, 0)
|
|
this.data.form.date = util.formatDate(min, 'Y-M-D')
|
|
this.setData({height: app.globalData.fragmentHeight - 100, tabIndex: this.data.tabIndex})
|
|
var searchString = storage.get('mall-search')
|
|
if(!util.isEmpty(searchString)){
|
|
rearchStringList = searchString.split(',').slice(0, 24)
|
|
if(rearchStringList.length > limit){
|
|
this.setData({searchList: rearchStringList.slice(0, limit), keyIndex: 1 })
|
|
} else {
|
|
this.setData({searchList: rearchStringList, keyIndex: 0 })
|
|
}
|
|
}
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
onEvent: function (message) {
|
|
if(message.what == 223){
|
|
this.setData({ visible: true })
|
|
}
|
|
},
|
|
flodKeybord: function(){
|
|
if(this.data.keyIndex > 0 && this.data.keyIndex == 2){
|
|
this.setData({keyIndex : 1, searchList: rearchStringList.slice(0, limit), focus: true})
|
|
} else if(this.data.keyIndex > 0 && this.data.keyIndex == 1){
|
|
this.setData({keyIndex : 2, searchList: rearchStringList, focus: true})
|
|
}
|
|
},
|
|
clearHistory: function(){
|
|
var that = this
|
|
wx.removeStorage({
|
|
key: 'mall-search',
|
|
success (res) {
|
|
rearchStringList = []
|
|
that.setData({ searchList: [], keyIndex: 0 })
|
|
}
|
|
})
|
|
},
|
|
onFocusChange: function(){
|
|
this.setData({ focus: true })
|
|
},
|
|
onTabChange: function({detail}){
|
|
if(this.data.tabIndex == Number(detail.index)){
|
|
return
|
|
}
|
|
this.data.tabIndex = Number(detail.index)
|
|
if (!app.globalData.userInfo && Number(detail.index) == 2) {
|
|
this.data.form.pageNum = 1
|
|
this.data.dataIndex = 0
|
|
this.setData({ taskList: [], finished: false, requesting: false })
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.searchKey)){
|
|
return
|
|
}
|
|
this.onSearchList({ detail:{value: this.data.form.searchKey} })
|
|
},
|
|
onSearchList: function({detail}){
|
|
if (!app.globalData.userInfo && this.data.tabIndex == 2) {
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
this.data.form.searchKey = detail.value
|
|
if(util.isEmpty(this.data.form.searchKey)){
|
|
util.showToast('请输入要搜索的关键字')
|
|
return
|
|
}
|
|
var index = rearchStringList.indexOf(this.data.form.searchKey)
|
|
if(index >= 0){
|
|
rearchStringList.splice(index, 1)
|
|
}
|
|
rearchStringList.unshift(this.data.form.searchKey)
|
|
if(rearchStringList.length > 24){
|
|
rearchStringList.slice(0, 24)
|
|
}
|
|
var searchList = []
|
|
if(this.data.keyIndex == 0 && rearchStringList.length > limit){
|
|
this.data.keyIndex = 1
|
|
searchList = rearchStringList.slice(0, limit)
|
|
} else if(this.data.keyIndex == 1 && rearchStringList.length > limit){
|
|
searchList = rearchStringList.slice(0, limit)
|
|
} else if(this.data.keyIndex == 2){
|
|
searchList = rearchStringList
|
|
} else {
|
|
searchList = rearchStringList
|
|
}
|
|
this.data.form.pageNum = 1
|
|
this.data.dataIndex = 0
|
|
this.setData({ taskList: [], loading: true, finished: false, searchList, keyIndex: this.data.keyIndex, focus: false, ['form.searchKey']: detail.value })
|
|
this.fetchTaskList()
|
|
},
|
|
fetchTaskList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
if (this.data.loading) {
|
|
this.setData({ loading: true })
|
|
} else {
|
|
this.setData({ requesting: true })
|
|
}
|
|
if(this.data.tabIndex == 0){
|
|
getFactoryPrice(this.data.form).then(result => {
|
|
if (result.data && result.data.records.length) {
|
|
this.handRespList(result.data)
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false, tabIndex: this.data.tabIndex})
|
|
util.showToast(err)
|
|
})
|
|
} else if(this.data.tabIndex == 1){
|
|
getInformationList(this.data.form).then(result => {
|
|
if (result.data && result.data.records.length) {
|
|
this.handMomentResult(result.data)
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
util.showToast(err)
|
|
})
|
|
} else if(this.data.tabIndex == 2){
|
|
getProxyOrderList(this.data.form).then(result => {
|
|
if (result.data && result.data.records.length) {
|
|
this.handRespList(result.data)
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
util.showToast(err)
|
|
})
|
|
} else if(this.data.tabIndex == 3){
|
|
getPreferList(this.data.form).then(result => {
|
|
if (result.data && result.data.records.length) {
|
|
this.handRespList(result.data)
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
handMomentResult: function(data){
|
|
var respList = 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 && 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 = `taskList[${this.data.taskList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= data.pages
|
|
this.setData({ [nowList]: respList, total: data.total, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
},
|
|
handRespList: function(data){
|
|
let nowList = `taskList[${this.data.taskList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= data.pages
|
|
if (this.data.form.pageNum == 1) {
|
|
this.setData({ [nowList]: data.records, total: data.total, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
} else {
|
|
this.setData({ [nowList]: data.records, total: data.total, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false, tabIndex: this.data.tabIndex })
|
|
}
|
|
},
|
|
tagClick: function(e){
|
|
this.data.form.searchKey = this.data.searchList[e.currentTarget.dataset.index]
|
|
this.onSearchList({detail:{value: this.data.form.searchKey}})
|
|
},
|
|
onShow: function () {
|
|
tdsdk.Page.onShow()
|
|
},
|
|
onHide: function(){
|
|
tdsdk.Page.onHide()
|
|
},
|
|
onUnload: function() {
|
|
tdsdk.Page.onUnload()
|
|
event.remove('EventMessage', this)
|
|
if(rearchStringList.length){
|
|
storage.put('mall-search', rearchStringList.toString())
|
|
}
|
|
}
|
|
})
|