index.js
3.26 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
95
96
97
98
99
100
101
102
103
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'
import router from '../../router/index.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
});
}
goToList(brand) {
router.go('productList', {
brand: brand.id,
name: brand.brand_name
});
}
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 (
<View
className={index < num ? 'brand-item border' : 'brand-item'}
key={index}
hover-class="none"
onClick={this.goToList.bind(this, item)}
>
<Image src={ getImgUrl(item.brand_logo, 160, 80) } mode ="aspectFit" className="brand-img"></Image>
</View>
)
})
}
</View>
}
</ScrollView>
)
}
}