<template>
	<view class="content padding-t-20">
		<view class="flex item padding-v-20 padding-c-20" v-for="(item,index) in goodsList">
			<view class="imgbox">
				<image class="img" :src="item.image" mode="scaleToFill"></image>
			</view>
			<view class="contentbox padding-l-20 flex">
				<view class="clamp2 title">
					{{item.store_name}}
				</view>
				<view class="oldMoneyBox ">
					<view class="flex-start padding-b-10">
						<text class="oldMoney">￥{{item.price}}</text>
						<image class="icon padding-l-10" src="../../static/img/domIcon.png" mode="scaleToFill"></image>
						<text class="domMoney font-size-sm">
							直降{{item.sales}}元
						</text>
					</view>
					<view class="flex">
						<view class="money">￥{{item.price}}</view>
						<view class="buttomPay" @click="navto('/')">立即购买</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import {
		getProducts
	} from '@/api/product.js';
	export default {
		data() {
			return {
				// 列表
				goodsList: [],
				limit: 6, //每次加载数据条数
				page: 1, //当前页数
				loadingType: 'more', //加载更多状态


			};
		},
		onLoad() {
			this.getProducts();
		},
		onShow() {},
		onPullDownRefresh() {
			this.getProducts('refresh');
		},
		methods: {
			navto(url) {
				// #ifdef H5
				console.log(url.indexOf('http'), 'banner');
				if (url.indexOf('http') >= 0) {
					window.location.href = url;
				}
				// #endif
				//测试数据没有写id，用title代替
				uni.navigateTo({
					url: url
				});
			},
			async getProducts(type) {
				let obj = this;
				// 判断是否为重新加载数据
				if (type !== 'refresh') {
					//没有更多数据直接跳出方法
					if (obj.loadingType === 'nomore') {
						return;
					}
					if (obj.loadingType === 'loading') {
						//防止重复加载
						return;
					}
					// 设置当前为数据载入中
					obj.loadingType = 'loading';
				} else {
					this.page = 1;
					obj.goodsList = [];
					//当重新加载数据时更新状态为可继续添加数据
					obj.loadingType = 'more';
				}
				let data = {
					page: obj.page,
					limit: obj.limit,
				};
				getProducts(data).then(e => {
					obj.goodsList = obj.goodsList.concat(e.data);
					//判断是否还有下一页，有是more  没有是nomore
					if (obj.limit == e.data.length) {
						obj.page++;
						obj.loadingType = 'more';
					} else {
						obj.loadingType = 'nomore';
					}
				});
			},

		}
	};
</script>

<style lang="scss">
	page,
	.content {
		min-height: 100%;
		height: auto;
	}

	.item {
		border-radius: 10rpx;
		background-color: #FFFFFF;
		width: 690rpx;
		margin: 0 30rpx 20rpx 30rpx;
		align-items: stretch;
		line-height: 1;

		.imgbox {
			line-height: 0;
			background-color: #EE2F72;
			border-radius: 10rpx;
			overflow: hidden;
			flex-shrink: 0;
			.img {
				height: 246rpx;
				width: 246rpx;
			}
		}

		.contentbox {
			flex-wrap: wrap;

			.title {
				width: 100%;
				align-self: flex-start;
				font-size: $font-lg;
				color: $font-color-dark;
				line-height: 1.5;
			}

			.money {
				font-size: $font-lg + 4rpx;
				font-weight: bold;
				color: #EE2F72;
			}

			.oldMoneyBox {
				align-self: flex-end;
				width: 100%;

				.oldMoney {
					font-size: $font-sm;
					text-decoration: line-through;
					color: $font-color-light;
				}

				.domMoney {
					color: #B59467;
				}

				.icon {
					width: 14rpx;
					height: 16rpx;
				}

				.buttomPay {
					padding: 14rpx 26rpx;
					font-size: $font-base;
					color: #fff;
					background: linear-gradient(90deg, #FF4A8A, #FF77A7);
					border-radius: 26px;
				}
			}
		}
	}
</style>
