<template>
	<view class="container">
		<navBar :show-title="true" :title="$t("home.我的邀請")" url="/pages/index/index"></navBar>
		<view class="centerBox">
			<view class="topBox background-linear-gradient">
				<view class="title">
					{{$t('user.数据统计')}}
					<view class="tip">

					</view>
				</view>
				<view class="flex numBox">
					<view class="ls">
						<view class="type">
							{{$t('user.直推人数')}}
						</view>
						<view class="num text-linear-gradient">
							{{shareNum}}
						</view>
					</view>
					<view class="jg">

					</view>
					<view class="ls">
						<view class="type">
							{{$t('user.团队人数')}}
						</view>
						<view class="flex-center">
							<view class="num text-linear-gradient">
								{{itemNum}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="itemList margin-t-30 background-linear-gradient">
				<view class="title">
					{{$t('user.链接地址')}}
					<view class="tip">

					</view>
				</view>
				<view class="list">
					<view class="item flex" v-for="(item,index) in listAll">
						<view class="leftItem">
							<view class="itemName">
								{{item.address|hideCenter}}
							</view>
							<view class="itemTime margin-t-10">
								{{item.spread_time|dateFormat}}
							</view>
						</view>
						<view class="rightItem">
							<view class="on text-linear-gradient" v-if="item.order_num>0">
								{{$t('user.已购买')}}
							</view>
							<view class="off" v-else>
								{{$t('user.未购买')}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" line :loadmoreText="$t('base.加载更多')" :loadingText="$t('base.正在加载')"
				:nomoreText="$t('base.没有更多了')" />
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from "vuex";
	import {
		spreadList
	} from '@/api/index.js';
	import navBar from "@/components/nav/nav.vue"
	import dayjs from '@/libs/dayjs/dayjs.min.js';
	export default {
		data() {
			return {
				listAll: [],
				loading: 'loadmore', //'上拉加載更多','加載中','沒有更多'
				page: 1,
				limit: 10,
				shareNum:0,
				itemNum:0,
			}
		},
		filters: {
			dateFormat: function (value) {
				return dayjs(value * 1000).format('YYYY/MM/DD hh:mm:ss');
			},
			hideCenter: function(value) {
				const st = value.slice(7, value.length - 7);
				const sr = value.replace(st, '...')
				return sr;
			},
		},
		components: {
			navBar
		},
		onLoad(option) {
			this.getList();
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			...mapMutations('user', ['setUserInfo']),
			// 获取列表
			getList() {
				const that = this;
				if (that.loading == 'nomore' || that.loding == "loading") {
					return
				}
				that.loading = 'loading';
				spreadList({
					page: that.page,
					limit: that.limit,
				}).then((res) => {
					that.shareNum = res.data.data.count;
					that.itemNum = res.data.data.group_count;
					const list = res.data.data.list.map((rs) => {
						return rs
					})
					that.listAll = that.listAll.concat(list);
					if (list.length != that.limit) {
						that.loading = 'nomore'
					} else {
						that.page++
						that.loading = 'loadmore'
					}
				}).catch((res) => {
					console.log(res);
				})

			},
		},
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		line-height: 1;
		background-color: rgb(12, 8, 21);
		min-height: 100vh;
	}

	.centerBox {
		padding: 30rpx;
		color: #FFF;

		.title {
			font-weight: bold;
			font-size: 27rpx;
			padding-bottom: 40rpx;

			.tip {
				width: 2em;
				height: 7rpx;
				background: linear-gradient(90deg, #7D32FF, #3EE0FF);
				border-radius: 4px;
				margin-top: -5rpx;
			}
		}

		.topBox {
			padding: 40rpx 30rpx;
			border-radius: 20rpx;

			.numBox {
				align-items: inherit;
				.ls {
					text-align: center;
					flex-grow: 1;
					font-weight: bold;

					.type {
						font-size: 30rpx;
					}

					.num {
						font-size: 42rpx;
						margin-top: 30rpx;
					}
				}

				.jg {
					width: 2px;
					background: linear-gradient(0deg, rgba(255, 255, 255, 0), #FFFFFF, rgba(255, 255, 255, 0));
				}
			}
		}
		.itemList{
			border-radius: 20rpx;
			padding: 40rpx 30rpx;
			.list{
				.leftItem{
					.itemName{
						font-weight: bold;
						font-size: 29rpx;
					}
					.itemTime{
						font-weight: 500;
						font-size: 20rpx;
						color: #FFFFFF;
						opacity: 0.5;
					}
				}
				.rightItem{
					font-weight: 500;
					font-size: 30rpx;
				}
			}
		}
	}
</style>