<template>
	<view class="main">
		<!-- nav -->
		<navigation>{{ i18n.DonateRecord }}</navigation>
		<view class="body">
			<view class="card" v-for="(item, index) in userInfoObj" :key="index">
				<u-icon class="icon" :name="'../../static/me/img_donate.png'" size="64rpx" width="64rpx"></u-icon>
				<view class="content">
					<key-value-row class="title" :keyName="item.title" :value="item.amount" :leftColor="'#fff'"
						:rightColor="'#F2FE8D'">
					</key-value-row>
					<view class="date">{{item.timestr}}</view>
				</view>
			</view>
		</view>
		<u-empty :text="i18n.Dataisempty" mode="data" v-if="userInfoObj.length==0"></u-empty>
		<u-loadmore :status="loadStatus" :loading-text="loadingText" :loadmore-text="loadmoreText"
			:nomore-text="nomoreText" v-if="userInfoObj.length" height="80" />
	</view>
</template>

<script>
	import api from '@/utils/api'
	import KeyValueRow from '../../components/KeyValueRow/KeyValueRow.vue';
	export default {
		components: {
			KeyValueRow
		},
		name: "donateRecord",
		data() {
			return {
				isLoadMore: false, //是否加载中
				loadStatus: 'loadmore',
				loadingText: this.$t("login").toload,
				loadmoreText: this.$t("login").pullup,
				nomoreText: this.$t("login").Nomore,
				form: {
					pageNumber: 1,
					pageSize: 20,
				},
				userInfoObj: [],
			};
		},
		computed: {
			i18n() {
				return this.$t("me");
			},
		},
		onReachBottom() {
			if (!this.isLoadMore) {
				this.form.pageNumber += 1
				this.getList();
			}
		},
		onLoad() {
			this.getList()
		},
		onShow() {},
		methods: {
			getList() {
				this.isLoadMore = true
				api.charityRecord(this.form).then(res => {
					if (res.content.length) {
						if (this.form.pageNumber > 1) {
							this.userInfoObj = this.userInfoObj.concat(res.content)
							for (var i = 0; i < this.userInfoObj.length; i++) {
								if (this.userInfoObj[i].addTime) {
									this.userInfoObj[i].timestr = this.$index.formatyymmddhhmmss(this.userInfoObj[
										i].addTime)
								}
							}
						} else {
							this.userInfoObj = res.content
							for (var i = 0; i < this.userInfoObj.length; i++) {
								if (this.userInfoObj[i].addTime) {
									this.userInfoObj[i].timestr = this.$index.formatyymmddhhmmss(this.userInfoObj[
										i].addTime)
								}
							}
						}
						if (this.userInfoObj.length >= Number(res.totalElements)) { // 判断接口返回数据量小于请求数据量，则表示此为最后一页
							this.isLoadMore = true
							this.loadStatus = 'nomore'
						} else {
							this.isLoadMore = false
						}
					} else {
						this.isLoadMore = true
						this.loadStatus = 'nomore'
						// this.userInfoObj = []
					}

					this.$forceUpdate()
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.main {

		.body {
			overflow: hidden;
			margin-top: 200rpx;
			padding: 0 32rpx;

			.card {
				height: 148rpx;
				position: relative;
				background: #211F32;
				border-radius: 32rpx;
				display: flex;
				flex-wrap: wrap;
				margin-top: 32rpx;

				.icon {
					margin: -20rpx 12rpx 0 20rpx;
					border-radius: 20rpx;
				}

				.content {
					width: 558rpx;

					.title {
						width: 558rpx;
						height: 36rpx;
						line-height: 36rpx;
						margin-top: 32rpx;
						font-size: 28rpx;

						/deep/.u-text__value {
							font-weight: 600 !important;
						}

					}

					.date {
						width: 558rpx;
						height: 36rpx;
						line-height: 36rpx;
						font-size: 28rpx;
						margin-top: 12rpx;
						color: #A1A0A8;
					}
				}



			}

		}

	}
</style>
