<template>
	<div class="xuefen">
		<div class="top">
			<div class="card">
				<div class="my_nums">我的学分：<span class="num">{{useInfo.xuefen}}</span></div>
				<image src="@/static/images/mine/icon_6.png" mode="" class="icon_6"></image>
			</div>
		</div>
		<div class="list">
			<div class="title">
				<div>记录明细</div>
				<div class="line"></div>
			</div>
			<div v-if="list.length>0">
				<div class="item" v-for="item in list" :key="item.id"  @click="recordDetail(item)">
					<image v-if="item.is_reward==1" src="@/static/images/xitong.png" mode="" class="item_icon"></image>
					<image v-if="item.is_reward==0" src="@/static/images/maihuo.png" mode="" class="item_icon"></image>
					</image>
					<div class="middle">
						<div class="name">{{item.reward_type_name}}</div>
						<div class="time">{{formatTime(item.updated_at)}}</div>
					</div>
					<div class="total_nums">+{{item.xuefen}}</div>
				</div>
			</div>
			<div class="empty_image" v-else>
				<u-empty text="暂无记录"></u-empty>
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				last: false,
				list: [],
				useInfo: {}
			}
		},
		onReachBottom() {
			if (!this.last) {
				this.page++
			}
			this.getList()
		},
		onShow() {
			this.useInfo = this.vuex_user
			this.page = 1
			this.last = false
			this.list=[]
			this.getList()
		},
		methods: {
			getList() {
				this.$u.get('/dwbs/xuefens', {
					page: this.page,
					user_id: this.vuex_user.id
				}).then(res => {
					console.log(res, 'list')
					let data = res.data.data
					if (this.page > 1 && data.length == 0) {
						uni.showToast({
							title: '暂无更多',
							icon: 'none'
						})
						this.last = true
					} else {
						this.list = this.list.concat(data)
					}
				})
			},
			//格式化时间
			formatTime(time) {
				return time.replace(/-/g, '/');
			},
			recordDetail(item) {
				if(item.is_reward==1) return
				uni.navigateTo({
					url: '/pages/xuefen/detail?id=' + item.id
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f5ff;
	}

	.top {
		background-color: #fff;
		padding: 12px;

		.card {
			padding: 7px 12px;
			display: flex;
			align-items: center;
			background: linear-gradient(270deg, #FF571B 0%, #F5222D 100%);
			border-radius: 10px;

			.my_nums {
				font-weight: 400;
				font-size: 20px;
				color: #fff;
				flex: 1;
				text-align: left;
				margin-left: 20px;

				.num {
					font-size: 22px;
				}
			}

			.icon_6 {
				width: 64px;
				height: 64px;
			}
		}
	}

	.list {
		margin-top: 4px;
		border-radius: 8px 8px 0px 0px;
		padding: 12px;
		background: #FFFFFF;

		.title {
			position: relative;
			font-size: 17px;
			color: #FB231F;
			text-align: center;

			.line {
				position: absolute;
				width: 16px;
				height: 2px;
				left: calc(50% - 8px);
				;
				bottom: -4px;
				border-radius: 2px;
				// margin: 0 auto;
				background: linear-gradient(180deg, #F30000 0%, #FE4815 100%);
			}
		}

		.item {
			display: flex;
			align-items: center;
			padding: 16px 0;
			border-bottom: 1px solid #EEEEEE;

			.item_icon {
				width: 40px;
				height: 40px;
				margin-right: 10px;
			}

			.middle {
				flex: 1;

				.name {
					font-size: 15px;
					color: #333333;
				}

				.time {
					margin-top: 8px;
					font-size: 14px;
					color: #999999;
				}
			}

			.total_nums {
				font-size: 18px;
				font-weight: 500;
				color: #FB231F;
			}
		}
	}
</style>