<template>
	<view>
		<u-picker v-model="showTime" mode="time" :params="params" :default-time="defaultTime" @confirm="confirmTime"></u-picker>
		<view class="top">
			<view class="value">
				<text>积分价值</text>
				<text>{{point}}</text>
			</view>
			<view class="flex justify-center align-center">
				<view class="cu-btn btn" hover-class="hoverClass1" @click="$jump('/pages/mine/my-points/accredit')">
					积分授权
				</view>
			</view>
		</view>
		<view class="data">
			<view class="left">
				<view @click.stop="showTime = true">
					<text>{{defaultTime}}</text>
					<text class="cuIcon-unfold padding-left-10"></text>
				</view>
				<!-- <view>
					<text>支出 ￥ 165.00 收入 ￥ 463.00</text>
				</view> -->
			</view>
			<view class="right">
				<text>统计</text>
				<text class="cuIcon-right"></text>
			</view>
		</view>

		<view class="card">
			<view style="display: flex;" class="cardTitle">
				<view class="area1 area-padding " style="padding-left: 40rpx;">
					<text>积分来源</text>
				</view>
				<view class="area2 area-padding">
					<text>积分数量</text>
				</view>
				<view class="area3 area-padding">
					<text>价值</text>
				</view>
			</view>
			<mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
				:up="upOption">
				<view @click="jump(item)" class="item" hover-class="hoverClass"
					v-for="(item,index) in list" :key="index">
					<view class="area1">
						<view class="item-padding">
							<image :src="item.logo" mode="aspectFit"></image>
							<view class="">
								<text>{{item.name}}</text>
								<text>{{item.updateTime}}</text>
							</view>
						</view>
					</view>
					<view class="area2 text-area ">
						<view class="item-padding">
							<image style="width: 35rpx;height: 35rpx;margin-bottom: -5rpx;"
								src="@/static/icon/points-value.png"></image>
							<text v-if="item.type==1||item.type==2" style="font-size: 32rpx;margin-left: 10rpx;color: #F39248;">+{{item.point}}</text>
							<text v-if="item.type==3" style="font-size: 32rpx;margin-left: 10rpx;color: #000000;">-{{item.point}}</text>
						</view>
					</view>
					<view class="area3 text-area ">
						<view class="item-padding" style="font-size: 34rpx;color: #000;">￥{{item.pointValue}}</view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				list:[],
				downOption:{
					auto:false
				},
				showTime:false,
				params: {
					year: true,
					month: true,
				},
				defaultTime:'',
				point:'',
				height:''
			}
		},
		onReady(){
			this.defaultTime=this.$dateTime.format(new Date(),'YYYY-mm')
			this.getElInfo()
		},
		onLoad(options) {
			if(options.point){
				this.point = options.point
			}
		},
		methods: {
			async getElInfo() {
				let rectInfo = await this.$u.getRect('.cardTitle');
				this.height = this.$u.sys().windowHeight - rectInfo.top + 'px'
			},
			jump(item){
				console.log(item);
				uni.navigateTo({
					url:'/pages/mine/bill-detail?billDetail='+JSON.stringify(item)+'&type=point'
				})
			},
			confirmTime(e){
				this.defaultTime = e.year + '-' +e.month
				this.downCallback()
			},
			upCallback(mescroll) {
				let params = {
					current:mescroll.num,
					size:mescroll.size,
					userId:this.vuex_userId,
					monthTime:this.defaultTime
				}
				if (this.defaultTime) {
					params.monthTime=this.defaultTime
				}else{
					params.monthTime=this.$dateTime.format(new Date(),'YYYY-mm')
				}
				
				try {
					this.$api.account.pointList(params).then(res => {
						let data = res.data.records
						let total = res.data.total
						mescroll.endBySize(data.length, total);
						if (mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(data); //追加新数据
					})
				} catch (e) {
					this.mescroll.endErr()
				}
			},
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
				}, 10)
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	
	.btn {
		background-color: #FC8D38;
		color: #FFFFFF;
		border-radius: 50rpx;
		border: 1rpx solid #FFFFFF;
	}
	
	.hoverClass1{
		box-shadow: 0rpx 0rpx 10rpx #DDDDDD;
	}

	.top {
		padding: 50rpx;
		background-color: #FC8D38;
		display: flex;
		justify-content: space-between;

		.value {
			display: flex;
			flex-direction: column;
			text-align: center;

			text:first-child {
				color: #FCE7D6;
				font-size: 32rpx;
			}

			text:last-child {
				padding-top: 10rpx;
				font-size: 70rpx;
				color: #FFFFFF;
			}
		}
	}

	.data {
		padding: 50rpx 0 25rpx 40rpx;
		display: flex;
		justify-content: space-between;

		.left {
			display: flex;
			flex-direction: column;

			view:first-child {
				font-size: 34rpx;
				color: #000;
				padding-bottom: 10rpx;
			}

			view:last-child {
				font-size: 26rpx;
				color: #666666;
			}
		}

		.right {
			padding-right: 20rpx;
			color: #666666;
			display: flex;
			justify-content: center;
			align-items: center;
			text-align: center;
		}
	}

	.card {
		background-color: #FFFFFF;

		.area-padding {
			padding: 40rpx 0 20rpx;
		}
		
		.text-area{
			display: flex;
			justify-content: flex-start;
			align-items: center;
		}

		.area1 {
			padding-left: 30rpx;
			width: 55%;

			view:first-child {
				display: flex;

				image {
					width: 80rpx;
					height: 80rpx
				}

				view {
					padding-left: 15rpx;
					padding-bottom: 5rpx;
					display: flex;
					flex-direction: column;

					text:first-child {
						font-size: 32rpx;
						padding-bottom: 10rpx;
						color: #000;
					}

					text:last-child {
						font-size: 22rpx;
						color: #888888;
					}
				}
			}
		}

		.area2 {
			width: 25%;
		}

		.area3 {
			width: 20%;
		}

		.item-padding {
			padding: 20rpx 0;
		}

		.item {
			padding: 5rpx;
			display: flex;
			border-bottom: 1rpx solid #DDDDDD;
		}
		
		.item:last-child{
			border: none;
		}



	}
</style>
