<template>
    <view class="mine-history">
		<scroll-view scroll-y class="history-box" @scrolltolower="reachBottom">
			<view class="item-box">
				<!-- 需求：只显示最近五十条数据　后台未作限制 -->
				<view v-for="(item, index) in historyList.slice(0, 50)" :key="index" class="history-item">
					<view class="item-title" @click="viewStoreDetails(item.store_id)">
						<image :src="item.store_avatar"></image>
						<view class="u-line-2">{{ item.store_name }}</view>
					</view>
					<image :src="item.goods_image" class="item-image" @click="viewGoodsDetails(item.goods_id)"></image>
					<view class="item-info" @click="viewGoodsDetails(item.goods_id)">
						<view class="info-name u-line-1">{{ item.goods_name }}</view>
					</view>
				</view>
			</view>
			<u-empty text="暂无足迹" mode="list" color="#000" v-if="!historyList.length"></u-empty>
			<u-loadmore :status="loadStatus" bgColor="#ECECEC" margin-bottom="20" v-if="historyList.length > 9"></u-loadmore>
		</scroll-view>
    </view>
</template>

<script>
export default {
    data() {
        return {
			historyList:  [],
			page: 1, // 默认1
			loadStatus: 'loadmore',
			timer: true,
		};
    },
    onLoad() {
		this.getBrowseList();
	},
    methods: {
		viewStoreDetails(sid) {
			this.$u.route({
				url: 'pageC/merchant/index',
				params: {
					id: sid,
				}
			})
		},
		viewGoodsDetails(id) {
			this.$u.route({
				url: 'pageB/sdetails/index',
				params: {
					id: id,
				}
			})
		},
		async getBrowseList () {
			const res = await this.$u.api.getBrowseList({ page: this.page });
			this.timer = false;
			if(res.errCode == 0) {
				this.historyList.push(...res.data.storeInfo);
			}
			return res.data.storeInfo.length;
		},
		reachBottom() {
			if(!this.timer) return false;
			this.loadStatus = "loading";
			this.page++;
			this.getBrowseList({page: this.page}).then(length => {
				if(length == 0) {
					this.page--;
					this.status = 'nomore';
				} else {
					this.status = 'loading';
				}
			}).catch(() => {
				this.loadStatus = "nomore";
				this.page--;
			})
		}
	}
};
</script>
<style lang="scss" scoped>
.mine-history {
	min-height: calc(100vh - var(--window-top));
	background: #ECECEC;
	.history-box {
		box-sizing: border-box;
		height: calc(100vh - var(--window-top));
		padding: 20rpx 30rpx 0;
		.item-box {
			display: flex;
			flex-wrap: wrap;
			.history-item {
				width: 220rpx;
				height: 290rpx;
				background: rgba(255,255,255,1);
				border-radius: 10rpx;
				padding: 20rpx 20rpx 22rpx;
				margin: 0 10rpx 20rpx 0;
				.item-title {
					display: flex;
					align-items: center;
					> image {
						width: 50rpx;
						height: 50rpx;
						border-radius: 50%;
						margin-right: 19rpx;
					}
					> view {
						font-size: 24rpx;
						color: rgba(51,51,51,1);
					}
				}
				.item-image {
					margin: 20rpx 0 17rpx;
					width: 180rpx;
					height: 140rpx;
					border-radius: 10rpx;
				}
				.item-info {
					display: flex;
					justify-content: space-between;
					align-items: center;
					.info-name {
						margin-right: 10rpx;
						flex: 1;
						font-size: 22rpx;
						color: rgba(51,51,51,1);
					}
					> image {
						width: 37rpx;
						height: 8rpx;
					}
				}
			}
		}
		
	}
}
</style>
