<template>
	<view>
		<view class='sign-record'>
		   <view class='list' v-for="(item,index) in growthList" :key="index">
		      <view class='item'>
		         <view class='data'>{{item.month}}</view>
		         <view class='listn'>
		            <view class='itemn acea-row row-between-wrapper' v-for="(itemn,indexn) in item.list" :key="indexn">
		               <view>
		                  <view class='name line1'>{{itemn.title}}</view>
		                  <view>{{itemn.create_time}}</view>
		               </view>
		               <view class='num font-color'>+{{itemn.number}}</view>
		            </view>
		         </view>
		      </view>
		   </view>
		    <view class='loadingicon acea-row row-center-wrapper'>
		      <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadtitle}}
		    </view>
		</view>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
	</view>
</template>

<script>

	import { growthValueRecord } from '@/api/user.js';
	 import { mapGetters } from "vuex";
	 import authorize from '@/components/Authorize';
  import spread from "../../../libs/spread";
	export default {
		components: {
			authorize
		},
		data() {
			return {
				loading:false,
				loadend:false,
				loadtitle:'加载更多',
				page:1,
				limit:8,
				growthList:[],
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false //是否隐藏授权
			};
		},
		computed: mapGetters(['isLogin','uid']),
		onLoad(options){
			if(this.isLogin){
				this.getGrowthListList();
			}else{
				this.isAuto = true;
                this.isShowAuth = true
			}

      // 关系处理
      if(options.spread) spread(options.spread, this.isLogin)
		},
		onReachBottom: function () {
		    this.getGrowthListList();
		  },
		methods: {
			  /**
			   *
			   * 授权回调
			  */
			  onLoadFun:function(){
				this.isShowAuth = false;
				this.getGrowthListList();
			  },
			  // 授权关闭
			  authColse:function(e){
			  	this.isShowAuth = e
			  },
			  /**
			     * 获取签到记录列表
			    */
			    getGrowthListList:function(){
			      let that=this;
			      if(that.loading) return;
			      if(that.loadend) return;
				  that.loading = true;
				  that.loadtitle = "";
			      growthValueRecord({ page: that.page, limit: that.limit }).then(res=>{
			        let list = res.data;
			        let loadend = list.length < that.limit;
			        that.growthList = that.$util.SplitArray(list, that.growthList);
					that.$set(that,'growthList',that.growthList);
					that.loadend = loadend;
					that.loading = false;
					that.loadtitle = loadend ? "哼😕~我也是有底线的~" : "加载更多"
			      }).catch(err=>{
					that.loading = false;
					that.loadtitle = '加载更多';
			      });
			    },
		},
    // #ifdef MP
    // 分享给好友
    onShareAppMessage () {
      let pages = getCurrentPages();
      let page = pages[pages.length - 1]
      let shareData = {
        title: '成长值记录',
        path: page.$page.fullPath || '/' + page.route,
      };
      // 判断：用户是否登录  已经登录则添加分享人信息，未登录则正常分享
      if (this.isLogin) shareData.path = shareData.path + '?spread=' + this.uid;
      // 返回最终的分享配置信息
      return shareData
    },
    // 分享到朋友圈
    onShareTimeline() {
      let shareData = {
        title: '成长值记录',
        query: {},
      };
      // 判断：用户是否登录  已经登录则添加分享人信息，未登录则正常分享
      if (this.isLogin) shareData.query.spread = this.uid;
      // 返回最终的分享配置信息
      return shareData
    },
    // #endif
	}
</script>

<style>
</style>
