<template>
	<view>
		<u-navbar leftIconSize="0" :placeholder="true" bgColor="#fff">
			<view class="u-nav-slot" slot="left">
				<text>兑换大厅</text>
			</view>
		</u-navbar>
		<view class="core">
			<view class="flex core-list">
				<navigator :url="`/pages/goods/detail?id=${ item.goodsId }`" class="core-list-item" hover-class="navigator-hover"
					v-for="(item, index) in list" :key="index">
					<view class="flex iamge-wrap">
						<image :src="item.picUrl" mode="aspectFill"></image>
					</view>
					<view class="title">{{ item.title }}</view>
					<view class="bean">
						<image src="../../static/logo.png" mode=""></image>
						<view>x{{ item.exchangePrice }}</view>
					</view>
				</navigator>
				<view class="core-list-item"></view>
			</view>
		</view>
		<custom-tab-bar :activeValue="'core'" />
	</view>
</template>

<script>
	import env from '../../config/env.js'
	import CustomTabBar from '../../components/custom-tab-bar/custom-tab-bar.vue'
	import $http from '@/utils/request.js'
	export default {
		components: {
			CustomTabBar,
		},
		data() {
			return {
				pageNum: 1,
				total: 0,
				list: [],
			};
		},
		onLoad(opthios) {
			this.getList()
		},
		onShow() {

		},
		methods: {
			getList() {
				uni.showLoading({
					title: '加载中'
				});
				let data = {
					categoryId: '',
				}
				$http.post(`/api/v1/mp/user/exchange/goods/list?pageNum=${this.pageNum}&pageSize=20`, data).then(
					res => {
						uni.hideLoading();
						if (res.code == 0) {
							res.rows.forEach(item => {
								item.picUrl = env.filePublic + item.picUrl
							})
							this.total = res.total
							this.list = this.list.concat(res.rows)
						}
					}).catch(() => {
					uni.hideLoading();
				})
			},
		},
		
		onReachBottom() {
			// 判断是否有数据
			if (this.total > this.pageNum * 20) {
				setTimeout(() => {
					++this.pageNum
					this.getList()
				}, 500)
			} else {
				uni.$u.toast('没有更多数据了')
			}
		},
	}
</script>

<style lang="scss" scoped>

</style>
<style lang="scss" scoped>
	.core {
		margin: 20rpx 0;

		&-list {
			justify-content: space-around;
			flex-wrap: wrap;

			&-item {
				width: 320rpx;
				box-sizing: border-box;
				padding: 0 14rpx;
				background-color: #FFFFFF;
				padding-bottom: 24rpx;
				border-radius: 10rpx;
				margin-bottom: 40rpx;

				.iamge-wrap {
					image {
						width: 150rpx;
						height: 200rpx;
						padding: 50rpx 0;
					}
				}

				.title {
					font-size: 24rpx;
					line-height: 40rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
				}

				.bean {
					display: flex;
					align-items: center;
					font-size: 32rpx;
					line-height: 44rpx;
					color: rgba(235, 112, 9, 100);
					margin-top: 12rpx;
					
					image {
						width: 42rpx;
						height: 42rpx;
						margin-right: 16rpx;
					}
				}
			}

			&-item:last-child {
				padding: 0;
			}
		}
	}
</style>
