<template>
	<view :class="[AppTheme]" class="collection">
		<view class="guess-section">
			<view v-for="(item, index) in likeList" :key="index" class="guess-item" @click="navToDetailPage(item)">
				<u-image :src=" item.imgurl" radius="10rpx" width="332rpx" height="340rpx" :lazy-load="true"
					:fade="true" duration="300" :show-loading="true">

					<view slot="error" style="font-size: 24rpx;">加载失败</view>
				</u-image>
				<view class="border">
					<view class="name">
						<view class="pri_fle">
							<image :src="settingFile.root_img+'/static/app/imgs/home/16.png'" mode="" class="hot">
							</image>
							{{ item.goodsname }}
						</view>
					</view>
					<view class="price_num">
						<text class="price text-neutral"
							v-if="item.goodstype==0">￥{{ item.price }}/{{ item.unit }}</text>
						<text class="price text-neutral"
							v-if="item.goodstype==4">￥{{ item.copies_price }}/{{ item.unit }}</text>
						<text class="oprice text-neutral" v-if="item.goodstype==0">￥{{ item.oprice }}</text>
					</view>
				</view>
			</view>
		</view>
		<u-empty marginTop="200" v-if="likeList.length==0" text="暂无更多数据" mode="list"></u-empty>
	</view>
</template>

<script>
	import api from '@/api/mall/index.js';
	import {
		mapState
	} from 'vuex';

	export default {
		data() {
			return {
				primary: this.$theme.primary,
				collectionList: [],
				settingFile: getApp().globalData.siteinfo,
				page: 1
			}
		},
		methods: {
			/* 跳转商品详情 */
			navToDetailPage(item) {
				console.log(item)
				/* 正常商品 0 || 认养商品   */
				if (item.goodstype == 0) {
					let id = item.goodsid;
					uni.navigateTo({
						url: `/pagesD/pages/product/product?id=${id}&isc=1`
					});
				} else {
					uni.navigateTo({
						url: `/pagesA/pages/adopt/adopt?id=${item.goodsid}&isc=1`
					});
				}
			},
			getlist() {
				api.goodslikelist({
					p: this.page
				}).then(res => {
					this.collectionList = this.collectionList.concat(res.data)
				})
			}
		},
		computed: {
			...mapState(['likeList', 'hasMoreData'])
		},
		onPullDownRefresh() {
			this.$store.state.page = 1
			this.$store.commit('getLike')
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 600);
		},
		onReachBottom() {
			if (this.hasMoreData) {
				this.$store.commit('getLike')
			} else {
				// this.$u.toast('没有更多数据')
			}
		},
		onLoad() {
			this.$store.state.page = 1
			this.$store.commit('getLike')
		},
		onShow() {
			this.$store.state.page = 1
			this.$store.commit('getLike')
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
	}

	.collection {
		width: 100%;
		padding: 20rpx 0rpx 30rpx 0rpx;

		.guess-section {
			display: flex;
			flex-wrap: wrap;

			padding: 10rpx 30upx;

			.guess-item {
				display: flex;
				flex-direction: column;
				width: 48%;
				padding-bottom: 14rpx;
				box-shadow: $box-shadow;
				border-radius: 15rpx;
				margin-bottom: 28rpx;

				&:nth-child(2n + 1) {
					margin-right: 4%;
				}
			}

			.image-wrapper {
				width: 100%;
				height: 330upx;
				border-radius: 3px;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
					max-height: 330upx;
					max-width: 100%;
					opacity: 1;
					border-radius: 15rpx;
				}
			}

			.border {
				margin-top: 16rpx;
				border-radius: 8rpx;
				border-style: none;

				.name {
					width: calc(100% - 20rpx);
					margin: 0 auto;

					.name1 {
						display: flex;
						justify-content: space-around;

						.item {
							width: 138rpx;
							height: 33rpx;
							text-align: center;
							line-height: 33rpx;
							background: #fde8ea;
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: 500;
							border-radius: 5px;
						}
					}

					.pri_fle {
						width: 100%;
						height: 70rpx;
						display: flex;
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #000000;
						line-height: 36rpx;
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;

						.hot {
							position: relative;
							top: 4rpx;
							width: 34rpx;
							height: 23rpx;
							margin-right: 5rpx;
						}

						.title {
							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #000000;
							line-height: 36rpx;
							width: 100%;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
						}
					}
				}

				.price_num {
					width: calc(100% - 20rpx);
					margin: 12rpx auto;

					.price {
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: bold;
					}

					.oprice {
						margin-left: 20rpx;
						margin-right: 20rpx;
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 400;
						text-decoration: line-through;
						color: #999999;
					}

					.num {
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
					}
				}
			}
		}
	}
</style>
