<template>
	<view class="content">
		<view class="content-money">
			<view class="status_bar"><!-- 这里是状态栏 --></view>
			<view class="body-title">
				<view class="goback-box" @click="toBack">
					<image class="goback" src="../../static/icon/fanhui.png" mode=""></image>
				</view>
				<view class="header">提货积分</view>
			</view>
			<view class="content-bg">
				<image src="../../static/img/gssy.png" mode=""></image>
			</view>
			<view class="money-box">
				<view class="money">{{ userInfo.good_integral }}</view>
				<view>余额</view>
			</view>
		</view>
		<view class="titlebox flex-center padding-t-30 padding-b-30">
			<view class="rich">
				<view class="richmin  left">
		
				</view>
			</view>
			<view class="name">
				产品交付区
			</view>
			<view class="rich right">
				<view class="richmin  right">
		
				</view>
			</view>
		</view>
		<scroll-view :style="{ height: maxheight }" class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<!-- 空白页 -->
			<empty v-if="orderList.length === 0"></empty>

			<!-- 订单列表 -->
			<view v-else>
				<view class="list">
					<view v-for="(item, index) in orderList" :key="index" class="priduct-item">
						<view class="priduct-main-image">
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<!-- <text class="title clamp">{{ item.title }}</text> -->
						<view class="priduct-main-name clamp2 margin-c-20">{{ item.title }}</view>
						<view class="priduct-main-price">
							<view class="price">
								<image class="instip" src="../../static/icon/quick1.png" mode="scaleToFill"></image>
								<text class="padding-l-10">
									{{ item.good_integral }}
								</text>
								<text class="font-size-sm">
									积分
								</text>
							</view>
						</view>
						<view class="priduct-main-price">
							<view class="price">
								+
								<text class="padding-l-10">
									{{ item.integral }}
								</text>
								<text class="font-size-sm">
									趣豆
								</text>
							</view>
						</view>
						<view class="flex padding-l-20 padding-b-20">
						<view class="buttom" @click="openPay(item)">
							立即提货
						</view>
						</view>
					</view>
				</view>
				<uni-load-more :status="loadingType"></uni-load-more>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		good_exchange
	} from '@/api/wallet.js';
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		getUserInfo
	} from '@/api/user.js';
	import uniLoadMore from '@/uview-ui/components/u-loadmore/u-loadmore.vue';
	import empty from '@/uview-ui/components/u-empty/u-empty.vue';
	export default {
		filters: {
			getMoneyStyle
		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		components: {
			empty,
			uniLoadMore
		},
		data() {
			return {
				loadingType: 'more',
				orderList: [],
				page: 1, //当前页数
				limit: 10, //每次信息条数
				maxheight: 0
			};
		},
		filters: {
			moneyNum(value) {
				return +value;
			}
		},
		onReady(res) {
			var _this = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.list-scroll-content').boundingClientRect().exec(function(res) {
						_this.maxheight = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', _this.height);
					});
				},
				fail: res => {}
			});
		},
		onShow() {
			this.loadData();
			this.getUserInfo();
		},
		methods: {
			...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
			getUserInfo() {
				getUserInfo({})
					.then(({
						data
					}) => {
						this.setUserInfo(data);
					})
					.catch(e => {
						console.log(e);
					});
			},
			openPay(item){
				uni.navigateTo({
					url:"./goodProduct?id="+item.id
				})
				// uni.showModal({
				// 	title: '支付提示',
				// 	content: `是否立即兑换兑换`,
				// 	cancelText: '取消',
				// 	confirmText: '兑换',
				// 	success: res => {
				// 		if(res.confirm){
							
				// 		}
				// 	},
				// });
			},
			// 转换金额为数字
			moneyNum(value) {
				return +value;
			},
			// 页面跳转
			navto(e) {
				uni.navigateTo({
					url: e
				});
			},
			// 点击返回 我的页面
			toBack() {
				uni.navigateBack({});
			},
			//获取收入支出信息
			async loadData(source) {
				let obj = this;
				good_exchange({
						page: obj.page,
						limit: obj.limit
					})
					.then(({
						data
					}) => {
						obj.orderList = obj.orderList.concat(data);
						// console.log(navItem.orderList);
						obj.page++;
						if (obj.limit == data.length) {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							obj.loadingType = 'more';
							return;
						} else {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							obj.loadingType = 'noMore';
						}
						uni.hideLoading();
					})
					.catch(e => {
						console.log(e);
					});
			},

			//swiper 切换
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				this.loadData('tabChange');
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #f1f1f1;
		height: 100%;
	}

	.titlebox {

		.rich {
			width: 20rpx;
			height: 20rpx;
			background: #FFA5A5;
			border-radius: 50%;
			position: relative;

			.richmin {
				width: 14rpx;
				height: 14rpx;
				border-radius: 50%;
				border: 1px solid #333333;

				&.left {
					position: absolute;
					left: -4rpx;
					bottom: -4rpx;
				}

				&.right {
					position: absolute;
					right: -4rpx;
					bottom: -4rpx;
				}
			}
		}

		.name {
			color: #FF6B2E;
			font-weight: 500;
			font-size: 33rpx;
			padding: 0 40rpx;
		}
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.content-money {
		position: relative;
		height: 400rpx;

		.content-bg {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			width: 750rpx;
			height: 400rpx;

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

		.body-title {
			height: 80rpx;
			text-align: center;
			font-size: 35rpx;
			position: relative;

			.header {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #fffeff;
				height: 80rpx;
				font-size: 36rpx;
				font-weight: 700;
				z-index: 9;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.goback-box {
				position: absolute;
				left: 18rpx;
				top: 0;
				height: 80rpx;
				display: flex;
				align-items: center;
			}

			.goback {
				z-index: 100;
				width: 34rpx;
				height: 34rpx;
			}
		}
	}

	.money-box {
		position: relative;
		z-index: 2;
		padding-top: 90rpx;
		color: #ffffff;
		text-align: center;

		.money {
			font-size: 72rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #ffffff;
		}

		.text {
			font-size: 30rpx;
		}
	}

	.list {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		padding: 0 32rpx;

		.priduct-item {
			width: 48%;
			background-color: #ffffff;
			border-radius: 12rpx;
			margin-bottom: 24rpx;

			&:nth-child(2n + 1) {
				margin-right: 24rpx;
			}
			.buttom{
				color: #fffeff;
				background-color:#FF6B2E ;
				padding: 6rpx 20rpx;
				border-radius: 100rpx;
			}
			.priduct-main-image {
				width: 100%;
				height: 330rpx;
				// background: red;
				border-radius: 3px;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
					opacity: 1;
					border-radius: 12rpx 12rpx 0 0;
				}
			}

			.priduct-main-name {
				font-size: $font-base;
				color: $font-color-dark;
				font-weight: bold;
				height: 3em;
			}

			.priduct-main-price {
				display: flex;
				justify-content: space-between;
				padding: 0 16rpx 12rpx;

				.price {
					font-size: 36rpx;
					font-weight: bold;
					color: #FF6B2E;
					.instip{
						width: 30rpx;
						height: 30rpx;
					}
				}
			}
		}
	}
</style>