<template>
	<view>

		<view class="index">
			<view class="index-content">
				<view class="index-content-item">
					<view class="index-content-item-nav baiyin-flex baiyin-flex-c-b">
						<text></text>
						<view>邀请新用户享受下单折扣</view>
					</view>
					<view class="index-content-item-li">1.成功邀请3位新用户,可享一单9折优惠</view>
					<view class="index-content-item-li">2.成功邀请5位新用户,可享两单9折优惠</view>
					<view class="index-content-item-li">3.成功邀请10位新用户,可享三单9折优惠</view>
				</view>
				<view class="index-content-item">
					<view class="index-content-item-nav baiyin-flex baiyin-flex-c-b">
						<text></text>
						<view>
							我已邀请:
							<text>{{total}}位用户</text>
						</view>
					</view>
				</view>
				<view class="d-flex flex-wrap">
					<view class="invate-avatar" v-for="(item,index) in inviteList">
						<image :src="item.headImgUrl" mode=""></image>
					</view>
				</view>
			</view>
			<!-- <u-button text="继续邀请新用户" color="#2C66FF" :customStyle="{
				width: '710rpx',
				height: '80rpx',
				borderRadius: '10rpx',
				padding: '0rpx',
				position: 'absolute',
				left: '20rpx',
				bottom: '142rpx'
			}"></u-button>
 -->
		</view>
		<view>
			<button class="invite-btn" open-type="share">继续邀请新用户</button>
		</view>
	</view>
</template>

<script>
	import apiBaseConfig from '@/config/index.js';
	import {
		queryInviteListGet,
		addInviterGet
	} from '@/api/my/index.js'
	export default {
		data() {
			return {
				imgBgUrl: apiBaseConfig.imgBgUrl,
				scrollTopHeader: 0,
				inviteList: [],
				total: 0
			};
		},
		onShareAppMessage(options) {
			var that = this;
			let token = uni.getStorageSync('token')
			if(token){
				var shareObj = {
					title: "新人力小程序", // 默认是小程序的名称(可以写slogan等)
					path: `/my/login/login?id=${that.$store.state.login.userInfo.user.id}`, // 默认是当前页面，必须是以‘/'开头的完整路径
				};
				// 来自页面内的按钮的转发
				if (options.from == 'button') {
					var eData = options.target.dataset;
					console.log(eData.name); // shareBtn
					// 此处可以修改 shareObj 中的内容
					shareObj.path = `/my/login/login?id=${that.$store.state.login.userInfo.user.id}`;
				}
				console.log("shareObj",shareObj)
				// 返回shareObj
				return shareObj;
				// 设置菜单中的转发按钮触发转发事件时的转发内容
			}else{
				uni.showModal({
					title: '请登录',
					content: '您需要登录才能使用该功能',
					success: (res) => {
						if (res.confirm) {
							that.$uniGo.reLaunch({
								url:'/my/login/login'
							})
						} else if (res.cancel) {
							uni.navigateBack()
				
						}
					}
				})
			}
			
		},

		onLoad() {
			wx.hideShareMenu()
			this.getList()
		},
		methods: {
			// 获取邀请列表
			async getList() {
				const data_back = await queryInviteListGet()
				const {
					code,
					rows,
					total
				} = data_back
				if (code == 200 && total > 0) {
					this.inviteList = rows
					this.total = total
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.index {
		&-content {
			margin: 24rpx 20rpx;
			width: calc(100% - 20rpx * 2);

			&-item {
				margin-bottom: 30rpx;

				&-nav {
					margin-bottom: 20rpx;

					>text {
						display: inline-block;
						width: 6rpx;
						height: 36rpx;
						background: #2c66ff;
						border-radius: 3rpx;
						margin-right: 10rpx;
					}

					>view {
						font-size: 28rpx;
						font-family: AlibabaPuHuiTi-Medium, AlibabaPuHuiTi;
						font-weight: 500;
						color: #333333;

						>text {
							color: #2c66ff;
						}
					}
				}

				&-nav:last-child {
					margin-bottom: 0rpx;
				}

				&-li {
					font-size: 24rpx;
					font-family: AlibabaPuHuiTi-Regular, AlibabaPuHuiTi;
					font-weight: 400;
					color: #333333;
					margin-bottom: 10rpx;
					padding-left: 14rpx;
				}

				&-li:last-child {
					margin-bottom: 0rpx;
				}
			}
		}
	}
	.invate-avatar{
		width: 68rpx;
		height: 68rpx;
		background: #f5f5f5;
		border-radius: 50%;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}

	.invite-btn {
		position: fixed;
		bottom: 142rpx;
		left: 0;
		right: 0;
		width: 710rpx;
		height: 80rpx;
		border-radius: 10rpx;
		bottom: 142rpx;
		color: #FFFFFF;
		font-size: 18px;
		text-align: center;
		line-height: 80rpx;
		background: #3476ff;
	}
</style>
