<template>
	<view :style="vuex_skin">
		<!-- #ifdef MP-WEIXIN -->
		<view class="navbar">
			<u-navbar title-color="#000000" :is-back="true" title="我的作品"></u-navbar>
		</view>
		<!-- #endif -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback"
			@up="upCallback">
			<image :src="cover" style="width: 100vw;" mode="widthFix"></image>
			<view class="head">
				<image :src="userInfo.avatar" mode="" class="avatar"></image>
				<view style="margin: 0 30upx 30upx 70upx;">
					<view class="flex align-center">
						<view class="text-black text-bold text-xl padding-right">{{userInfo.nickName}}</view>
					</view>
					<view class="flex align-center margin-top-20">
						<view>
							<text class="text-sm">共获热力</text>
							<text class="cuIcon-hotfill padding-lr-xs text-base"></text>
							<text class="text-lg text-bold">{{totalHeatValue}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="margin-top bg-white">
				<view class="padding-30 flex justify-start align-center">
					<view class="margin-left-sm text-lg text-black text-bold">我的作品</view>
				</view>
			</view>
			<view @click.stop="$jump('/pages/activity/activityDetail?id='+item.id+'&isCustomBack=false')" v-for="(item, index) in list" :key="index">
				<view class="flex bg-white" style="padding:10rpx 30rpx 30rpx">
					<view class="">
						<image :src="item.imgUrl" style="width: 120upx;height: 120upx;margin-right: 20upx;" mode="aspectFill"></image>
					</view>
					<view style="width: 100%;">
						<view class="flex justify-between margin-bottom-10">
							<view class="music" style="width: 75%">
								<view class="name text-cut-1" style="height: 34rpx;">{{item.title}}</view>
								<view style="margin: 20rpx 20rpx 20rpx 0;">
									<rich-text class="desc text-cut-2 "
										style="font-size: 24rpx;font-weight: 400;color: #969696;"
										:nodes="decodeURIComponent(item.content)"></rich-text>
								</view>
							</view>
							<view class="" style="width: 20%;">
								<view class="text-base center">
									<text class="cuIcon-hotfill padding-right-xs"></text>
									<text class="text-lg text-bold">{{item.heatValue}}</text>
								</view>
								<view class="music-rank">NO.{{item.rank}}</view>
							</view>
						</view>
						<view class="">
							<u-line color="#cacaca"></u-line>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				downOption: {
					auto: false
				},
				cover: '',
				userInfo: {},
				totalHeatValue:0,
				list: []
			}
		},
		onLoad(options) {
			this.fetchUserInfo()
			this.fetchCover()
		},
		methods: {
			async fetchCover() {
				this.cover=this.vuex_active_setting.myProductImage
			},
			fetchUserInfo() {
				if (this.$cache.get('userInfo')) {
					this.userInfo = this.$cache.get('userInfo')
					return
				}
				let params = {
					id: this.vuex_userId
				}
				this.$api.loginUser.detail(params).then(res => {
					this.userInfo = res.data.data
				})
			},
			fetchMyTotalHeatValue(){
				let params={
					phone: this.vuex_phone || '-1'
				}
				this.$api.activity.getMyTotalHeat(params).then(res=>{
					this.totalHeatValue=res.data.data || 0
				})
			},
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
				}, 1000)
			},
			upCallback(mescroll) {
				console.log(mescroll.num);
				if (mescroll.num==1) {
					this.fetchMyTotalHeatValue()
				}
				try {
					let params = {
						current: mescroll.num,
						size: mescroll.size,
						phone: this.vuex_phone || '-1'
					}
					this.$api.activity.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) {
					console.error(e);
					this.mescroll.endErr()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.head {
		background-color: #ffffff;
		margin-top: -10upx;
		height: 220upx;
		border-radius: 26upx 26upx 0 0;
	}

	.avatar {
		border-radius: 50%;
		width: 120upx;
		height: 120upx;
		margin: -50upx 0 30upx 80upx;
	}

	.rank {
		display: flex;
		justify-content: center;
		background-color: #583be6;
		width: 40%;
		color: #ffffff;
		border-radius: 16upx;
		line-height: 60upx;
	}

	.music {
		.name {
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333;
			padding-bottom: 20upx;
		}

		.author {
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #9A9A9A;
		}
	}

	.music-rank {
		display: flex;
		margin-top: 18upx;
		line-height: 40upx;
		justify-content: center;
		border: #9d9d9d 1px solid;
		color: #9d9d9d;
		border-radius: 50upx;
		font-style: italic;
	}
</style>
