<template>
	<view class="container">
	  <view class="points-overview">
	    <view class="points-overview__content">
	      <view class="points-overview__label">账户积分</view>
	      <view class="points-overview__num">{{ pointsNum }}</view>
	    </view>
	    <navigator class="points-overview__action" url="/packages/user/pointsRule/index">
	      <text class="points-overview__desc">积分规则</text>
	      <image
	        style="width: 12rpx; height: 22rpx;"
	        src="https://static.hshuishang.com/User/_assets/more.primary.12x22.png"
	      >
	      </image>
	    </navigator >
	  </view>
	
	  <view class="block-divider"></view>
	
	  <view class="record-list">
	    <view
	      v-for="(item, index ) in records"
	      :key="index"
	      class="record-list-item"
	    >
	      <view class="record-list-item__content">
	        <view class="record-list-item__label">{{ item.source }}</view>
	        <view class="record-list-item__num">+{{ item.integral }}</view>
	      </view>
	      <view class="record-list-item__datetime">{{ item.create_time }}</view>
	    </view>
	  </view>
		
		<nav-footer />
	</view>
</template>

<script>
	import { request } from '../../../utils';
	import { apiArr } from '../../../api/user';
	export default {
		data() {
			return {
				count: 0,
				records: [],
				pointsNum: 0,
			}
		},
		methods: {
			async init () {
				uni.showLoading({
					title: '加载中',
				})
				const res = await request(apiArr.signIntegral,"POST", {});
				this.pointsNum = res.integral;
				await this.getSignCycle();
			},
			
			async getSignCycle () {
				const res = await request(apiArr.signCycle, 'POST', {});
				const { start_time, end_time, day_num } = res;
				this.getSignList(start_time, end_time, day_num)
			},
			
			async getSignList(startTime, endTime, dayNum) {
				const res = await request(apiArr.signList, 'POST', {
					page_num: 1,
					page_size: dayNum,
					sign_date: [startTime, endTime]
				});
				uni.hideLoading();
				this.records = res.rows;
			  },
			
		},
		onLoad() {
			this.init();
		}
	}
</script>

<style>
	@import url("./index.css");
</style>