<template>
	<view class="section_page_main clearfix">
		<view class="recommend-list">
			<swiper
				class="tui-banner-swiper"
				:autoplay="true"
				:interval="5000"
				:duration="500"
				:circular="true"
				@change="swiperChange"
			>
				<swiper-item class="clearfix">
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
				</swiper-item>
				<swiper-item class="clearfix">
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
					<view class="img-box">
						<image :src="testImgUrl" mode="aspectFill"></image>
					</view>
				</swiper-item>
			</swiper>
			<view class="swiper__recommenddots-box" v-if="productList.length > 1">
				<view
					v-for="(item, idx) in productList"
					:key="idx"
					:class="[idx === swiperCurrent ? 'swiper__dots-long' : 'none']"
					:data-index="swiperCurrent"
					class="swiper__dots-item"
				>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import uniGrader from '@/components/uni-grade/uni-grade.vue'
export default {
	name: 'templateH',
	components: {
		uniGrader
	},
	props: {
		pageData: {
			type: Object
		},
		userIdentity: {
			type: Number
		}
	},
	data() {
		return {
			shopId: 0,
			productList: [1, 2],
			current: 100,
			swiperCurrent: 0,
			pageSize: 4,
			testImgUrl:
				'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-3ad36ff8-4f90-4748-8ad3-ca265841c862/8df647e0-69c4-4ea5-ac2f-648218096656.jpg'
		}
	},
	filters: {
		NumFormat: function(text) {
			//处理金额
			return Number(text).toFixed(2)
		}
	},
	created() {
		// this.initData(this.pageData)
	},
	watch: {
		pageData: {
			handler: function(el) {
				//监听对象的变换使用 function，箭头函数容易出现this指向不正确
				this.pageData = el
				this.initData(this.pageData)
			},
			deep: true
		}
	},
	methods: {
		initData(data) {
			this.$api.getStorage().then(resolve => {
				this.shopId = resolve.shopId ? resolve.shopId : 0
			})
			if (data.floorImageList.length > 0) {
				this.productList.splice(0, this.productList.length)
				for (var i = 0, j = data.floorImageList.length; i < j; i += this.pageSize) {
					this.productList.push(data.floorImageList.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(pros) {
			//跳转商品详情页
			this.$api.FlooryNavigateTo(pros)
		}
	}
}
</script>

<style lang="scss">
.section_page_main {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	.recommend-list {
		width: 100%;
		height: 500rpx;
		position: relative;
		padding-bottom: 20rpx;
		.tui-banner-swiper {
			width: 100%;
			margin: 0 auto;
			background: #f7f7f7;
			height: 445rpx;
			overflow: hidden;
			transform: translateY(0);
			.img-box {
				width: 339rpx;
				height: 210rpx;
				float: left;
				margin: 24rpx 24rpx 0 0;
				overflow: hidden;
				border-radius: 16rpx;
				image {
					width: 339rpx;
					height: 210rpx;
				}
				&:nth-child(2n) {
					margin-right: 0;
				}
				&:nth-child(1),
				&:nth-child(2) {
					margin-top: 0;
				}
			}
		}
	}
	.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, 0.3);
		}
		.swiper__dots-long {
			width: 32rpx;
			height: 8rpx;
			border-radius: 4rpx;
			background-color: #e15616;
			transition: all 0.4s;
		}
	}
}
</style>
