<template>
	<view :style="vuex_skin" style="width: 100vw;overflow: hidden;">
		<!-- #ifdef MP-WEIXIN -->
		<u-navbar title-color="#fff" z-index="90" :border-bottom="false" :is-back="false" title="积分换礼"
			:background="{'backgroundColor': vuex_theme.shopBg}"></u-navbar>
		<!-- #endif -->
		<mescroll-body 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="avatar">
						</image>
						<view class="center data">
							<text style="color: #FFD7D9;">我的积分：</text>
							<text class="text-bold text-xxl">{{userData.userPufaPoint || 0}}</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" @click="$jump('/pages/introduce/notice?title=积分规则')">
							积分兑换规则
						</view>
					</view>
				</view>
			</view>
			<view class="swiper">
				<u-swiper :list="swiperList"  name="url" mode="rect" border-radius="12" height="270"></u-swiper>
			</view>
			<view class="recommend-info">
				<view class="goods-list">
					<navigator hover-class="none" :url="'detail?id='+item.id" 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 class="text-cut-1">{{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>
					</navigator>
				</view>
			</view>
		</mescroll-body>
		<login ref="login" @signIn="signIn" @phoneSuccess="phoneSuccess"></login>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				swiperList: [],
				downOption: {
					auto: false
				},
				avatar: '',
				userData: {},
				list: []
			}
		},
		onShow() {
			this.init()
		},
		onLoad() {
			this.fetchSwiperList()
		},
		methods: {
			async fetchSwiperList() {
				try {
					let {
						POINT_GOODS_SETTING
					} = (await this.$api.platform.getPlatformParams({
						keys: 'POINT_GOODS_SETTING'
					})).data.data;
					this.swiperList = JSON.parse(POINT_GOODS_SETTING).indexImageList
				} catch (e) {
					console.log(e);
				}
			},
			init() {
				this.avatar = this.$cache.get('userInfo').avatar
				this.fetchUserInfo()
			},
			fetchUserInfo() {
				if (!this.vuex_phone) {
					return
				}
				let params = {
					phone: this.vuex_phone
				}
				this.$api.loginUser.userHeatValueAndPufaPoint(params).then(res => {
					this.userData = res.data.data
				})
			},
			downCallback() {
				setTimeout(() => {
					this.fetchSwiperList()
					this.mescroll.resetUpScroll();
				}, 800)
			},
			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>


 -->
