<template>
	<view class="common_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title="我的爱心值" bgColor="transparent"></cus-header>
		<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/24/19f555c2-ee0a-437b-8871-42b5605f8a8b.png" class="top_bg_img" mode="widthFix"></image>
		<div class="top">
			<div class="num">{{loveValue}}</div>
			<div class="text">我的爱心值</div>
		</div>
		<div class="list" v-if="list.length">
			<up-list @scrolltolower="scrolltolower" style="height: 100%;">
				<up-list-item v-for="(item, index) in list" :key="index">
					<div class="list-item">
						<div class="time">{{item.createDate||''}}</div>
						<div class="content adfacjb">
							<div class="left adfac">
								<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/24/d5b79c0e-bcda-49ff-8cc5-5f6275b6bac1.png"></image>
								<div class="texts">
									<div class="p">{{transactionTypeDict[item.transactionType]||''}}</div>
									<div class="p tip">{{'报名参与公益实践活动'}}</div>
								</div>
							</div>
							<div class="right adfac">
								<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/24/9d038c9c-268c-44ae-a396-949039c77f47.png" v-if="item.capitalFlow==2"></image>
								<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/24/b6cbd075-f008-448a-ac9f-074787d08924.png" v-else></image>
								<text :class="{'black':item.capitalFlow==2,'red':item.capitalFlow==1}">{{item.capitalFlow==2?'':'+'}}</text>
								<text :class="{'black':item.capitalFlow==2,'red':item.capitalFlow==1}">{{item.loveQuantity??0}}</text>
							</div>
						</div>
					</div>
				</up-list-item>
			</up-list>
		</div>
		<div class="dataEmpty" v-else>
			<page-empty text="暂无爱心值记录"></page-empty>
		</div>
	</view>
</template>

<script setup name="">
	import CusHeader from '@/components/CusHeader/index.vue'
	import PageEmpty from '@/components/pageEmpty/index.vue'
	import { onLoad } from '@dcloudio/uni-app'
	import { ref, getCurrentInstance } from 'vue'
	const { proxy } = getCurrentInstance()
	
	const queryParams = ref({
		page:1,
		limit:10,
		userId:''
	})
	const transactionTypeDict = ref({
		1:'渠道导入',
		2:'公益捐赠'
	})
	const loveValue = ref(0)
	const isOver = ref(false)
	const list = ref([])
	
	const scrolltolower = () => {
		if(isOver.value) return
		getList()
	}
	
	const getList = () => {
		proxy.$api.get('/core/love/value/record/loveValueList',queryParams.value).then(({data:res})=>{
			if(res.code!==0) return proxy.$showToast(res.msg)
			list.value= [...list.value,...res.data.list];
			queryParams.value.page++
			if(res.data.list.length===0) isOver.value = true;
		})
	}
	
	onLoad(options=>{
		loveValue.value = options.loveValue??0;
		queryParams.value.userId = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
		getList()
	})
</script>

<style scoped lang="scss">
	.common_page{
		padding-bottom: 20rpx;
		box-sizing: border-box;
		.top{
			padding: 93rpx 64rpx 0;
			height: 296rpx;
			box-sizing: border-box;
			position: relative;
			.num{
				font-family: DINAlternate, DINAlternate;
				font-weight: bold;
				font-size: 88rpx;
				color: #151B29;
				line-height: 103rpx;
			}
			.text{
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #151B29;
				line-height: 30rpx;
				margin-top: 11rpx;
			}
		}
		.list{
			position: relative;
			flex: 1;
			overflow-y: auto;
			width: calc(100% - 48rpx);
			margin: 0 auto;
			background: #FFFFFF;
			border-radius: 24rpx;
			padding: 6rpx 24rpx 40rpx;
			box-sizing: border-box;
			&-item{
				padding: 36rpx 0;
				border-bottom: 1rpx solid #E7E7E7;
				.time{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #989998;
					line-height: 24rpx;
				}
				.content{
					margin-top: 36rpx;
					.left{
						flex: 1;
						image{
							width: 64rpx;
							height: 64rpx;
						}
						.texts{
							margin-left: 20rpx;
							.p{
								font-family: PingFangSC, PingFang SC;
								font-weight: 400;
								font-size: 32rpx;
								color: #151B29;
								line-height: 32rpx;
								&.tip{
									font-size: 24rpx;
									color: #676775;
									line-height: 24rpx;
									margin-top: 20rpx;
								}
							}
						}
					}
					.right{
						width: 200rpx;
						justify-content: flex-end;
						image{
							width: 24rpx;
							height: 22rpx;
							margin-right: 10rpx;
						}
						text{
							font-family: DINAlternate, DINAlternate;
							font-weight: bold;
							font-size: 36rpx;
							line-height: 42rpx;
							&.black{
								color: #151B29;
							}
							&.red{
								color: #F4657A;
							}
						}
					}
				}
			}
		}
	}
</style>