import React, {Component} from 'react'
import {Link} from 'react-router-dom'
import CartItem from './cartItem'

class cartList extends Component {
    render() {
        return (
            <div className="cart-main">
                {/* 遍历购物车商品列表 */}
                <div className="cart-c-body">
                    {
                        this.props.data.length > 0 ?
                            this.props.data.map((item, index) => {
                                return (
                                    <CartItem
                                        index={index}
                                        changeStock={(id, val) => {
                                            this.props.changeStock(id, val)
                                        }}
                                        checkChange={(id, val) => {
                                            this.props.checkChange(id, val)
                                        }}
                                        key={index} 
                                        item={item}
                                        toDetail={this.props.toDetail}
                                    />
                                )
                            })
                            : <div className="cart-tip">
                                <p className='cart-mess'>这里是空的，快去逛逛吧~</p>
                                <Link to='/classify'>去逛逛</Link>
                            </div>
                    }
                </div>
            </div>
        )
    }
}

export default cartList;