index.js
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Taro, { Component } from '@tarojs/taro';
import { View, Text} from '@tarojs/components';
import { SearchItem, SearchBar, PageTitle } from '../../components';
import {search as searchModel} from '../../models';
import './index.scss';
export default class Search extends Component {
constructor() {
super(...arguments);
this.state = {
hotSearch: [],
latelySearch: [],
hotSearchTitle: '热门推荐',
latelySearchTitle: '最近搜索',
fixed: false
};
}
config = {
navigationBarTitleText: '搜索'
}
componentDidMount () {
searchModel.getSearchWord().then(ret => {
if (ret && ret.code === 200) {
this.setState({
hotSearch: ret.data || []
});
}
})
}
onScroll(e) {
if (e.detail.scrollTop > 48) {
this.setState({
fixed: true
});
} else {
this.setState({
fixed: false
});
}
}
onScrolltoupper() {
this.setState({
fixed: false
});
}
render () {
let {hotSearchTitle, hotSearch, latelySearchTitle, latelySearch} = this.state;
return (
<ScrollView
className='search-page'
scrollY
scrollWithAnimation
scrollTop='0'
lowerThreshold='20'
upperThreshold='20'
onScrolltoupper={this.onScrolltoupper}
onScroll={this.onScroll}>
<PageTitle pageTitle="搜索"></PageTitle>
<View className={this.fixed ? 'fixed search-out-box' : 'search-out-box'}>
<SearchBar></SearchBar>
</View>
{
latelySearch.length > 0 &&
<SearchItem title={latelySearchTitle} list={latelySearch}></SearchItem>
}
{
hotSearch.length > 0 &&
<SearchItem title={hotSearchTitle} list={hotSearch} ></SearchItem>
}
</ScrollView>
)
}
}