<template>
	<view class="center">
		<view class="list-box-h">
			<view v-for="(item, index) in dataList" :key="index" class="guess-item" @click="navToDetailPage(item)">
				<image :src="item.image"></image>
				<view class="guess-box">
					<view class="title clamp2">{{ item.title }}</view>
					<view class="price-box flex">
						<view class="yuanprice">{{ item.ot_price }}</view>
						<image src="../../static/img/jiantou.png" mode=""></image>
						<view class="jiang">直降{{ (item.ot_price - item.price).toFixed(2) }}元</view>
					</view>
					<view class="price">￥{{ item.price }}</view>
					<view class="btn">立即购买</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { dhList } from '@/api/product.js';
export default {
	data() {
		return {
			dataList: [],
			page: 1,
			limit: 10,
			loadingType:'more'
		};
	},
	onLoad() {
		this.loadData();
	},
	onReachBottom(){
		this.loadData()
	},
	methods: {
		loadData() {
			const obj = this;
			if (this.loadingType === 'loading') {
				//防止重复加载
				return;
			}
			if (this.loadingType === 'noMore') {
				//防止重复加载
				return;
			}
			this.loadingType = 'loading';
			dhList({ page: this.page, limit: this.limit }).then(({ data }) => {
				console.log(data)
				if(data.length > 0){
					this.dataList = this.dataList.concat(data)
				}
				this.$nextTick(function() {
					if (obj.limit == data.length) {
						//判断是否还有数据， 有改为 more， 没有改为noMore
						obj.loadingType = 'more';
						return;
					} else {
						//判断是否还有数据， 有改为 more， 没有改为noMore
						obj.loadingType = 'noMore';
					}
				});
				this.$set(obj.dataList, 'loaded', true);
			});
		},
		navToDetailPage(item){
			uni.navigateTo({
				url:'/pages/product/vipProduct?id=' + item.id
			})
		}
	}
};
</script>

<style lang="scss">
page,
.center {
	height: auto;
	min-height: 100%;
	background-color: #ffffff;
}
.guess-item {
	display: flex;
	width: 710rpx;
	height: 290rpx;
	background: #ffffff;
	box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
	border-radius: 10rpx;
	padding: 15rpx;
	padding-bottom: 150rpx;
	margin: 20rpx auto 0;
	position: relative;
	image {
		width: 200rpx;
		height: 200rpx;
		border-radius: 10rpx;
	}
	.guess-box {
		padding: 12rpx 0 0 24rpx;
		width: 436rpx;
		.title {
			font-size: 36rpx;
			padding-left: 4rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			width: 368rpx;
			line-height: 36rpx;
			.tuanF {
				display: inline-block;
				margin-right: 4rpx;
				position: relative;
				top: -6rpx;
				.tuan {
					display: flex;
					align-items: center;
					padding: 10rpx;
					height: 36rpx;
					background: #ffebe9;
					border-radius: 18rpx;
					.tuan-image {
						width: 18rpx;
						height: 18rpx;
					}
					.tuan-font {
						display: inline;
						font-size: 20rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #ff1135;
						margin-left: 2rpx;
					}
				}
			}
		}
		.ping-box {
			margin-top: 15rpx;
			justify-content: flex-start;
			.ping {
				margin-left: 10rpx;
				height: 39rpx;
				background: #fdf7eb;
				border-radius: 5rpx;
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #ff911f;
				display: flex;
				align-items: center;
				padding: 0 10rpx;
			}
		}
		.price-box {
			margin-top: 80rpx;
			justify-content: flex-start;
			.yuanprice {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				text-decoration: line-through;
				color: #999999;
				padding-right: 6rpx;
			}
			image {
				width: 14rpx;
				height: 16rpx;
			}
			.jiang {
				padding-left: 2rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #b59467;
			}
		}
		.price {
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #ff1135;
		}
		.btn {
			width: 137rpx;
			height: 56rpx;
			background: #16cc9f;
			border-radius: 28rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			line-height: 56rpx;
			text-align: center;
			position: absolute;
			bottom: 25rpx;
			right: 25rpx;
		}
	}
}
</style>
