<template>
	<view class="common_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title="我的爱心值" bgColor="transparent"></cus-header>
		<image src="https://oss.familydaf.cn/sxsnfile/20251218/812f9cd7c1cf4c1b82853f3a6266e93a.png" class="top_bg_img" mode="widthFix"></image>
		<view class="top">
			<view class="num">{{loveValue}}</view>
			<view class="text">{{isFamilyMember?'使用爱心值':'剩余爱心值'}}</view>
		</view>
		<view class="list" v-if="list.length">
			<up-list @scrolltolower="scrolltolower" style="height: 100%;">
				<up-list-item v-for="(item, index) in list" :key="index">
					<view class="list-item">
						<view class="time">{{item.createDate||''}}</view>
						<view class="content adfacjb">
							<view class="left adfac">
								<image src="https://oss.familydaf.cn/sxsnfile/20251218/9ac66362a57b4c6d94ddbc9538735be7.png"></image>
								<view class="texts">
									<view class="p" v-if="item.transactionType==1">导入爱心值</view>
									<view class="p" v-else>{{item.activityName||''}}</view>
									<view class="p tip">{{item.memberName||''}}</view>
								</view>
							</view>
							<view class="right adfac">
								<image src="https://oss.familydaf.cn/sxsnfile/20251218/cdb8e97d40e44618ac38ad0e96f25cc0.png" v-if="item.type==2"></image>
								<image src="https://oss.familydaf.cn/sxsnfile/20251218/b349d32d69ab4b0eb70d6731d37197f8.png" v-else></image>
								<text :class="{'black':item.type==2,'red':item.type==1}">{{item.type==2?'':'+'}}</text>
								<text :class="{'black':item.type==2,'red':item.type==1}">{{item.loveQuantity||0}}</text>
							</view>
						</view>
					</view>
				</up-list-item>
			</up-list>
		</view>
		<view class="dataEmpty" v-else>
			<page-empty text="暂无爱心值记录"></page-empty>
		</view>
	</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:'',
		memberId:''
	})
	const transactionTypeDict = ref({
		1:'导入爱心值',
		2:'参与献爱心'
	})
	const loveValue = ref(0)
	const isOver = ref(false)
	const list = ref([])
	const isFamilyMember = ref(false)
	
	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];
			list.value.forEach(l=>{
				if(!l._formatted) {
					l.createDate = new Date(l.createDate).Format('yyyy.MM.dd hh:mm:ss')
					l.type = l.loveQuantity>=0?1:2 //1增加 2减少
					l._formatted = true
				}
			})
			queryParams.value.page++
			if(res.data.list.length===0) isOver.value = true;
		})
	}
	
	onLoad(options=>{
		isFamilyMember.value = uni.getStorageSync('isFamilyMember')?true:false;
		loveValue.value = options.loveValue??0;
		queryParams.value.userId = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
		if(uni.getStorageSync('familyMemberInfo')) queryParams.value.memberId = JSON.parse(uni.getStorageSync('familyMemberInfo')).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;
								&.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>