index.js
2.99 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
83
84
85
86
87
88
89
90
91
92
93
94
import Taro, { Component } from '@tarojs/taro';
import { View, Text, Navigator} from '@tarojs/components';
import contentCode from '../../utils/content-code';
import {Resources} from '../../components';
import {classify as classifyModel} from '../../models';
import {getImgUrl} from '../../utils';
import './index.scss';
import getPrivateKey from '../../libs/request/getPrivateKey.js'
export default class Classify extends Component {
constructor() {
super(...arguments);
this.state = {
tabs: ['品类', '品牌'],
actived: '品类',
brandList: []
};
}
config = {
navigationBarTitleText: '分类'
}
async componentDidMount () {
const pk = await getPrivateKey();
Taro.setStorage({ key: 'verifyKey', data: pk });
classifyModel.getBrandList().then(ret => {
if (ret && ret.code === 200) {
this.setState({
brandList: ret.data && ret.data.brand_list || []
});
}
})
}
changeTab(item) {
this.setState({
actived: item
});
}
render () {
let {tabs, actived, brandList} = this.state;
let num = brandList.length - brandList.length % 3;
return (
<ScrollView
className='classify-page'
scrollY
scrollWithAnimation
scrollTop='0'
lowerThreshold='20'
upperThreshold='20'
onScrolltoupper={this.onScrolltoupper}
onScroll={this.onScroll}>
<View className="tabs">
{
tabs.map(item => {
return (
<Text
className={item === actived ? 'actived tab-item' : 'tab-item'}
onClick={this.changeTab.bind(this, item)}
key={item}>{item}</Text>
)
})
}
</View>
{
actived === '品类' &&
<Resources code={contentCode.classify}></Resources>
}
{
actived === '品牌' &&
<View className="brand-list">
{
brandList.length > 0 &&
brandList.map((item, index) => {
return (
<Navigator
className={index < num ? 'brand-item border' : 'brand-item'}
key={index}
hover-class="none"
url={`/pages/searchList/index?brand=${item.id}&name=${item.brand_name}`}>
<Image src={getImgUrl(item.brand_logo, 160, 80)} mode="aspectFill" className="brand-img"></Image>
</Navigator>
)
})
}
</View>
}
</ScrollView>
)
}
}