<template>
	<view class="back">
	  <!-- <view class="back-top"></view> -->
	  <view class="uni-radius back-con uni-shadow-sm">
	    <view class="">
	      <view class="back-con-top"> 邀请码 </view>
	      <view class="inviteCode">
				{{userInfo.inviteCode}}
	      </view>
	    </view>
		<view class="border"></view>
		<view class="">
		  <view class="back-con-top"> 微信邀请 </view>
		  <button @click="" open-type="share">点击邀请</button> 
		</view>
	  </view>
	  
	  <view>
		  <uni-list border-full v-for="(item,index) in inviteLogList" :key="index">
		    	<uni-list-item :title="item.invitedScanCode" :note="item.createTime" :thumb="item.img" thumb-size="lg" />
		    </uni-list>
		  <view class="ivOver" v-if="flag">-----已经到底啦-----</view>
	  </view>
	  
	</view>
</template>

<script>
	import {
		getInviteLog
	} from '@/api/userInfo.js'
	export default {
		data() {
			return {
				inviteLogList: [],
				pageSize: 10,
				pageNum: 1,
				userInfo: {},
				flag: false
			}
		},
		created() {
			const userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				console.log('havent userInfo')
				uni.showModal({
					content: '艺术家账户过期,请重新登录！',
					showCancel: false,
					success() {
						//没有缓存则跳转登录页面
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}
				});
			} else {
				this.userInfo = userInfo;
				console.log('have userInfo')
			}
			this.getInviteLog();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1
			this.inviteLogList = []
			this.getInviteLog();
			uni.stopPullDownRefresh()
		},
		// 上划加载更多
		onReachBottom() {
			if (this.inviteLogList.length > this.pageSize*this.pageNum-1) {
				this.flag = false;
				this.pageNum += 1
				this.getInviteLog();
			}else{
				this.flag = true;
			}
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		      console.log(res.target)
		    }
		    return {
		      title: '邀请更多',
		      path: '/pages/register/register',
		    }
		  },
		methods:{
			// 获取邀请记录
			async getInviteLog() {
				let that = this;
				const res = await getInviteLog({
					pageSize: that.pageSize,
					pageNum: that.pageNum,
					creatorId: that.userInfo.id
				})
				console.log('res', res)
				if (res.data.code === 200) {
					that.inviteLogList.push(...res.data.rows)
					console.log('inviteLogList', that.inviteLogList)
				} else {
					uni.showModal({
						content: '邀请记录加载失败！',
						showCancel: false
					});
				}
			},
		}
	}
</script>

<style lang="scss">
.back {
  width: 100%;
  height: 320px;
  position: relative;
}
.back-con {
  width: 95%;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  background-color: white;
  position: relative;
  height: 440rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}
.back2 {
  width: 100%;
}
.back-top {
  width: 100%;
  position: absolute;
  height: 240rpx;
  background: #416bdc;
}
.back-con-top {
  font-size: 40rpx;
  font-weight: 600;
  margin: 40rpx 0 30rpx 0;
  display: flex;
  justify-content: center;
}

.border {
  width: 95%;
  height: 2rpx;
  margin-top: 19rpx;
  background-color: rgb(165, 165, 165);
}	

.ivOver{
		width: 100%;
		height:100rpx;
		line-height: 100rpx;
		text-align: center;
		background: #fff;
		font-size: 20rpx;
	}	
</style>
