<template>
	<view class="integral">
		<!-- 标题栏 -->
		<view class="nav">
			<image src="http://t9.9026.com/imgs/integralbg.png" style="width: 100%; height: 100%;"></image>
			<view class="PointsColumn">
				<image src="/static/icon/integralicon.png"></image>
				<text>{{userIntegral}}</text>
			</view>
			<view class="titletext">
				<view class="textitem" @click="gointegralRecord">
					<image src="/static/icon/integralrecord.png"></image>
					<text>积分记录</text>
				</view>
				<view class="textitem" @click="goMyorder">
					<image src="/static/icon/lament.png"></image>
					<text>我的兑换</text>
				</view>
				<view class="textitem" @click="gointegralRule">
					<image src="/static/icon/integralrule.png"></image>
					<text>积分规则</text>
				</view>
			</view>
		</view>
		
		<!-- 积分商品 -->
		<view class="shopList">
			<view class="listTop">
				<text>积分兑换</text>
			</view>
			<!-- 瀑布流组件 -->
			<!-- <helang-waterfall-list 
			:status="waterfall.status"
			:list="waterfall.list"
			:reset="waterfall.reset"></helang-waterfall-list> -->
			<view class="ListContent">
				<view :class="item.short?'[contentItemShort,contentItem]':'[contentItemLong,contentItem]'" v-for="item in integralList" @click="goIntegralDetail(item.id)" >
					<image :src="item.cover_img?item.cover_img:'http://t9.9026.com/imgs/loginBg.png'" ></image>
					<view class="itemName">{{item.name}}</view>
					<view class="itemPrice">{{item.integral}}积分</view>
				</view>
			</view>
			
			<!-- 已经到底啦 -->
			<uni-load-more :status="status" color="#CCCCCC" :content-text="contentText"/>
		</view>
	</view>
</template>

<script>
	import helangWaterfallList from "components/waterfall/waterfall-list"
	export default{
		components: {
			"helang-waterfall-list": helangWaterfallList
		},
		data(){
			return{
				// 用户积分
				userIntegral:0,
				// 组件uni-load-more	
				status: 'noMore',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '——  已经到底啦  ——'
				},
				// 积分产品列表
				integralList:[],
				
				arr:[],
				// 瀑布流组件相关
				waterfall:{
					status:"success",
					reset:true,
					list:[{
						label:'中秋佳节五仁月饼，惊喜特供，限时抢购111111111111111111111111111111',
						money:8459,
						url:'http://t9.9026.com/imgs/swiper01.png',
					},{
						label:'中秋佳节五仁月饼，惊喜特供，限时抢购',
						money:8459,
						url:'http://t9.9026.com/imgs/loginBg.png',
					},{
						label:'中秋佳节五仁月饼，惊喜特供，限时抢购1111111111111111111111111111',
						money:8459,
						url:'http://t9.9026.com/imgs/Kudosbg.png',
					},{
						label:'中秋佳节五仁月饼，惊喜特供，限时抢购',
						money:8459,
						url:'http://t9.9026.com/imgs/Kudosbg.png',
					},{
						label:'中秋佳节',
						money:8459,
						url:'http://t9.9026.com/imgs/swiper01.png',
					},{
						label:'中秋佳节五仁月饼，惊喜特供，限时抢购',
						money:8459,
						url:'http://t9.9026.com/imgs/loginBg.png',
					},{
						label:'中秋佳节五仁月饼，惊喜特供，限时抢购1111111111111111111111111111',
						money:8459,
						url:'http://t9.9026.com/imgs/Kudosbg.png',
					},{
						label:'中秋佳节五仁月饼',
						money:8459,
						url:'http://t9.9026.com/imgs/Kudosbg.png',
					}],
				}
			}
		},
		onLoad() {
			this.shortLong()
			this.getProductList()
			console.log(this.$store.getters.userInfo)
			this.userIntegral=this.$store.getters.userInfo.integral
		},
		methods:{
			// 获取积分产品列表
			getProductList(){
				this.$api.product.getProducts({
					page:1,
					type:2,
				}).then(res=>{
					console.log(res,"积分产品")
					if(res.code==0){
						this.integralList=res.data.data
					}
				})
			},
			// 跳转积分规则
			gointegralRule(){
				uni.navigateTo({
					url:'/pages/my/integral/integralRule'
				})
			},
			// 跳转积分记录
			gointegralRecord(){
				uni.navigateTo({
					url:'/pages/my/integral/integralRecord'
				})
			},
			// 跳转积分产品详情
			goIntegralDetail(id){
				uni.navigateTo({
					url:'/pages/goods/goods-detail/index?id='+id
				})
			},
			// 跳转订单记录
			goMyorder(){
				uni.navigateTo({
					url:'/pages/my/myorders/orders'
				})
			},
			// 瀑布流
			shortLong(){
				console.log(typeof(this.waterfall.list))
				let arr=this.waterfall.list
				arr.forEach((item,index,arr)=>{
					if(index%4===0){
						item.short = true
					}
					if(index%4===1){
						item.long = true
					}
					if(index%4===2){
						item.long = true
					}
					if(index%4===3){
						item.short = true
					}
				})
				console.log(arr);
				this.arr=arr
			},
		}
	}
</script>

<style lang="scss" scoped>
	$pageColor:#F9F9F9;
	$bgColor:#FFFFFF;
	// flex布局居中对齐
	@mixin flexlayout {
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.integral{
		height: 100%;
		background:$pageColor ;
	}
	.nav{
		width: 750rpx;
		height: 238rpx;
		position: relative;
		.PointsColumn{
			position: absolute;
			width: 690rpx;
			border-radius: 8rpx;
			height: 74rpx;
			background: #FFFFFF;
			border-radius: $bgColor;
			left:30rpx;
			top:32rpx;
			display: flex;
			align-items: center;
			image{
				margin-left: 30rpx;
				width: 46rpx;
				height: 46rpx;
			}
			text{
				margin-left: 16rpx;
				font-size: 48rpx;
				font-family: DINAlternate-Bold, DINAlternate;
				font-weight: 500;
				color: #333333;
			}
		}
		.titletext{
			position: absolute;
			bottom:30rpx;
			left: 30rpx;
			width: 690rpx;
			height: 74rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.textitem{
				display: flex;
				align-items: center;
				image{
					width: 44rpx;
					height: 44rpx;
				}
				text{
					margin-left: 8rpx;
					font-size: 30rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: $bgColor;
				}
			}
		}
	}
	.shopList{
		margin-top: 24rpx;
		width: 750rpx;
		background: $bgColor;
		border-radius: 16rpx 16rpx 0px 0px;
		padding: 0 30rpx;
		box-sizing: border-box;
		padding-top: 32rpx;
		.listTop{
			@include flexlayout;
			margin-bottom: 40rpx;
			text{
				font-size: 36rpx;
				font-family: PingFang-SC-Bold, PingFang-SC;
				font-weight: bold;
				color: #333333;
			}
		}
		.ListContent{
			// display: flex;
			// flex-wrap: wrap;
			.contentItemShort{
				width: 332rpx;
				background: $bgColor;
				box-sizing: border-box;
				box-shadow: 0px 4rpx 8rpx 0px rgba(0,0,0,0.04);
				border-radius: 12rpx;
				display: inline-block;
				margin-bottom: 24rpx;
				image{
					width: 332rpx;
					height: 332rpx;
				}
				.itemName{
					margin:0 18rpx 20rpx 22rpx ;
					font-size: 28rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: #333333;
					overflow: hidden;
				}
				.itemPrice{
					margin-left: 22rpx;
					font-size: 28rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: #FF6200;
				}
			}
			.contentItemLong{
				width: 332rpx;
				background: $bgColor;
				box-sizing: border-box;
				box-shadow: 0px 4rpx 8rpx 0px rgba(0,0,0,0.04);
				border-radius: 12rpx;
				margin-bottom: 24rpx;
				display: inline-block;
				clear: both;
				image{
					width: 332rpx;
					height: 400rpx;
				}
				.itemName{
					margin:0 18rpx 20rpx 22rpx ;
					font-size: 28rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: #333333;
					overflow: hidden;
				}
				.itemPrice{
					margin-left: 22rpx;
					font-size: 28rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: #FF6200;
				}
			}
			.contentItem:nth-child(odd){
				margin-right: 26rpx;
			}
		}
	}
</style>