<template>
	<view class="safe-area-inset-bottom">
		<back v-if="backShow" :title="title"></back>
		<u-navbar v-else title-color="#fff" :border-bottom="false" title="积分明细" back-icon-color="#fff"
			:background="{'backgroundColor': vuex_theme.shopBg}"></u-navbar>
		<view class="" >
			<view class="bg-img flex justify-center align-center"
				style="background-image: url('https://music.nanyue6688.com/obsfile/29a50aaf357d45cc96033d470eb2b971-bg_mingxi@2x.png');height: 340upx;z-index: 9999999999999;">
				<view class="text-center" style="margin-top: 150upx;">
					<view style="font-size: 26upx;color: #FFFFFF;font-weight: 400;">可用积分</view>
					<view style="font-size: 58upx;margin-top: 7rpx;color: #ffffff;">
						{{$cache.get('userInfo').pufaPoint}}
					</view>
				</view>
			</view>
			<mescroll-body-diy ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback"
				@up="upCallback">
				<view class="flex justify-between align-center container " v-for="(item, index) in list" :key="index">
					<view class="padding">
						<view class="type">活动助力</view>
						<view class="time">{{item.createTime}}</view>
					</view>
					<view class="padding">
						<view class="points plus">{{item.point}} 积分</view>
					</view>
				</view>
			</mescroll-body-diy>
		</view>
	</view>
</template>

<script>
	import back from "@/components/back.vue"
	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: {
			back,
			MescrollBodyDiy,
		},
		data() {
			return {
				title: '积分明细',
				backShow: true,

				downOption: {
					auto: false
				},
				upOption:{
					auto:false
				},
				list: []
			}
		},
		onPageScroll(res) {
			if (res.scrollTop > 0) {
				this.title = ''
			} else {
				this.title = '积分明细'
			}

			if (res.scrollTop > 100) {
				this.backShow = false
			} else {
				this.backShow = true
			}
		},
		onLoad() {
			this.mescroll.resetUpScroll();
		},
		methods: {
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
				}, 800)
			},
			upCallback(mescroll) {
				try {
					let params = {
						current: mescroll.num,
						size: mescroll.size,
					}
					this.$api.points.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) {
					this.mescroll.endErr()
				} 
			}
		}
	}
</script>

<style>
	.container {
		background-color: #FFFFFF;
		border-radius: 10upx;
		margin: 20upx;
	}

	.type {
		font-size: 30upx;
		font-family: PingFang-SC-Heavy;
		font-weight: bold;
		margin-bottom: 20upx;
		color: #111111;
	}

	.time {
		font-size: 24upx;
		font-family: PingFang-SC-Medium;
		font-weight: 400;
		color: #999999;
	}

	.points {
		font-size: 28upx;
		font-family: PingFang-SC-Bold;
		color: #111111;
	}
</style>
