<template>
	<view class="inspage-content" :style="{'--status-bar-': statusBarHeight}">
		<view class="inspage-content-info">
			<!-- 头部主要内容 开始 -->
			<view class="inspage-content-header">	
				<customNavbar 
				title="统计分销" 
				bgColor="#fff"
				:contentStyle="{color: '#000'}"
				></customNavbar>
			</view>
			<!-- 头部主要内容 结束 -->
			
			<!-- userInfo内容 开始 -->
			
			<view class="inspage-content-userinfo">
				<view class="inspage-userinfo-info">
					<view class="inspage-userinfo-title"><text>我邀请的(人数)</text></view>
					<view class="inspage-userinfo-count">
						<view 
						class="inspage-userinfo-item"
						v-for="(item,index) in tool"
						:key="index"
						>
							<text>
								<u-count-to :decimals="item.num<100000?item.decimals:2" :startVal="0" :endVal="numFormat(item.num)" color="#fff" />
								<text v-if="item.num>=100000" class="inspage-userinfo-util">万</text>
							</text>
							<text>{{ item.title }}</text>
						</view>
					</view>
				</view>
			</view>
			<!-- userInfo内容 结束 -->
		</view>
	</view>
</template>

<script>
	import { navigateTo } from "@/utils/util.js"
	export default {
		data() {
			return {
				title: '统计分销',
				statusBarHeight: 0, // 状态栏安全距离
				tool: [ // 我的工具
					{ title: "邀请总人数",num: 0,decimals:0 },
					{ title: "待核销票数",num: 0,decimals:0 },
					{ title: "已核销票数",num: 0,decimals:0 },
				],
				retailStatistics: {}, // 统计信息
			}
		},
		onLoad() {

		},
		onShow() {
			this.statusBarHeight = getApp().globalData.statusBarHeight
			this.getRetailStatistics()
		},
		methods: {
			/**
			 * @author ygh
			 * @data 2023-12-20
			 */
			navigateToFun(item){
				navigateTo(item.url)
			},
			/**
			 * 数字显示格式化
			 *
			 */
			numFormat(num=0) {
				if(num<100000) {
					return num
				}else if(num>100000){
					return (num/10000).toFixed(2)
				}
			},
			/** 获取数据 */
			async getRetailStatistics(){
				try{
					let res = await this.$u.api.getRetailStatistics({
						noSign: 1,
						userid: this.distribution_user_info.userId
					})
					
					if(res && res.code ===200) {
						this.retailStatistics = res.data
						let list = [].concat(this.tool)
						list[0].num = this.retailStatistics.retailMemberNum
						list[1].num = this.retailStatistics.retailNouseNum
						list[2].num = this.retailStatistics.retailUseNum
						
						this.tool = [].concat(list)
					} 
				}catch(e){
					//TODO handle the exception
					console.error("e===",e)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.inspage-content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		--header-h: 90rpx;
		.inspage-content-info {
			width: 100%;
			box-sizing: border-box;
		}
	}
	/** 头部主要内容 开始 */
	.inspage-content-header {
		width: 100%;
		height: var(--header-h);
		box-sizing: border-box;
		::v-deep .u-search {
			padding: 0 30rpx !important;
		}
		::v-deep .u-search__action {
			color: #fff !important;
		}
	}
	/** 头部主要内容 结束  **/
	
	/** userInfo内容 开始 */
	.inspage-content-userinfo {
		width: 100%;
		padding: 24rpx 40rpx 0;
		box-sizing: border-box;
		.inspage-userinfo-info {
			width: 100%;
			height: 320rpx;
			box-sizing: border-box;
			background-image: url("#{$image-beas-url}invitationStatistics/bgm.png");
			background-size: 100% 100%;
			background-repeat: no-repeat;
			border-radius: 20rpx;
			box-shadow: 0rpx 0 20rpx 2rpx rgba(205, 205, 205, 0.50);
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: space-between;
			color: #fff;
			font-size: 28rpx;
			font-family: SourceHanSansCN, SourceHanSansCN;
			padding: 38rpx 0;
			.inspage-userinfo-title {
				display: flex;
				font-weight: 600;
				width: 100%;
				box-sizing: border-box;
				padding: 0 36rpx;
			}
			.inspage-userinfo-count {
				width: 100%;
				display: flex;
				box-sizing: border-box;
				.inspage-userinfo-item {
					flex: 1;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					> text:nth-child(1) {
						.inspage-userinfo-util {
							font-size: 24rpx;
							margin-left: 5rpx;
						}
						::v-deep .u-count-num {
							font-weight: bold !important;
							font-size: 32rpx !important;
						}
					}
					> text:nth-child(2) {
						margin-top: 20rpx;
						font-size: 24rpx;
					}
				}
				
			}
		}
	}
	/** userInfo内容 结束  **/
</style>
