index.js
1.38 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
import Taro, {Component} from '@tarojs/taro';
import {View, Text, Image, Navigator} from '@tarojs/components';
import {getImgUrl} from '../../utils';
import './index.scss';
import router from '../../router/index.js'
export default class ProductList extends Component {
constructor(props) {
super(props);
this.state = {
newList: []
};
}
static defaultProps = {
list: []
}
goToDetail(product) {
router.go('productDetail', {
id: product.id
});
}
render() {
let { list } = this.props;
let newList = list.map((item) => {
if (!item.price) {
item.price = ''
}
return item
})
return (
<View className="product-list">
{
newList.map((item, index) => {
return (
<View className= "product-item" key = { index }>
<View onClick={this.goToDetail.bind(this, item)} hover-class="none">
<Text className="product-price">{item.price ? '¥' + item.price : ''}</Text>
<Image src={getImgUrl(item.default_images, 376, 376)} mode="aspectFit" className="product-img"/>
<Text className="product-name">{item.product_name}</Text>
</View>
</View>
)
})
}
</View>
)
}
}