<!-- 我的佣金 -->
<template>
	<s-layout class="wallet-wrap" :bgStyle="{'backgroundColor':'#ffffff'}" title="钱包" navbar="normal">
		<view class="score-box bg-white ss-flex-col ss-row-center ss-col-center">
			<view class="ss-flex ss-m-y-30 w-100">
				<view class="ss-flex"  style="flex-direction: column;flex:1;border-right:1px solid #f6f6f6">
					<view class="ss-m-b-10  circle value-box ss-flex ss-row-center" :style="circleStyle">
						<view>佣金</view>
					</view>
					<view class="ss-m-b-30 ss-font-40" :style="{color:percentageColor}">
						<text class="all-title ss-m-r-8">{{ points2point(userWallet.integralDO.currentQuota) }}</text>
					</view>
					<view class="ss-flex">
						<view class="all-title ss-m-r-8">
							<button class="btn ss-reset-button" @tap="sheep.$router.go('/pages/user/wallet/withdraw')">
								提现
							</button>
						</view>
						<view class="all-title ss-m-r-8">
							<button class="btn ss-reset-button" @tap="sheep.$router.go('/pages/user/wallet/scoreToConsumption')">
								转消费分
							</button>
						</view>
					</view>
				</view>
				<view class="ss-flex" style="flex-direction: column;flex:1;">
					<view class="ss-m-b-10  circle value-box ss-flex ss-row-center" style="background:#0c912f">
						<view>消费分</view>
					</view>
					<view class="ss-m-b-30 ss-font-40" style="color:#0c912f">
						<text class="all-title ss-m-r-8">{{ points2point(userWallet.integralDO.consumptionPoints) }}</text>
					</view>
					<view class="ss-flex">
						<view class="all-title ss-m-x-8" >
							<button class="btn ss-reset-button" @tap="sheep.$router.go('/pages/user/wallet/topupConsumptionPoints')">
								充值
							</button>
						</view>
						<view class="all-title ss-m-x-8">
							
							<button class="btn ss-reset-button" @tap="sheep.$router.go('/pages/user/wallet/consumptionTransfers')">
								消费分转让
							</button>
						</view>
					</view>
				</view>
			</view>
			<!-- 分割线 -->
			<view style="width: 100%;height: 20rpx;background-color: #ececec;"></view>
			<uni-list :border="false" class="ss-p-t-10 ss-w-100">
				<uni-list-item clickable @tap="sheep.$router.go('/pages/user/wallet/maxScoreLog')" title="当前可获得峰值"
					showArrow :border="false">
					<template v-slot:body>
						<p style="width: 100%">
							当前可获得峰值：{{ points2point(userWallet.integralDO.accumulatedQuota + userWallet.integralDO.ancestorQuota) }}/{{ points2point(userWallet.integralDO.highQuotaTotal) }}
						</p>
					</template>
				</uni-list-item>
				<!-- <uni-list-item clickable @tap="sheep.$router.go('/pages/user/wallet/ScoreLog', {isFreeze: true})"
					title="待确权" showArrow :border="false">
					<template v-slot:body>
						<p style="width: 100%">待确权：{{points2point(userWallet.integralDO.freezeQuota)}}</p>
					</template>
				</uni-list-item> -->
				<uni-list-item clickable @tap="sheep.$router.go('/pages/user/wallet/ScoreLog',{isFreeze: false})"
					title="佣金记录" showArrow :border="false">
					<template v-slot:body>
						<p style="width: 100%">佣金记录</p>
					</template>
				</uni-list-item>
				<uni-list-item clickable @tap="sheep.$router.go('/pages/user/wallet/consumptionLog')"
					title="消费分记录" showArrow :border="false">
					<template v-slot:body>
						<p style="width: 100%">消费分记录</p>
					</template>
				</uni-list-item>
				<!-- <uni-list-item clickable @tap="sheep.$router.go('/pages/user/wallet/consumptionTransfersLog')"
					title="消费分转账" showArrow :border="false">
					<template v-slot:body>
						<p style="width: 100%">消费分转账</p>
					</template>
				</uni-list-item> -->
				<uni-list-item clickable @tap="sheep.$router.go('/pages/user/wallet/withdrawalLog')" title="提现记录"
					showArrow :border="false">
					<template v-slot:body>
						<p style="width: 100%">提现 (预计24小时左右到账)</p>
					</template>
				</uni-list-item>
				<uni-list-item clickable @tap="state.showModel = true" title="佣金计算规则" :border="false">
					<template v-slot:body>
						<p style="width: 100%">佣金计算规则</p>
					</template>
				</uni-list-item>
			</uni-list>

		</view>
		<!-- 佣金计算规则 -->
		<su-popup :show="state.showModel" type="center" round="10" :isMaskClick="false" showClose @close="close">
			<view class="head-nav">
				<view :class="state.navIndex==0?'activite':''" class="ss-m-l-20" @click="checkIndex(0)">
					佣金计算规则
				</view>
			</view>
			<scroll-view class="scroll-view_H" scroll-y="true">

				<richtext title="佣金计算规则" type='tab' />
			</scroll-view>
		</su-popup>

	</s-layout>

</template>

<script setup>
	import sheep from '@/sheep';
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app';
	import {
		computed,
		reactive
	} from 'vue';
	import {
		points2point,
		// isBetaUser
	} from '@/sheep/hooks/useGoods';
	import _ from 'lodash';
	import dayjs from 'dayjs';
	import PointApi from '@/sheep/api/member/point';
	import {
		resetPagination
	} from '@/sheep/util';
	import ScoreApi from '@/sheep/api/distri/score';
	import ScoreLog from './ScoreLog'
	import richtext from '@/pages/public/richtext'

	const userWallet = computed(() => sheep.$store('user').userWallet);
	const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
	const userInfo = computed(() => sheep.$store('user').userInfo);
	// const isBeta = computed(() => isBetaUser(userInfo.value.username));
	const sys_navBar = sheep.$platform.navbar;

	const state = reactive({
		currentTab: 0,
		pagination: {
			list: [],
			total: 0,
			pageSize: 10,
			pageNo: 1,
		},
		loadStatus: '',
		showModel: false,

	});

	function close() {
		state.showModel = false;
	}
	const pointsPercentage = computed(() => {

		const currentQuota = parseFloat(points2point(userWallet.value.integralDO.accumulatedQuota + userWallet
			.value.integralDO.ancestorQuota));
		const highQuotaTotal = parseFloat(points2point(userWallet.value.integralDO.highQuotaTotal));


		const percentage = (currentQuota / highQuotaTotal) * 100;
		return Math.min(percentage, 100); // 确保百分比不会超过100

	});
	const percentageColor = computed(() => {
		if (pointsPercentage.value >= 90) {
			return '#fe0000';
		} else if (pointsPercentage.value >= 75) {
			return '#d8b800';
		} else {
			return '#0c912f';
		}
	});
	const circleStyle = computed(() => {
		return {
			// background: `conic-gradient(${percentageColor.value} ${pointsPercentage.value}%, #ddd ${pointsPercentage.value}%)`
			background: percentageColor.value
		};
	});
	onLoad((options) => {
		uni.$on('createWithDrawComplete', sheep.$store('user').getWallet);
		uni.$on('consumptionTransfersComplete', sheep.$store('user').getWallet);
	});
</script>

<style lang="scss" scoped>
	.circle {
		position: relative;
		width: 100px;
		height: 100px;
		border-radius: 50%;

	}

	.circle::before {
		content: '';
		position: absolute;
		top: 5px;
		left: 5px;
		right: 5px;
		bottom: 5px;
		border-radius: 50%;
		background-color: #fff;
	}

	.circle view {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		font-size: 14px;
		font-weight: bold;
	}



	.scroll-view_H {
		width: 600rpx;
		height: 700rpx;
		padding: 20rpx;
	}

	.head-nav {
		margin: 20rpx auto;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		color: var(--ui-BG-Main);

	}

	.head-nav>view {
		padding-bottom: 10rpx;
		border-bottom: 4rpx solid var(--ui-BG-Main);
	}

	.uni-list-item {
		margin: 0 20rpx;
		padding: 10rpx 0;
		border-bottom: 1px solid #d8d8d9;
	}

	.color-red {
		color: red;
	}

	.color-green {
		color: green;
	}

	.score-box {
		border-radius: 20rpx;
		// padding-top: 100rpx;
	}

	.avatar-box {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		overflow: hidden;

		.avatar-img {
			width: 100%;
			height: 100%;
		}
	}

	.value-box {
		width: 150rpx;
		height: 150rpx;
		text-align: center;
		border-radius: 50%;
		font-weight: bold;
	}

	.btn {
		padding:0 1rem;
		background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
		border-radius: 20rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: $white;
		position: relative;
		z-index: 1;
	}
	
	.header-box {
		width: 100%;
		background: linear-gradient(180deg, var(--ui-BG-Main) 0%, var(--ui-BG-Main-gradient) 100%) no-repeat;
		background-size: 750rpx 100%;
		padding: 0 0 120rpx 0;
		box-sizing: border-box;

		.score-box {
			height: 100%;

			.all-num {
				font-size: 50rpx;
				font-weight: bold;
				color: #fff;
				font-family: OPPOSANS;
			}

			.all-title {
				font-size: 26rpx;
				font-weight: 500;
				color: #fff;
			}

			.cicon-help-o {
				color: #fff;
				font-size: 28rpx;
			}
		}
	}

	// 筛选
	.filter-box {
		height: 114rpx;
		background-color: $bg-page;

		.total-box {
			font-size: 24rpx;
			font-weight: 500;
			color: $dark-9;
		}

		.date-btn {
			background-color: $white;
			line-height: 54rpx;
			border-radius: 27rpx;
			padding: 0 20rpx;
			font-size: 24rpx;
			font-weight: 500;
			color: $dark-6;

			.ss-seldate-icon {
				font-size: 50rpx;
				color: $dark-9;
			}
		}
	}

	.model-box {
		height: 50vh;
	}

	.list-box {
		width: 500rpx;
		padding: 0 30rpx;
		overflow-y: auto;

		.list-item {

			background: #fff;
			// border-bottom: 1rpx solid #dfdfdf;
			padding: 30rpx;

			.name {
				font-size: 28rpx;

				font-weight: 500;
				color: rgba(102, 102, 102, 1);
				line-height: 28rpx;
				// margin-bottom: 20rpx;
			}

			.time {
				font-size: 24rpx;

				font-weight: 500;
				color: rgba(196, 196, 196, 1);
				line-height: 24px;
			}

			.add {
				font-size: 30rpx;

				font-weight: 500;
				color: #e6b873;
			}

			.minus {
				font-size: 30rpx;

				font-weight: 500;
				color: $dark-3;
			}
		}
	}
</style>