<template>
    <view class="cm-product" @click.stop="detail">
        <view class="recommend" v-if="data.recommend === '1'"></view>
        <!-- 封面 -->
        <image class="cover" :src="data.mainImage"></image>
        <view class="content">
            <!-- 标题名称 -->
            <view class="title">{{ data.name }}</view>
            <!-- 标签 -->
            <view class="tags">
                <!-- <view class="tag type1">自营</view> -->
                <view class="tag pt" v-if="data.collageStatus === 1">拼团价</view>
                <view class="tag hd" v-if="data.activeStatus == 1 && data.collageStatus === 0">活动价</view>
                <view class="tag hd" v-if="data.couponsLogo">优惠券</view>
            </view>
            <!-- 底部 -->
            <view class="footer">
                <!-- 价格 -->
                <view class="price">
                    <view class="delete">
                        <text v-if="data.normalPrice">￥{{ data.normalPrice | priceFormat }}</text>
                        <!-- <view class="delete" >￥99.00</view> -->
                    </view>
                    <view>￥{{ data.price | priceFormat }}</view>
                </view>
                <!-- 加入购物车 -->
                <view
                    class="add-cart iconfont icon-gouwuche"
                    @click.stop="addCart"
                    v-if="data.collageStatus !== 1"
                ></view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    name: 'cm-product',
    props: {
        data: {
            type: Object,
            default: () => {}
        }
    },
    methods: {
        // 跳转商品详情
        detail() {
            this.$router.navigateTo(`goods/goods-detail?productId=${this.data.productId}&jumpState=1`)
        },
        // 加入购物车
        addCart() {
            this.$store.dispatch('cart/addToCart', { productId: this.data.productId })
        }
    }
}
</script>

<style lang="scss" scoped>
$width: 224rpx;
$height: 430rpx;
$radius: 16rpx;
$grid: 16rpx;

.cm-product {
    position: relative;
    width: $width;
    height: $height;
    background: #fff;
    border-radius: $radius;
    overflow: hidden;
    .recommend {
        position: absolute;
        top: 0;
        left: 34rpx;
        width: 68rpx;
        height: 55rpx;
        background: url(https://static.caimei365.com/app/mini-hehe/icon/recommend.png) no-repeat center;
        background-size: 68rpx 55rpx;
    }
    .cover {
        width: $width;
        height: $width;
    }
    .title,
    .tags,
    .footer {
        padding: 0 $grid;
        margin: 8rpx 0;
    }
    .title {
        height: 70rpx;
        font-size: 26rpx;
        line-height: 35rpx;
        text-align: justify;
        color: #333333;
        @include ellipsis(2);
    }
    .tags {
        @extend .cm-flex-center;
        justify-content: flex-start;
        height: 24rpx;
    }
    .footer {
        position: relative;

        .add-cart {
            position: absolute;
            bottom: 0;
            right: $grid;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 44rpx;
            height: 44rpx;
            background: #ff457b;
            color: #fff;
            border-radius: 50%;
        }
        .price {
            height: 66rpx;
            box-sizing: border-box;
            padding-right: $grid;
            font-size: 26rpx;
            font-weight: 600;
            color: #f83c6c;
            .delete {
                height: 26rpx;
                margin-top: 4rpx;
                font-size: 20rpx;
                color: #999999;
                text-decoration: line-through;
                font-weight: normal;
            }
        }
    }
}
</style>
