index.js 3.35 KB
import Taro, {Component} from '@tarojs/taro';
import {View, Text, ScrollView, Image} from '@tarojs/components';
import {getImgUrl} from '../../utils';
import arrowIcon from '../../static/images/arrow-right.png';
import './index.scss';
import router from '../../router/index.js'


export default class category extends Component {
    constructor(props) {
        super(props);

        this.state = {};
    }

    static defaultProps = {
        floor: {}
    }

    goToList(floor) {
      router.goUrl(floor.more_url);
    }

    goToDetail(product) {
      router.go('productDetail', { id: product.product_id });
    }

    render() {
        let {floor} = this.props;
        let list = floor.list || [];
        let newList = [];

        for(let i = 0; i < list.length; i+=3) {
            newList.push(list.slice(i, i + 3));
        }

        return (
            <View className="category">
                <View className="floor-header">
                    <View className="title">{floor.category_name}</View>
                    <View className="more" hover-class="none" onClick={this.goToList.bind(this, floor)}>
                      MORE
                      <Image src={arrowIcon} className="arrow-right-icon"/>
                    </View>
                </View>
                {
                    newList.length > 0 &&
                    <ScrollView
                        className='scrollview'
                        scrollX
                        scrollWithAnimation
                        scrollLeft='0'
                        lowerThreshold='20'
                        upperThreshold='20'
                    >
                        {
                            newList.map((s, i) => {
                                return (
                                    <View className="item-group" key={i}>
                                    {
                                        s.map(item => {
                                            return (
                                                <View className="item" key={item.product_id} key={item.product_id}>
                                                    <View className="item-navigator" onClick={this.goToDetail.bind(this, item)} hover-class="none">
                                                        <View className="item-img">
                                                            <Image className="img" src={getImgUrl(item.image_url, 140, 140)} mode="aspectFit"/>
                                                        </View>
                                                        <View className="product-dec">
                                                            <Text className="item-name">{item.product_name}</Text>
                                                            <View className="item-code">货号 {item.product_code}</View>
                                                        </View>
                                                    </View>
                                                </View>
                                            )
                                        })
                                    }
                                </View>
                                )                     
                            })
                        }
                    </ScrollView>
                }                
            </View>
        )
    }
}