<template>
	<view class="container">
		<!-- 头部轮播 -->
		<!-- <view class="carousel-section">
			<swiper class="carousel" autoplay="true" duration="400" interval="5000">
				<swiper-item v-for="(item, index) in bannerImg" :key="index" class="carousel-item" @click="bannerNavToUrl(item)">
					<image :src="item.img" mode=" scaleToFill" />
				</swiper-item>
			</swiper>
		</view> -->
		<!-- <view class="type-title-box flex">
			<view class="title-border"></view>
			<view class="title-content">
				<text v-if="type == 1">精品推荐</text>
				<text v-if="type == 2">热门榜单</text>
				<text v-if="type == 3">首发新品</text>
				<text v-if="type == 4">促销单品</text>
			</view>
			<view class="title-border"></view>
		</view> -->

		<view class="goodsList-box">
			<view class="goodsList-item flex" :key="ind" v-for="(ls, ind) in list">
				<image :src="ls.image || errImg" mode=" scaleToFill"></image>
				<view class="goodsList-content">
					<view class="title">
						<text class="clamp2">{{ ls.store_name }}</text>
					</view>
					<view class="goods-money flex">
						<view class="money-box">
							<text class="otMoney">￥{{ ls.ot_price }}</text>
							<image src="@/static/icon/decline.png"></image>
							<!-- <image src="../../static/error/errorImage.jpg"></image> -->
							<text class="decline">直降{{ ls.ot_price - ls.price}}元</text>
							<!-- <view class="otMoney-box"> -->
								<view class="money">￥{{ ls.price }}</view>
								<!-- <text class="sales">已售{{ ls.sales }}件</text> -->
							<!-- </view> -->
						</view>
						<view class="button" @click="navTo(ls)">立即购买</view>
						<!-- <view @click="navTo(ls)" class="cart iconfont iconcart"></view> -->
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { groomList } from '@/api/product.js';
export default {
	data() {
		return {
			list: [],
			bannerImg: [],
			title: '',
			errImg: require('@/static/error/errorImage.jpg')
		};
	},
	onLoad(option) {
		// 获取查询对象
		this.type = option.type;
		// 加载基础数据
		this.loadData();
	},
	created() {
		this.getTitle()
	},
	mounted() {
		
	},
	methods: {
		//动态改变标头
		getTitle() {
			let title = ''
			if(this.type == 1) {
				title = "精选好货"
			}else if(this.type == 2) {
				title = "热销专区"
			}else if(this.type == 3) {
				title = "收藏夹"
			}else {
				title = "促销单品"
			}
			uni.setNavigationBarTitle({
				title: title
			});
		},
		navTo: function(ls) {
			uni.navigateTo({
				url: '/pages/product/product?id=' + ls.id
			});
		},
		// 请求载入数据
		async loadData() {
			groomList({}, this.type)
				.then(({ data }) => {
					// 保存轮播图
					this.bannerImg = data.banner;
					// 保存商品信息
					this.list = data.list;
				})
				.catch(e => {
					console.log(e);
				});
		},
		// 轮播图跳转
		bannerNavToUrl(item) {
			// #ifdef H5
			if (item.wap_link.indexOf('http') > 0) {
				window.location.href = item.wap_link;
			}
			// #endif
			if (item.wap_link) {
				uni.navigateTo({
					url: item.wap_link
				});
			}
		}
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
}
.carousel-section {
	padding: 0;
	.titleNview-placing {
		padding-top: 0;
		height: 0;
	}
	.swiper-dots {
		left: 45rpx;
		bottom: 40rpx;
	}
	.carousel {
		width: 100%;
		height: 360rpx;
		.carousel-item {
			width: 100%;
			height: 100%;
			overflow: hidden;
		}
		image {
			width: 100%;
			height: 100%;
		}
	}
}
// 中间标题样式
.type-title-box {
	padding: 40rpx;
	.title-content {
		height: 100%;
		width: 200rpx;
		text-align: center;
		font-size: $font-lg;
		font-weight: 500;
		color: $font-color-dark;
	}
	.title-border {
		width: 250rpx;
		height: 2rpx;
		background-color: #e9e9e9;
	}
}
// 商品列表
.goodsList-box {
	padding: 30rpx;
	.goodsList-item {
		box-shadow:0 0 20rpx 6rpx #f1f1f1;
		border-radius: 10rpx;
		margin-bottom: 30rpx;
		background-color: #ffffff;
		padding: 30rpx;
		image {
			flex-shrink: 0;
			border-radius: $border-radius-sm;
			height: 180rpx;
			width: 180rpx;
		}
		.goodsList-content {
			margin-left: 20rpx;
			flex-grow: 1;
			height: 180rpx;
			position: relative;
			.title {
				font-size: $font-base;
				color: $font-color-dark;
				font-weight: bold;
			}
			.goods-money {
				position: absolute;
				left: 0;
				bottom: 0;
				width:100%;
				.money-box {
					.otMoney {
						color: #999999;
						text-decoration: line-through;
						margin-right: 15rpx;
						font-size: 20rpx;
					}
					.money {
						color: #EF3A55;
						font-weight: bold;
						font-size: 35rpx;
					}
					image {
						width: 20rpx;
						height: 20rpx;
						margin-right: 5rpx;
					}
					.decline {
						color: #FFB238;
						font-size: 20rpx;
					}
					.sales {
						color: $font-color-light;
					}
				}
				.button {
					background: linear-gradient(90deg, #438BED 0%,  #44BFEC 100%);
					background-color: #438BED;
					height: 50rpx;
					border-radius: 20rpx;
					padding: 10rpx 15rpx;
					color: #fff;
					font-size: 25rpx;
					position: relative;
					top: 20rpx;
				}
				.cart {
					border: 1px solid $color-red;
					color: $color-red;
					font-size: $font-base;
					font-weight: bold;
					border-radius: 99px;
					width: 55rpx;
					height: 55rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}
	}
}
</style>
