<import name="x-page" src="../../components/page/page.ux"></import>
<template>
	<div class="sign-wrap">
		<text class="sign-tips" if="{{signToday}}">
			今日签到成功！{{signTodayFee}}书币已到账
		</text>
		<text class="sign-tips" else>
			今日还未签到,快去首页签到领奖励吧
		</text>
		<div class="sign-list" if={{showSignList}}>
			<block for="{{signList}}">
				<div class="sign-item">
					<text class="sign-fee">签到得币:{{$item.reward}}</text>
					<text class="sign-date">签到日期:{{$item.sign_time}}</text>
				</div>
			</block>
		</div>
		<x-page current="{{page.current}}" total="{{page.total}}" @prev="prev" @next="next"></x-page>
	</div>
</template>
<script>
import { getSignRecord } from "../../api/index";
export default {
	private: {
		signList: [

		],
		signToday: false,
		signTodayFee: 0,
		page: {
			total: 0,
			current: 1
		},
	},
	computed: {
		showSignList() {
			return this.signList.length > 0;
		}
	},
	onInit() {
		this.getUserRecord(1, this.getDate());
	},
	getDate() {
		let date = new Date();
		let fullYear = date.getFullYear();
		let month = date.getMonth() + 1;
		let ms = month < 10 ? "-" + "0" + month : "-" + month;
		let day = date.getDate();
		let ds = day < 10 ? "-" + "0" + day : "-" + day;
		let rs = fullYear + ms + ds;
		return rs;
	},
	async getUserRecord(page = 1, date) {
		let res = await getSignRecord({ page: page, date });
		if (res.sign_status) {
			this.signToday = true;
			this.signTodayFee = res.sign_today.reward;
		}
		let { list, meta } = res.sign_result;
		this.signList = list;
		this.page = {
			total: meta.last_page,
			current: meta.current_page
		}
	},
	prev() {
		this.getUserRecord(--this.page.current, this.getDate());
	},
	next() {
		this.getUserRecord(++this.page.current, this.getDate());
	}

}
</script>
<style lang="less">
@import "../../assets/less/sign.less";
</style>


