From 8cd682144aa00e6bf78401662bac598a6b4f19b3 Mon Sep 17 00:00:00 2001 From: xpz2018 <107107461@qq.com> Date: Tue, 28 Sep 2021 20:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/mall/search-list/index.js | 100 +++++++++++++++++++++++++++--- pages/mall/search-list/index.wxml | 10 +-- 2 files changed, 95 insertions(+), 15 deletions(-) diff --git a/pages/mall/search-list/index.js b/pages/mall/search-list/index.js index f21122f..26c4981 100644 --- a/pages/mall/search-list/index.js +++ b/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()) diff --git a/pages/mall/search-list/index.wxml b/pages/mall/search-list/index.wxml index dea8304..466a752 100644 --- a/pages/mall/search-list/index.wxml +++ b/pages/mall/search-list/index.wxml @@ -4,7 +4,7 @@ - + @@ -35,10 +35,10 @@ - - - - + + + +