<template>
	<view>
		<view class="" :style="{paddingTop:statusBarHeight+'px'}">
			<image src="/static/tabbar/my-back.png" mode="" class="width100 posia" style="top: 0;z-index: -1;" lazy-load :style="{height:newHeight+'px'}"></image>
			<view class="disac colf fon42" style="height: 42px;padding: 0 30rpx;"><view class="icon icon-return fon38 colf" @tap="goBack"></view><span @tap="goBack">每日签到</span></view>
		</view>
		<view class="" v-if="loading">
			<view class="disjcac mar-x20">
				<view class="posir disjcac" @tap="signEv">
					<image src="/static/public/icon-sign-box.png" mode="" style="width: 166rpx;height: 166rpx;" lazy-load></image>
					<view class="disjcac fc posia fon38 bold" style="color: #f37c20;">
						<image class="mar-x10" src="/static/public/icon-sign.png" mode="" style="width: 40rpx;height: 36rpx;" lazy-load></image>
						{{signText}}
					</view>
				</view>
			</view>
			<view class="pad-zy30">
				<view class="disjbac" style="background: linear-gradient(to bottom, #fefcfc 0%, #f8efed 100%);border-radius: 24rpx 24rpx 0 0;">
					<view class="disjcac fc fon24 pad-sx30 width100" :class="item.is_sign==1?'activeDay':''" v-for="(item,index) in signList" :key="index">
						<view class="">+{{parseInt(item.score)}}</view>
						<view class="mar-s10">{{item.key}}</view>
					</view>
				</view>
			</view>
			<view class="pad-zy20">
				<view class="posir bacf disac fw pad-zy10 boxshow2 pad-x30" style="z-index: 1;">
					<view class="disjbac bbot width100 pad-sx20 pad-zy30" v-for="(item,index) in dataList" :key="index">
						<view class="fon24 col-e42417">+{{parseInt(item.num)}}</view>
						<view class="fon20" style="color: #676767;" v-if="item.created_at">{{item.created_at.slice(0,10).split('-').join('.')}}</view>
					</view>
				</view>
				<view class="" v-if="moreLoading">
					<pitera :textStr="`${noMore && total > dataList.length?'上滑加载更多':'到底了'}~~`" textColor="#b0aaa9" paddingStr="40rpx 0 20rpx 0"></pitera>
				</view>
			</view>
		</view>
		<dynamic-frame ref="refFrame" :showType="showType"></dynamic-frame>
	</view>
</template>

<script>
	import dynamicFrame from '@/components/dynamic-frame.vue';
	import pitera from '@/components/nothing/pitera.vue';
	export default {
		components:{
			dynamicFrame,
			pitera
		},
		data() {
			return {
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
				newHeight:uni.getSystemInfoSync().screenHeight,
				dataList:[],// 记录列表
				signList:[],// 日期列表
				signText:'签到',
				showType:4,
				page:1,
				size:20,
				loading:false,
				noMore:false,
				moreLoading:false
			}
		},
		onLoad() {
			this.getSignInfo();
		},
		onReachBottom() {
			if(this.total!=this.dataList.length){
				this.page++;
				this.getSignList();
			} else {
				this.noMore = true;
			}
		},
		methods: {
			// 获取签到信息
			getSignInfo(){
				this.$requst.get('/api/sign/info').then(res=>{
					if(res.code==0){
						this.signList = res.data.week;
						this.signText = ['签到','已签到'][res.data.today_sign];
						this.loading = true;
						// 获取签到记录
						this.getSignList();
					}
				})
			},
			// 返回
			goBack(){
				uni.navigateBack({
					delta:1
				})
			},
			// 执行签到
			signEv(){
				this.$requst.post('/api/sign/sign').then(res=>{
					if(res.code==0){
						this.signText = "已签到";
						this.$refs.refFrame.ifLogistics = true;
						this.$refs.refFrame.ifAnimated = true;
						// 获取签到信息
						this.getSignInfo();
					}
				})
			},
			// 获取签到记录
			getSignList(){
				let params = {
					page:this.page,
					size:this.size
				}
				this.moreLoading = false;
				if(this.page==1) this.dataList = [];
				this.$requst.get('/api/user/sign-score',params).then(res=>{
					if(res.code==0){
						console.log(res,12121212)
						this.total = res.data.total;
						this.dataList = [...this.dataList,...res.data.list];
						this.moreLoading = true;
					}
				})
			}
		}
	}
</script>

<style>
	.activeDay{
		background-color: #f37717;
		color: #FFFFFF;
	}
</style>
