Browse Source

搜索

featrue/v4.5
xpz2018 4 years ago
parent
commit
8cd682144a
2 changed files with 95 additions and 15 deletions
  1. 100
      pages/mall/search-list/index.js
  2. 10
      pages/mall/search-list/index.wxml

100
pages/mall/search-list/index.js

@ -1,6 +1,9 @@
// 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({
@ -14,10 +17,13 @@ Page({
tabList: [ '交易', '行情', '订单' , '资讯'],
tabIndex: 0,
form: {
name: '',
searchKey: '',
pageSize: 10,
pageNum: 1
},
loading: true,
requesting: false,
finished: false,
taskList: []
},
/**
@ -46,7 +52,7 @@ Page({
this.setData({ focus: true })
},
onBlurChange: function(){
if(util.isEmpty(this.data.form.name)){
if(util.isEmpty(this.data.form.searchKey)){
return
}
this.setData({ focus: false })
@ -60,25 +66,99 @@ Page({
wx.navigateTo({ url: '/pages/login/index' })
return
}
this.onSearchList({ detail:{value: this.data.form.name} })
this.onSearchList({ detail:{value: this.data.form.searchKey} })
},
onSearchList: function({detail}){
this.data.form.name = detail.value
if(util.isEmpty(this.data.form.name)){
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.name) && strList.indexOf(this.data.form.name) < 0){
strList.splice(0, 0, this.data.form.name)
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 })
}
this.setData({ rearchStringList: strList.slice(0, 24), focus: false, ['form.name']: detail.value })
},
tagClick: function(e){
this.setData({ ['form.name']: this.data.rearchStringList[e.currentTarget.dataset.index] })
this.onSearchList({detail:{value: this.data.form.name}})
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())

10
pages/mall/search-list/index.wxml

@ -4,7 +4,7 @@
</cu-custom>
<view class="bg-white">
<free-input value="{{form.name}}" placeholder="请输入关键字" extreaWord="搜索" bind:focus="onFocusChange" bind:blur="onBlurChange" focus="{{focus}}" close="{{true}}" bind:extrea="onSearchList"></free-input>
<free-input value="{{form.searchKey}}" placeholder="请输入关键字" extreaWord="搜索" bind:focus="onFocusChange" bind:blur="onBlurChange" focus="{{focus}}" close="{{true}}" bind:extrea="onSearchList"></free-input>
</view>
<view class="bg-white" style="height:90rpx;border-bottom:2rpx solid #f3f3f3" wx:if="{{!focus || rearchStringList.length == 0}}">
<wux-tabi tab-data="{{tabList}}" tab-index="{{tabIndex}}" line-height="{{3}}" scroll="{{false}}" bind:change="onTabChange"></wux-tabi>
@ -35,10 +35,10 @@
<view style="height:2rpx;background-color:#f3f3f3"></view>
</view>
<view wx:for="{{pageItem}}" wx:key="index">
<agent-item item="{{item}}" keyword="{{form.name}}" wx:if="{{tabIndex == 0}}"></agent-item>
<moment-item item="{{item}}" keyword="{{form.name}}" wx:elif="{{tabIndex == 1}}"></moment-item>
<order-item item="{{item}}" keyword="{{form.name}}" wx:elif="{{tabIndex == 2}}"></order-item>
<info-item item="{{item}}" keyword="{{form.name}}" wx:else></info-item>
<agent-item item="{{item}}" keyword="{{form.searchKey}}" wx:if="{{tabIndex == 0}}"></agent-item>
<moment-item item="{{item}}" keyword="{{form.searchKey}}" wx:elif="{{tabIndex == 1}}"></moment-item>
<order-item item="{{item}}" keyword="{{form.searchKey}}" wx:elif="{{tabIndex == 2}}"></order-item>
<info-item item="{{item}}" keyword="{{form.searchKey}}" wx:else></info-item>
</view>
</view>
<!--加载更多的UI-->

Loading…
Cancel
Save