<template name="hotProduct">
	<view>
		<view class="container clearfix">
			<view class="title">推荐专区</view>
			<view class="recommend-list">
				<swiper class="tui-banner-swiper" :autoplay="false" :interval="5000" :duration="500" :circular="true" @change="swiperChange">
					<swiper-item v-for="(product,index) in hotProductList" :key="index">
						<view class="floor-item" v-for="(item, idx) in product" :key="idx" @click.stop="navToDetailPage(item.id)">
							<image class="tui-skeleton-fillet" :src="item.image" mode="aspectFill"></image>
							<view class="floor-item-content">
								<view class="title tui-skeleton-rect">
									<text class="mclap">{{item.name}}</text>
								</view>
								<view class="" v-if="hasLogin">
									<view v-if="userIdentity == 4">
										<view class="title-none" v-show="item.price1TextFlag == '1'">
											<text class="p big">￥未公开价格</text>
										</view>
										<view class="title-none" v-show="item.price1TextFlag == '2'">
											<text class="p big">￥价格仅会员可见</text>
										</view>
										<view class="price tui-skeleton-rect" v-show="item.price1TextFlag == '0'" :class="PromotionsFormat(item.promotions) ? 'none' : ''">
											<text class="p sm">￥</text>
											<text class="p big">{{ (PromotionsFormat(item.promotions) ? item.originalPrice : item.price ) | NumFormat}}</text>
										</view>
									</view>
									<view v-else>
										<view class="title-none" v-if="item.price1TextFlag == '1'">
											<text class="p big">未公开价格</text>
										</view>
										<view class="price tui-skeleton-rect" v-else :class="PromotionsFormat(item.promotions) ? 'none' : ''">
											<text class="p sm">￥</text>
											<text class="p big">{{ (PromotionsFormat(item.promotions) ? item.originalPrice : item.price ) | NumFormat}}</text>
											<template v-if="item.actStatus==1">
												<view class="floor-tags" v-if="PromotionsFormat(item.promotions)">
													{{item.promotions.name}}<text v-if="hasLogin && item.price1TextFlag != '1'">:￥{{item.price | NumFormat}}</text>
												</view>
												<view class="floor-tags" v-else>{{item.promotions.name}}</view>	
											</template>
											<template v-if="item.actStatus ==0  &&  item.ladderPriceFlag==1">
												<view class="floor-tags">阶梯价格</view>	
											</template>
										</view>
									</view>
								</view>
								<view v-else class="no-price">
									<view class="p-stars">
										<text class="p-no">￥</text>
										<uni-stars :stars="parseInt(item.price1Grade)" :fontSize="36" :widthInfo="180"></uni-stars>
										<template v-if="item.actStatus==1">
											<view class="floor-tags" v-if="PromotionsFormat(item.promotions)">
												{{item.promotions.name}}<text v-if="hasLogin && item.price1TextFlag != '1'">:￥{{item.price | NumFormat}}</text>
											</view>
											<view class="floor-tags" v-else>{{item.promotions.name}}</view>	
										</template>
										<template v-if="item.actStatus ==0  &&  item.ladderPriceFlag==1">
											<view class="floor-tags">阶梯价格</view>	
										</template>
									</view>
								</view>	
							</view>
						</view>
					</swiper-item>
				</swiper>
				<view class="swiper__recommenddots-box" v-if="hotProductList.length > 1">
					<view v-for="(item,idx) in hotProductList" 
						  :key="idx" 
						  :class="[idx===swiperCurrent?'swiper__dots-long':'none']" 
						  :data-index="swiperCurrent" class="swiper__dots-item">
					</view>	  
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations} from 'vuex';
	export default{
		name:"hotProduct",
		props:{
			list:{
				type:Array
			},
			userIdentity:{
				type:Number
			}
		},
		data() {
			return{
				current:100,
				swiperCurrent:0,
				hotProductList:[],
				pageSize:4,
			}
		},
		filters: {
			NumFormat:function(text) {//处理金额
				return Number(text).toFixed(2);
			},
		},
		created(){
			this.initData(this.list)
		},
		computed: {
			...mapState(['hasLogin','userInfo','isActivity'])
		},
		methods:{
			initData(res){
				if(res.length>0){
					for (var i = 0, j = res.length; i < j; i += this.pageSize) {
						this.hotProductList.push(res.slice(i, i + this.pageSize));
					}
				}
			},
			PromotionsFormat(promo){//促销活动类型数据处理
				if(promo!=null){
					if(promo.type == 1 && promo.mode == 1){
						return true
					}else{
						return false
					}
				}
				return false
			},
			tabClick(index) {//轮播图切换
				this.current = index;
			},
			swiperChange(e) {//轮播切换
				const index = e.detail.current;
				this.swiperCurrent = index;
			},
			navToDetailPage(id) {//跳转商品详情页
				this.$api.navigateTo(`/pages/goods/product?id=${id}`)
			}
		}
	}
</script>

<style lang="scss">
	.container{
		width: 100%;
		height: auto;
		box-sizing: border-box;
		.title{
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: left;
			font-weight: bold;
			font-size: $font-size-34;
			color: $text-color;
			padding: 0 24rpx;
			box-sizing: border-box;
		}
		.recommend-list{
			width: 100%;
			height: 1070rpx;
			position: relative;
			padding-bottom: 20rpx;
			.tui-banner-swiper {
				width: 702rpx;
				margin: 0 auto;
				background: #F7F7F7;
				padding: 0 24rpx 0 24rpx;
				height: 1070rpx;
				overflow: hidden;
				transform: translateY(0);
				.floor-item{
					width: 341rpx;
					height: auto;
					margin-right: 20rpx;
					font-size: $font-size-24;
					color: $text-color;
					background: #FFFFFF;
					line-height: 36rpx;
					border-radius: 2rpx;
					margin-bottom: 20rpx;
					float: left;
					box-sizing: border-box;
					&:nth-child(2n){
						margin-right: 0;
					}
					image{
						width: 341rpx;
						height: 341rpx;
						border-radius: 2rpx 2rpx 0 0;
						display: block;
						margin-bottom: 20rpx;
					}
					.floor-item-content{
						width: 311rpx;
						padding: 0 15rpx;
					}
					.floor-item-act{
						display: block;
						width: 100%;
						height: 68rpx;
						text-align: center;
						box-sizing: border-box;
						padding: 16rpx 0;
						margin-top: 8rpx;
					}
					.floor-tags{
						height: 36rpx;
						border-radius: 6rpx;
						background-color: #FFFFFF;
						line-height: 36rpx;
						color: $color-system;
						text-align: center;
						display: inline-block;
						padding:0 16rpx;
						font-size: $font-size-20;
						margin-left: 15rpx;
						border: 1px solid #E15616;
					}
					.title-none{
						font-size: $font-size-26;
						color: #FF2A2A;
						line-height: 44rpx;
						.btn{
							display: inline-block;
							float: right;
							width: 112rpx;
							height: 44rpx;
							background: $btn-confirm;
							line-height: 44rpx;
							font-size: $font-size-24;
							color: #FFFFFF;
							text-align: center;
							border-radius: 22rpx;
							margin-top: 17rpx;
						}
					}
					.title{
						width: 100%;
						height: 72rpx;
						display: flex;
						flex-direction: column;
						.mclap{
							width: 100%;
							line-height:40rpx;
							text-overflow:ellipsis;
							display: -webkit-box;
							word-break: break-all;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							font-size: 26rpx;
						}
					}
					.no-price{
						height: 54rpx;
						line-height: 54rpx;
						display: flex;
						box-sizing: border-box;
						.p-no{
							font-size: $font-size-30;
							color: $text-color;
							display: block;
							float: left;
						}
						.p-stars{
							width: 230rpx;
							float: left;
						}
					}
					.price{
						color: #FF2A2A;
						line-height:70rpx;
						&.none{
							text-decoration: line-through;
							color: #999999;
						}
						.sm{
							font-size: $font-size-24;
						}
						.big{
							font-size: $font-size-28;
						}
					}
				}
			}
		}	
		.swiper__recommenddots-box{
			position: absolute;
			bottom: 0;
			left: 0;
			right: 0;
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			flex: 1;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			height: 60rpx;
			.swiper__dots-item{
				width: 8rpx;
				height: 8rpx;
				border-radius: 100%;
				margin-left: 6px;
				background-color:rgba(225,86,22,.3);
			}
			.swiper__dots-long{
				width: 32rpx;
				height: 8rpx;
				border-radius: 4rpx;
				background-color: #e15616;
				transition: all 0.4s;
			}
		}
	}
</style>
