<template>
	<scroll-view class="container" scroll-y="true" @scrolltolower="handleLoadMore()">
		<view style="padding-top: 20px;background-color: transparent;" v-if="plantList.length<=0">
			<u-divider color="#909399" border-color="#909399" bg-color="transparent">没有更多了</u-divider>
		</view>
		<view class="goods-row" v-for="(item, index) in plantList" :key="index" @click="goToGoodDetail(item)">
			<image class="goods-img" :src="item.imgPath"></image>
			<view class="goods-info">
				<view class="goods-name">{{item.productName}}</view>
				<view class="goods-area">面积：{{item.areaSize}}㎡</view>
				<view class="goods-number">
					<text class="goods-icon">￥</text>
					<text class="goods-spec">{{item.bizPrice}}</text>
					<text class="goods-price">￥{{item.originalPrice}}</text>
				</view>
				<view class="goods-date">有效期：{{item.term}}天</view>
			</view>
			<view class="goods-cart">
				<view class="more-button">
					<view class="iconfont icongengduo"></view>
				</view>
			</view>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
	</scroll-view>
</template>

<script>
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	export default {
		data() {
			return {
				pageIndex: 1,
				isOver: false,
				plantList: [],
			}
		},
		onLoad() {
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.pageIndex = 1
			this.plantList = []
			this.getGoodsList('refresh')
		},
		methods: {
			//  懒加载
			handleLoadMore() {
				if (!this.isOver) {
					this.pageIndex++
					this.getGoodsList()
				}
			},
			//  获取商品
			getGoodsList(refresh) {
				NET.request(API.getPlantList, {
					pageIndex: this.pageIndex,
					pageSize: 10,
				}, 'GET').then(res => {
					if (refresh == 'refresh') {
						uni.stopPullDownRefresh();
					}
					if (res.isSuccess) {
						if (res.data.list && res.data.list.length) {
							this.isOver = res.data.list.length != 10
							this.plantList = this.plantList.concat(res.data.list)
						}
						// else {
						// 	this.$refs.uTips.show({
						// 		title: res.msg,
						// 		type: 'warning',
						// 	})
						// }
					}
				}).catch(error => {
					console.log(error)
					this.$refs.uTips.show({
						title: '获取共享种植列表失败',
						type: 'warning',
					})
				})
			},
			//  跳转详情
			goToGoodDetail(item) {
				uni.navigateTo({
					url: '/pagesGood/goodDetails?minePlant=true&goodId=' + item.id
				});
			},
		},
	}
</script>

<style>
	page {
		background-color: #f7f7f7;
	}
</style>
<style lang="less" scoped>
	page {
		width: 100%;
		height: 100%;
	}

	.container {
		width: 100%;
		height: 100%;
		float: left;
		background-color: #f7f7f7;
		overflow-y: auto;

		.goods-row:first-child {
			margin-top: 12px;
		}

		.goods-row {
			width: calc(100% - 24px);
			height: 104px;
			float: left;
			padding: 11px 11px 11px 7px;
			box-sizing: border-box;
			margin: 0 0 12px 12px;
			background: #FFFFFF;
			box-shadow: 0px 1px 5px 0px rgba(102, 102, 102, 0.43);
			border-radius: 15px;

			.goods-img {
				width: 84px;
				height: 84px;
				float: left;
			}

			.goods-info {
				width: calc(100% - 108px);
				height: 84px;
				box-sizing: border-box;
				padding-left: 6px;
				float: left;

				.goods-name {
					width: calc(100% + 24px);
					height: 20px;
					font-size: 16px;
					font-family: PingFang SC;
					color: #333333;
					line-height: 20px;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}

				.goods-area {
					height: 18px;
					margin: 6px 0 2px 0;
					line-height: 18px;
					font-size: 13px;
					font-family: PingFang SC;
					color: #666666;
				}

				.goods-number {
					height: 18px;
					font-family: PingFang SC;
					line-height: 18px;

					.goods-icon {
						font-size: 12px;
						color: #52A63A;
					}

					.goods-spec {
						font-size: 15px;
						color: #52A63A;
						margin-right: 15px;
					}

					.goods-price {
						font-size: 13px;
						text-decoration: line-through;
						color: #A67954;
					}
				}

				.goods-date {
					height: 16px;
					margin-top: 4px;
					line-height: 16px;
					font-size: 13px;
					font-family: PingFang SC;
					color: #666666;
				}

			}

			.goods-cart {
				width: 24px;
				height: 84px;
				float: left;

				.more-button {
					width: 24px;
					height: 20px;
					margin-top: 64px;

					.iconfont {
						color: #999999;
						font-size: 32px;
						line-height: 20px;
					}
				}
			}
		}
	}
</style>
