<template>
	<view :style="vuex_skin">
		<u-navbar title-color="#fff" z-index="90" :border-bottom="false" :is-back="false" title="积分商城"
			:background="{'backgroundColor': vuex_theme.shopBg}"></u-navbar>

		<mescroll-body-diy ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback"
			@up="upCallback">
			<view class="bg-card">
				<view class="info" style="display: flex;justify-content: space-between;">
					<view class="flex" v-if="vuex_userId">
						<image style="width: 90rpx;height: 90rpx;border-radius: 50%;" :src="$cache.get('userInfo').avatar">
						</image>
						<view class="center data">
							<text style="color: #FFD7D9;">我的积分：</text>
							<text class="text-bold text-xxl">{{$cache.get('userInfo').pufaPoint}}</text>
						</view>
					</view>
					<view class="flex" v-else @click="showLogin">
						<image style="width: 90rpx;height: 90rpx;border-radius: 50%;" src="/static/icon/unlogin.png">
						</image>
						<view class="center data">
							<text style="color: #FFFFFF;font-weight: 800;">点击授权登录</text>
						</view>
					</view>
					<view class="center" style="margin-right: -30rpx;">
						<view class="cu-btn round sm rule">
							积分规则
						</view>
					</view>
				</view>
			</view>
			<view class="swiper">
				<u-swiper :list="swiperList" border-radius="12" height="250"></u-swiper>
			</view>
			<view class="recommend-info">
				<view class="goods-list">
					<view class="list" v-for="(item,index) in list" :key="index">
						<view class="pictrue">
							<image :src="item.imgUrl"></image>
						</view>
						<view class="title-tag" style="text-align: center;font-weight: 800;">
							<text>{{item.name}}</text>
						</view>
						<view class="price-info">
							<view class="user-price">
								<text class="min">￥</text>
								<text class="max">{{item.point}}积分</text>
							</view>
						</view>
						<view class="bottom padding-top-20">
							<button class="cu-btn round text-white bg-base"
								style="width: 140upx;height: 50upx;">兑换</button>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body-diy>
		<login ref="login" @signIn="signIn" @phoneSuccess="phoneSuccess"></login>
	</view>
</template>

<script>
	import MescrollBodyDiy from "@/uni_modules/mescroll-uni/components/mescroll-diy/xinlang/mescroll-body.vue";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		components: {
			MescrollBodyDiy,
		},
		data() {
			return {
				swiperList: [
					'https://guosen-bucket-ldt.obs.cn-south-1.myhuaweicloud.com:443/a20288db71c24a8983801f0c0cd66ea8-bg.jpg'
				],

				downOption: {
					auto: false
				},
				top: 0,
				list: []
			}
		},
		methods: {
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
				}, 1000)
			},
			upCallback(mescroll) {
				try {
					let params = {
						current: mescroll.num,
						size: mescroll.size,
					}
					this.$api.pointgoods.list(params).then(res => {
						let data = res.data.data.records
						let total = res.data.data.total
						mescroll.endBySize(data.length, total);
						if (mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(data); //追加新数据
					})
				} catch (e) {
					console.error(e);
					this.mescroll.endErr()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.rule {
		background-color: var(--shopRule);
		color: #FFFFFF;
		padding: 20rpx 40rpx 20rpx 30rpx;
	}

	.bg-card {
		// position: relative;
		width: 100vw;
		height: 260rpx;
		background-color: var(--shopBg);
		border-radius: 0 0 10% 10%;

		.info {
			display: flex;
			padding: 30rpx 0rpx 0rpx 40rpx;

			.data {
				color: #FFFFFF;
				margin-left: 10rpx;
			}
		}
	}

	.swiper {
		margin-top: -120rpx;
		padding: 0 20rpx;
	}

	/* 为你推荐 */
	.recommend-info {
		padding-top: 30rpx;
		width: 100%;
		border-radius: 20rpx;

		.recommend-title {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 100rpx;

			.title {
				display: flex;
				align-items: center;

				image {
					width: 416rpx;
					height: 40rpx;
				}
			}
		}

		.goods-list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 0 20rpx;

			.list {
				width: 49%;
				height: 550rpx;
				margin-bottom: 20rpx;
				background-color: #FFFFFF;
				border-radius: 12rpx;
				overflow: hidden;

				.pictrue {
					display: flex;
					justify-content: center;
					width: 100%;

					image {
						width: 100%;
						height: 340rpx;
					}
				}

				.title-tag {
					// display: flex;
					height: 70rpx;
					padding: 20rpx;
				}

				.price-info {
					display: flex;
					flex-wrap: wrap;
					align-items: center;
					justify-content: center;
					padding: 0 20rpx;
					height: 50rpx;

					.user-price {
						display: flex;
						justify-content: center;
						align-items: center;

						text {
							color: #e72226;
						}

						.min {
							font-size: 24rpx;
						}

						.max {
							font-size: 32rpx;
						}
					}

					.vip-price {
						padding-left: 20rpx;
						display: flex;
						align-items: center;

						image {
							width: 26rpx;
							height: 26rpx;
							margin-right: 10rpx;
						}

						text {
							text-decoration: line-through;
							color: #8c8c8c;
							font-size: 24rpx;
						}
					}
				}

				.bottom {
					margin: 10rpx 0;
					display: flex;
					justify-content: center;
					align-items: flex-end;
				}
			}
		}
	}
</style>


<!-- <template>
	<view :style="vuex_skin">
		<mescroll-body-diy ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback"
			@up="upCallback">
			

			
			

		</mescroll-body-diy>
	</view>
</template>
<script>
	import MescrollBodyDiy from "@/uni_modules/mescroll-uni/components/mescroll-diy/xinlang/mescroll-body.vue";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				
				downOption: {
					auto: false
				},
				list: [],
			}
		},
		methods: {
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
				}, 1000)
			},
			upCallback(mescroll) {
				try {
					let params = {
						current: mescroll.num,
						size: mescroll.size,
					}
					this.$api.pointgoods.list(params).then(res => {
						let data = res.data.data.records
						let total = res.data.data.total
						mescroll.endBySize(data.length, total);
						if (mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(data); //追加新数据
					})
				} catch (e) {
					console.error(e);
					this.mescroll.endErr()
				}
			}
		}
	}
</script>


 -->
