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

170 lines
5.3 KiB

// pages/home/about/index.js
import { getFactoryPrice, getProxyOrderList } from "../../../api/ztb"
import { getPreferList, getInformationList } from "../../../api/moment"
const storage = require('../../../utils/storage')
const util = require('../../../utils/util')
const tdsdk = require('../../../libs/tdweapp.js')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
height: app.globalData.fragmentHeight - 100,
focus: true,
rearchStringList: [],
tabList: [ '交易', '行情', '订单' , '资讯'],
tabIndex: 0,
form: {
searchKey: '',
pageSize: 10,
pageNum: 1
},
loading: true,
requesting: false,
finished: false,
taskList: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var searchString = storage.get('mall-search')
if(!util.isEmpty(searchString)){
this.setData({rearchStringList: searchString.split(',').slice(0, 24)})
}
if(options.tab) {
this.data.tabIndex = Number(options.tab)
}
this.setData({height: app.globalData.fragmentHeight - 100, tabIndex: this.data.tabIndex})
},
clearHistory: function(){
var that = this
wx.removeStorage({
key: 'mall-search',
success (res) {
that.setData({ rearchStringList: [] })
}
})
},
onFocusChange: function(){
this.setData({ focus: true })
},
onBlurChange: function(){
if(util.isEmpty(this.data.form.searchKey)){
return
}
this.setData({ focus: false })
},
onTabChange: function({detail}){
if(this.data.tabIndex == Number(detail.index)){
return
}
this.data.tabIndex = Number(detail.index)
if (!app.globalData.userInfo && this.data.tabIndex == 3) {
wx.navigateTo({ url: '/pages/login/index' })
return
}
this.onSearchList({ detail:{value: this.data.form.searchKey} })
},
onSearchList: function({detail}){
this.data.form.searchKey = detail.value
if(util.isEmpty(this.data.form.searchKey)){
util.showToast('请输入要搜索的关键字')
return
}
var strList = this.data.rearchStringList
if(!util.isEmpty(this.data.form.searchKey) && strList.indexOf(this.data.form.searchKey) < 0){
strList.splice(0, 0, this.data.form.searchKey)
}
this.data.form.pageNum = 1
this.setData({ taskList: [], loading: true, finished: false, rearchStringList: strList.slice(0, 24), focus: false, ['form.searchKey']: detail.value })
this.fetchTaskList()
},
fetchTaskList: function(){
if (this.data.requesting || this.data.finished) {
return
}
if (this.data.loading) {
this.data.requesting = true
} else {
this.setData({ requesting: true })
}
if(this.data.tabIndex == 0){
getFactoryPrice(this.data.form).then(result => {
if (result.data.records.length) {
this.handRespList(result.data.records)
} else {
this.setData({ finished: true, requesting: false, loading: false })
}
}).catch(err => {
this.setData({ requesting: false, loading: false })
util.showToast(err)
})
} else if(this.data.tabIndex == 1){
getInformationList(this.data.form).then(result => {
if (result.data.records.length) {
this.handRespList(result.data.records)
} else {
this.setData({ finished: true, requesting: false, loading: false })
}
}).catch(err => {
this.setData({ requesting: false, loading: false })
util.showToast(err)
})
} else if(this.data.tabIndex == 2){
getProxyOrderList(this.data.form).then(result => {
if (result.data.records.length) {
this.handRespList(result.data.records)
} else {
this.setData({ finished: true, requesting: false, loading: false })
}
}).catch(err => {
this.setData({ requesting: false, loading: false })
util.showToast(err)
})
} else if(this.data.tabIndex == 3){
getPreferList(this.data.form).then(result => {
if (result.data.records.length) {
this.handRespList(result.data.records)
} else {
this.setData({ finished: true, requesting: false, loading: false })
}
}).catch(err => {
this.setData({ requesting: false, loading: false })
util.showToast(err)
})
}
},
handRespList: function(respList){
let nowList = `taskList[${this.data.taskList.length}]`
var num = this.data.form.pageNum
var finished = this.data.form.pageNum >= result.data.pages
if (this.data.form.pageNum == 1) {
this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false })
} else {
this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false })
}
},
tagClick: function(e){
this.data.form.searchKey = this.data.rearchStringList[e.currentTarget.dataset.index]
this.onSearchList({detail:{value: this.data.form.searchKey}})
},
onShow: function () {
tdsdk.Page.onShow()
},
onHide: function(){
tdsdk.Page.onHide()
},
onUnload() {
tdsdk.Page.onUnload()
if(this.data.rearchStringList.length){
try {
wx.setStorageSync('mall-search', this.data.rearchStringList.toString())
} catch (e) {
}
}
}
})