<template>
	<view>
		<public-module></public-module>
		<view class="headers dis a-c j-c" :style="headerStyle">
			<text>{{userInfo.sysUser.userName}}</text>
			<view class="right dis a-c">
				<image src="/static/home/customerService.png" mode=""></image>
				<text>客服</text>
			</view>
		</view>
		<view class="homeBackground"></view>
		<view class="" style="padding: 0 30rpx;">
			<view class="dailyData-block">
				<view class="title " @click="searchPopup">
					<view class="search">
						<text>{{ startTime && endTime ? startTime + '-' + endTime : '时间筛选' }}</text>
						<i></i>
					</view>
					<image src="/static/home/icon3.png" class="image3" mode=""></image>
				</view>
				<image src="/static/home/icon2.png" class="image2" mode=""></image>
				<view class="data dis f-wrap j-s">
					<view class="dis f-c a-start view">
						<text>{{numberFormat(todayOverview.numberOrders || 0) }}</text>
						<text>订单（笔）</text>
					</view>
					<view class="dis f-c a-start view">
						<text>{{numberFormat(todayOverview.addPerNumber || 0) }}</text>
						<text>新增人员</text>
					</view>
					<view class="dis f-c a-start view">
						<text>{{numberFormat(todayOverview.premium || 0)}}</text>
						<text>保费（元）</text>
					</view>
					<view class="dis f-c a-start view">
						<text>{{numberFormat(todayOverview.commission || 0 ) }}</text>
						<text>佣金（元）</text>
					</view>
				</view>
			</view>
			<!-- 我的收益 -->
			<view class="earnings dis a-c j-s mt-2" @click="myEarnings">
				<view class="dis a-c ">
					<image src="/static/home/wallet.png" mode=""></image>
					<image class="incomeText ml-1" src="/static/home/incomeText.png" mode=""></image>
					<image class="income" src="/static/home/income.png" mode=""></image>
				</view>
				<view class="btn">
					去查看
				</view>
			</view>
			<view class="statistics">
				<uni-tabs :list="teamOverview" :is-scroll="true" name="gradeName" active-color="#333"
					inactive-color="#999" :current="current" @change="change"
					style="background: transparent;border-bottom: 1rpx solid #EEEEEE;"></uni-tabs>
				<view class="count">
					<template v-if="teamOverviewInfo.grade==1">
						<image src="/static/home/icon4.png" class="mb-2" mode=""
							@click="invitationCode(teamOverviewInfo.grade)">
						</image>
						<view class="data dis f-wrap j-s ">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo1.v1 || 0}}</text>
								<text>我的管理人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo1.v2 || 0}}</text>
								<text>管理人的合伙人</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo1.v3 || 0}}</text>
								<text>我今日新增管理人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo1.v4 || 0}}</text>
								<text>今日管理人邀请的合伙人</text>
							</view>
						</view>
						<view class="data dis f-wrap j-s  mt-2">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.sumPremium || 0}}</text>
								<text>保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{userWalletInfo.extractFee || 0}}</text>
								<text>佣金</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.historyFee || 0}}</text>
								<text>佣金已转入</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{userWalletInfo.cashFee || 0}}</text>
								<text>佣金未转入</text>
								<view class="commissionIn" @click="roleCommInShow=true">
									<text>转入</text>
									<u-icon name="arrow-rightward" color="#2D6DFF" size="20"></u-icon>
								</view>
							</view>
						</view>
					</template>
					<template v-if="teamOverviewInfo.grade==2 ">
						<image src="/static/home/icon5.png" class="mb-2" mode=""
							@click="invitationCode(teamOverviewInfo.grade)">
						</image>
						<view class="data dis f-wrap j-s ">
							<!-- 权限锁定组件 -->
							<!-- <uni-permission-view v-if="teamOverviewInfo.parentStatus=='2'"
								:genericText="teamOverviewInfo.lockCommission?`解锁“${gradeText}”，立即到账<text style='color:#F74141;font-weight: bold;'>${teamOverviewInfo.lockCommission}</text>元`:`完成任务，解锁“${gradeText}”，佣金即可提现到账`"
								cornerRadius="8rpx" :imageStyle="{width:'109rpx',height:'107rpx'}"
								@requestUnlock="requestUnlock">
							</uni-permission-view> -->
							<!-- 权限锁定组件 -->
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo2.v1 || 0}}</text>
								<text>我的合伙人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo2.v2 || 0}}</text>
								<text>合伙人的工作室</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo2.v3 || 0}}</text>
								<text>我今日新增合伙人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo2.v4 || 0}}</text>
								<text>今日合伙人邀请的工作室</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{teamOverviewInfo.vo2.v5 || 0}}</text>
								<text>今日保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo2.v6 || 0}}</text>
								<text>今日佣金</text>
							</view>
						</view>
						<view class="data dis f-wrap j-s mt-2">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.sumPremium ||0 }}</text>
								<text>保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{userWalletInfo.extractFee ||0}}</text>
								<text>佣金</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.historyFee ||0 }}</text>
								<text>佣金已转入</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{userWalletInfo.expired||0 }}</text>
								<text>佣金已过期</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.cashFee ||0 }}</text>
								<text>佣金未转入</text>
								<view class="commissionIn " @click="roleCommInShow=true">
									<text>转入</text>
									<u-icon name="arrow-rightward" color="#2D6DFF" size="20"></u-icon>
								</view>
							</view>
							<view class="dis f-c a-c view">
								<text
									:style="{color:userWalletInfo.freeze>0?'#999':'#333'}">{{userWalletInfo.freeze ||0}}</text>
								<text>佣金已冻结</text>
								<image v-if="userWalletInfo.freeze>0" class="frozen" src="/static/home/frozen.png"
									mode="">
								</image>
							</view>
						</view>
					</template>
					<template v-if="teamOverviewInfo.grade==3 ">
						<image src="/static/home/icon6.png" class="mb-2" mode=""
							@click="invitationCode(teamOverviewInfo.grade)">
						</image>
						<view class="data dis f-wrap j-s ">
							<!-- 权限锁定组件 -->
							<!-- <uni-permission-view v-if="teamOverviewInfo.parentStatus=='2'"
								:genericText="teamOverviewInfo.lockCommission?`解锁“${gradeText}”，立即到账<text style='color:#F74141;font-weight: bold;'>${teamOverviewInfo.lockCommission}</text>元`:`完成任务，解锁“${gradeText}”，佣金即可提现到账`"
								cornerRadius="8rpx" :imageStyle="{width:'109rpx',height:'107rpx'}"
								@requestUnlock="requestUnlock"
								:btnText="teamOverviewInfo.upgradeStatus==2?'申请中':'立即解锁'">
							</uni-permission-view> -->
							<!-- 权限锁定组件 -->
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo3.v1 || 0}}</text>
								<text>我的工作室</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo3.v2 || 0}}</text>
								<text>工作室下的业务团队</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo3.v3 || 0}}</text>
								<text>我今日新增工作室</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo3.v4 || 0}}</text>
								<text>今日工作室邀请的团队</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{teamOverviewInfo.vo3.v5 || 0}}</text>
								<text>今日保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo3.v6 || 0}}</text>
								<text>今日佣金</text>
							</view>
						</view>
						<view class="data dis f-wrap j-s mt-2">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.sumPremium ||0 }}</text>
								<text>保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{userWalletInfo.extractFee ||0}}</text>
								<text>佣金</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.historyFee ||0 }}</text>
								<text>佣金已转入</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{userWalletInfo.expired||0 }}</text>
								<text>佣金已过期</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.cashFee ||0 }}</text>
								<text>佣金未转入</text>
								<view class="commissionIn " @click="roleCommInShow=true">
									<text>转入</text>
									<u-icon name="arrow-rightward" color="#2D6DFF" size="20"></u-icon>
								</view>
							</view>
							<view class="dis f-c a-c view">
								<text
									:style="{color:userWalletInfo.freeze>0?'#999':'#333'}">{{userWalletInfo.freeze ||0}}</text>
								<text>佣金已冻结</text>
								<image v-if="userWalletInfo.freeze>0" class="frozen" src="/static/home/frozen.png"
									mode="">
								</image>
							</view>
						</view>
					</template>
					<template v-if="teamOverviewInfo.grade==4 ">
						<image src="/static/home/icon7.png" class="mb-2" mode=""
							@click="invitationCode(teamOverviewInfo.grade)">
						</image>
						<view class="data dis f-wrap j-s ">
							<!-- 权限锁定组件 -->
							<!-- <uni-permission-view v-if="teamOverviewInfo.parentStatus=='2'"
								:genericText="teamOverviewInfo.lockCommission?`解锁“${gradeText}”，立即到账<text style='color:#F74141;font-weight: bold;'>${teamOverviewInfo.lockCommission}</text>元`:`完成任务，解锁“${gradeText}”，佣金即可提现到账`"
								cornerRadius="8rpx" :imageStyle="{width:'109rpx',height:'107rpx'}"
								@requestUnlock="requestUnlock">
							</uni-permission-view> -->
							<!-- 权限锁定组件 -->
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo4.v1 || 0}}</text>
								<text>我的团队</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo4.v2 || 0}}</text>
								<text>代理人人数</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo4.v3 || 0}}</text>
								<text>我今日新增团队</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo4.v4 || 0}}</text>
								<text>今日新增代理人</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{teamOverviewInfo.vo4.v5 || 0}}</text>
								<text>今日保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo4.v6 || 0 }}</text>
								<text>今日佣金</text>
							</view>
						</view>
						<view class="data dis f-wrap j-s mt-2">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.sumPremium ||0 }}</text>
								<text>保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{userWalletInfo.extractFee ||0}}</text>
								<text>佣金</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="incomingTransferLog">
								<text>{{userWalletInfo.historyFee ||0 }}</text>
								<text>佣金已转入</text>
							</view>
							<view class="dis f-c a-c view" @click="accountFreezeRecord">
								<text>{{userWalletInfo.expired||0 }}</text>
								<text>佣金已过期</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{userWalletInfo.cashFee ||0 }}</text>
								<text>佣金未转入</text>
								<view class="commissionIn " @click="roleCommInShow=true">
									<text>转入</text>
									<u-icon name="arrow-rightward" color="#2D6DFF" size="20"></u-icon>
								</view>
							</view>
							<view class="dis f-c a-c view" @click="accountFreezeRecord">
								<text
									:style="{color:userWalletInfo.freeze>0?'#999':'#333'}">{{userWalletInfo.freeze ||0}}</text>
								<text>佣金已冻结</text>
								<image v-if="userWalletInfo.freeze>0" class="frozen" src="/static/home/frozen.png"
									mode="">
								</image>
							</view>
						</view>
					</template>
				</view>
			</view>
		</view>
		<!-- 购买等级 -->
		<view class="purchaseLevels  dis a-c j-c " v-if="teamOverviewInfo.parentStatus == '2'">
			<view class="purchaseLevel">
				<!-- 头部 -->
				<view class="header dis a-c j-c mb-2">
					<!-- 星星装饰图 -->
					<image class="star" src="/static/image/my/upgradeTask/star-left.png" mode=""></image>
					<view class="title ">
						<text>完成任务或直接联系客服购买该等级</text>
						<view class="line"></view>
					</view>
					<image class="star" src="/static/image/my/upgradeTask/star-right.png" mode=""></image>
				</view>
				<!-- 内容 -->
				<view class="dis a-c j-s">
					<!-- 左侧红包样式 -->
					<view class="redPacket">
						<!-- 红包图片 -->
						<image class="redPacket-img" src="/static/image/my/upgradeTask/redPacket.png" mode="">
						</image>
						<!-- 锁定样式 -->
						<view class="lock">
							<image class="lock-img" src="/static/image/my/upgradeTask/lock.png" mode=""></image>
						</view>
					</view>
					<view class="redPacket-data dis f-c">
						<view class="dis a-c ">
							<text class="sum">￥{{teamOverviewInfo.lockCommission || 0 }}</text>
							<text class="days">(已锁定 {{teamOverviewInfo.zeroDays || 0}}天清0)</text>
						</view>
						<text class="ml-1" style="font-size: 26rpx;color: #999;">支付<text
								style="color: #FFA008;">{{teamOverviewInfo.fallAmount}}</text>
							元可解锁</text>
					</view>
					<view class="btn" @click="requestUnlock">去解锁</view>
				</view>
			</view>
		</view>
		<!-- 升级任务 -->
		<view class="purchaseLevels  dis a-c j-c "
			v-if="teamOverviewInfo.parentStatus == '1' && teamOverviewInfo.grade!=1">
			<view class="purchaseLevel">
				<!-- 头部 -->
				<view class="header dis a-c j-c mb-1">
					<!-- 星星装饰图 -->
					<image class="star" src="/static/image/my/upgradeTask/star-left.png" mode=""></image>
					<view class="title ">
						<text>完成任务，解锁{{this.gradeText1(teamOverviewInfo.grade)}}权益</text>
						<view class="line"></view>
					</view>
					<image class="star" src="/static/image/my/upgradeTask/star-right.png" mode=""></image>
				</view>
				<!-- 任务轮播 -->
				<view class="taskCarousel">
					<!-- 加载状态 -->
					<view v-if="loading" class="loading">加载中...</view>
					<swiper v-if="!loading && upgradeTaskdata.requirement.length > 0" :key="swiperKey" class="swiper "
						circular :indicator-dots="true" :autoplay="true" :duration="300" indicator-color="#D9D9D9"
						indicator-active-color="#2DD9FF" :circular="true">
						<swiper-item v-for="(item,index) in upgradeTaskdata.requirement" :key="item.id">
							<view class="taskitem dis a-c j-s">
								<view class="task-icon">
									<image :src="`/static/image/my/upgradeTask/icon${index+1}.png`" mode=""></image>
								</view>
								<view class="task-progress">
									<!-- 任务标题 -->
									<text class="title " v-if="upgradeTaskdata.grade=='2'">
										{{ index==0 ? '邀请合伙人' :index==1? `${upgradeTaskdata.gradeName}下属成员出单保费`:'自己的出单保费' }}达{{item.min}}{{ index ? '元' : '人' }}
									</text>
									<text class="title " v-if="upgradeTaskdata.grade=='3'">
										{{ index==0 ? '邀请工作室' :index==1? `${upgradeTaskdata.gradeName}下属成员出单保费`:'自己的出单保费' }}达{{item.min}}{{ index ? '元' : '人' }}
									</text>
									<text class="title " v-if="upgradeTaskdata.grade=='4'">
										{{ index==0 ? '邀请团队长' :index==1? `${upgradeTaskdata.gradeName}下属成员出单保费`:'自己的出单保费' }}达{{item.min}}{{ index ? '元' : '人' }}
									</text>
									<text class="title " v-if="upgradeTaskdata.grade=='5'">
										{{ index==0 ? '邀请团队长' :index==1? `${upgradeTaskdata.gradeName}下属成员出单保费`:'自己的出单保费' }}达{{item.min}}{{ index ? '元' : '人' }}
									</text>
									<view class=" dis a-c">
										<!-- 进度条 -->
										<view class="progressBar">
											<view class="jindu"
												:style="{width: `${ Number(item.achieve) / Number(item.min) * 100}%`}">
											</view>
										</view>
										<!-- 进度条 -->
										<view class="task-data dis a-c ml-1">
											<text>{{item.achieve}}</text>
											<text class="ml-1 mr-1">/</text>
											<text>{{item.min}}</text>
										</view>
									</view>
								</view>
								<view :class="index==1?'task-btn1':'task-btn'"
									v-if="Number(item.achieve)>=Number(item.min)">
									已完成
								</view>
								<view :class="index==1?'task-btn1':'task-btn'" v-else @click="requestUnlock">
									{{index==1?'未完成':'去完成'}}
								</view>
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>
		</view>
		<u-popup v-model="ShowModalCodebusiness" mode="bottom" border-radius="15" :closeable="true">
			<view>
				<text class=" ShowModalCode-business">工作室业务</text>
				<view>
					<radio-group class="uni-list" @change="styleChange">
						<view v-for="(item, index) in styles" :key="index" class="uni-list-item">
							<view class="uni-list-item__container">
								<view class="uni-list-item__content">
									<text class="uni-list-item__content-title">{{ item.text }}</text>
								</view>
								<view class="uni-list-item__extra">
									<radio :value="item.value" :checked="item.checked" />
								</view>
							</view>
							<view class="uni-list-item__notestext">{{ item.notestext }}</view>
						</view>
					</radio-group>
				</view>
				<view class="ShowModalCode-sumbit" @click="ShowModalCodeSumbit()">确定</view>
			</view>
		</u-popup>
		<u-modal v-model="promptshow" :show-cancel-button="true" :confirm-text="`确认为${deptSource==1?'渠道':'个代'}模式`"
			cancel-text="重新选择" :cancel-style="{fontSize:'28rpx',color:'#007AFF'}" :confirm-style="{fontSize:'28rpx'}"
			@confirm="promptshowconfirm">
			<view class="p-2">
				<text v-if="deptSource==1">您选择的 <text style="color: #007AFF;">渠道</text> 模式，业务员出单后，业务员的
					<text> <strong>佣金都会归到团队长账户内由团队长进行分配</strong></text>。</text>
				<text v-else>您选择的 <text style="color: #007AFF;margin: 0 10rpx;">个代</text> 模式，业务员出单后，业务员的
					<text> <strong>佣金都会归到自己账户内</strong> </text>。</text>

			</view>

		</u-modal>
		<!-- 佣金转入 -->
		<u-popup v-model="roleCommInShow" mode="center" border-radius="10">
			<view class=" roleCommInClass dis f-c a-c">
				<text class="title font-weight mt-3">佣金转入钱包</text>
				<view class="dis f-c p-3 content">
					<text>您的每一个等级收益需要手动转入钱包中，才可以将收益提现</text>
					<view class="mt-1 ">
						<text>{{userWalletInfo.cashFee}}元</text>
						<text class="ml-2" style="color: #2D6DFF;">全部转入</text>
					</view>
					<u-input v-model="amount" class="mt-1" type="digit" :border="true" placeholder="输入转入金额" focus />
				</view>

			</view>
			<view class="roleCommInClass-footer dis a-c j-s ">
				<view class="dis a-c j-c" @click="roleCommInShow=false">取消</view>
				<view class="dis a-c j-c" @click="roleCommInconfirm">确认</view>
			</view>
		</u-popup>

		<my-date-picker ref="datePicker" @confirmPickDate="confirmPickDate" />
	</view>
</template>
<script>
	import myDatePicker from '../components/todaydate-picker.vue';
	import QR from "@/common/wxqrcode.js"
	import {
		mapState,
		mapMutations
	} from "vuex"
	import {
		nextTick,
		vShow
	} from "vue"
	export default {
		computed: {
			...mapState(['userInfo', "userCheckInfo"]),
			gradeText() {
				const gradeMap = {
					1: '创始人',
					2: '管理人',
					3: '合伙人',
					4: '工作室'
				}
				return gradeMap[this.teamOverviewInfo.grade] || ''
			},
			displayData() {
				return this.upgradeTaskdata.requirement;
			}
		},
		components: {
			myDatePicker
		},
		data() {
			return {
				startTime: null,
				endTime: null,
				swiperKey: 0, // 用于强制更新 swiper
				loading: true, // 加载状态
				upgradeTaskdata: {}, //升级任务数据
				amount: null, //转入佣金
				roleCommInShow: false, //佣金转入弹窗
				promptshow: false, //提示
				personTypeshow: false, //业务类型弹窗
				userWalletInfo: {}, //角色钱包数据
				teamOverviewInfo: {}, //页面展示数据
				todayOverview: {}, //今日数据
				teamOverview: [],
				current: 0,
				showData: '全部数据',
				ShowModalCodebusiness: false, //业务来源弹窗
				teamImg: '',
				workImg: '',
				totalList: {},
				type: uni.getStorageSync('type'),
				headerStyle: {
					backgroundColor: 'transparent',
					backgroundImage: '',
					backgroundSize: '',
					backgroundPosition: '',
					boxShadow: ''
					// 其他样式属性...
				},
				styles: [{
						value: '1',
						text: '渠道',
						notestext: '团队长加出单员模式，无分销模式，结费都在团队长处。',
						checked: true
					},
					{
						value: '2',
						notestext: '团队长加代理人模式，三级分销模式，结费方式为个人，有佣金。',
						text: '个代'
					}
				],
				deptSource: 1,
				grade: 0,
			}
		},
		onShow() {},
		async onLoad() {

			this.type = uni.getStorageSync('type')
			this.showData = '全部数据';
			await this.getList() //人员统计
			this.getAmountList(this.userInfo.sysUser.grade); //角色佣金
			if (this.userInfo.sysUser.grade > 1) this.getUpgradeTask(this.userInfo.sysUser.grade); //角色升级任务


		},
		methods: {
			incomingTransferLog() {
				uni.navigateTo({
					url: '/pages/institutional/incomingTransferLog'
				})
			},
			accountFreezeRecord() {
				uni.navigateTo({
					url: '/pages/institutional/accountFreezeRecord'
				})
			},
			//日期选择回调
			confirmPickDate(startdate, enddate) {
				console.log(startdate, enddate);
				this.startTime = startdate;
				this.endTime = enddate;
				this.getList(startdate, enddate) //人员统计
			},
			//激活时间选择组件
			searchPopup() {
				this.$refs.datePicker.open()
			},
			//获取上级角色名称
			gradeText1(grade) {
				const gradeMap = {
					1: '创始人',
					2: '管理人',
					3: '合伙人',
					4: '工作室'
				}
				return gradeMap[Number(grade) - 1] || ''
			},
			//获取升级任务
			async getUpgradeTask(grade) {
				this.loading = true; // 开始加载
				try {
					let res = await this.$http.get('/partner/queryDowngradeTask?grade=' + grade); //升级任务
					if (res.code == 200) {
						this.upgradeTaskdata = res.data;
					} else {
						this.upgradeTaskdata = {}
					}
				} catch (error) {
					console.error("数据加载失败:", error);
				} finally {
					this.loading = false; // 加载完成
					this.swiperKey += 1; // 更新 swiperKey 以强制重新渲染
				}

			},

			//角色佣金转入
			async roleCommInconfirm() {
				if (Number(this.amount) > this.userWalletInfo.cashFee) {
					return uni.showToast({
						title: '转入金额不能大于可转入金额',
						icon: 'none',
					});
				}
				if (Number(this.amount) <= 0) {
					return uni.showToast({
						title: '转入金额不能为0',
						icon: 'none',
					});
				}
				let res = await this.$http.post('/partnerExtractHistory/extractRecords', {
					grade: this.userWalletInfo.grade,
					amount: this.amount,
				});
				if (res.code == 200) {
					this.roleCommInShow = true;
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
					});
				}

			},
			//锁定视图点击事件
			async requestUnlock() {
				if (this.teamOverviewInfo.parentStatus == '2' && this.teamOverviewInfo.unlockedStatus) {
					switch (this.teamOverviewInfo.upgradeStatus) {
						case 0:
							let params = {
								grade: Number(this.teamOverviewInfo.grade),
								lockingState: this.teamOverviewInfo.parentStatus,
								lockCommission: this.teamOverviewInfo.lockCommission,
								zeroDays: this.teamOverviewInfo.zeroDays,
								fallAmount: this.teamOverviewInfo.fallAmount,
							}
							uni.navigateTo({
								url: "/pages/my/upgradeTask?info=" + JSON.stringify(params),
							})
							break;
						case 1:
							let res = await this.$http.post('/partner/submitLiftingRecord', {
								grade: this.teamOverviewInfo.grade,
								upgradeType: '1'
							});
							if (res.code == '200') {
								uni.showToast({
									title: res.msg,
									icon: 'none',
								});
								this.getList()
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none',
								});
							}
							break;
						case 2:
							uni.showToast({
								title: '申请中',
								icon: 'none',
							});
							break;
						default:
					}
				} else {
					uni.showToast({
						title: '先解锁上一级',
						icon: 'none',
					});
				}
			},
			//业务来源确定事件
			promptshowconfirm() {
				this.promptshow = false;
				this.ShowModalCodebusiness = false;
				uni.navigateTo({
					url: "/pages/institutional/invitationCode?grade=" + this.grade + "&deptSource=" + this
						.deptSource + '&userId=' + this.userInfo.sysUser.userId + "&info=" + JSON.stringify(this
							.teamOverviewInfo),
				})
				// uni.navigateTo({
				// 	url: "/pages/index/applypartner?grade=" + this.grade + "&deptSource=" + this
				// 		.deptSource + '&userId=' + this.userInfo.sysUser.userId,
				// })
			},
			//业务类型
			styleChange(e) {
				this.deptSource = e.detail.value
			},
			//数据格式化
			numberFormat(value) {
				return (value).toLocaleString('en-US');
			},
			//标签切换
			change(index) {
				console.log(this.teamOverview[index]);
				const info = this.teamOverview[index];
				console.log(info);
				this.teamOverviewInfo = info;
				this.current = index;
				this.getAmountList(info.grade)
				this.getUpgradeTask(info.grade); //角色升级任务
			},
			//获取人员数据
			async getList(startTime, endTime) {
				let params = {
					type: this.type,
					"startTime": startTime + '00:00:00' || '',
					"endTime": endTime + '23:59:59' || '',
				}
				let res = await this.$http.post('/newAppPartner/getHomePage', params); //统计数据
				if (res.code == '200') {
					this.todayOverview = res.data.todayOverview; //今日数据
					res.data.teamOverview.map(val => {
						val.gradeName = '我是' + val.gradeName;
						return val;
					})
					res.data.teamOverview.map(val => {
						if (val.parentStatus == '2') {
							val.imageSel = '/static/home/imageSel.png'
							val.imageUnSel = '/static/home/imageUnSel.png'
						}
						return val;
					})
					this.teamOverview = res.data.teamOverview; //选项卡
					console.log(this.teamOverview);
					this.current = 0;
					this.teamOverviewInfo = res.data.teamOverview[0]; //页面赋值第一条数据
				}
			},
			//钱包
			async getAmountList(grade) {
				let params = {
					grade: grade,
					"startTime": '',
					"endTime": '',
				}
				let res = await this.$http.post('/newAppPartner/getHomeWallet', params); //佣金
				if (res.code == '200') {
					this.userWalletInfo = res.data;
				}
			},
			//业务来源确定
			ShowModalCodeSumbit() {
				this.promptshow = true;
			},
			//人员列表
			closePartner() {
				uni.navigateTo({
					url: "/pages/institutional/partner?grade=" + this.teamOverviewInfo.grade,
				})
			},
			//今日人员
			todayclosePartner() {
				let dotayDate = new Date().toISOString().split('T')[0] //今日日期
				uni.navigateTo({
					url: "/pages/institutional/partner?grade=" + this.teamOverviewInfo.grade + '&startTime=' +
						dotayDate + '&endTime=' + dotayDate,
				})
			},
			//我的收益
			myEarnings() {
				uni.navigateTo({
					url: "/pages/institutional/myEarnings?info=" + JSON.stringify(this.teamOverviewInfo),
				})
			},
			//邀请码
			invitationCode(value) {
				this.grade = value;
				if (value == 4) { //区分合伙人和工作室  4==工作室
					this.ShowModalCodebusiness = true;
				} else {
					uni.navigateTo({
						url: "/pages/institutional/invitationCode?grade=" + value + "&info=" + JSON.stringify({
							...this
							.teamOverviewInfo,
							lockingState: this.teamOverviewInfo.parentStatus
						}),
					})
					// uni.navigateTo({
					// 	url: "/pages/index/applypartner?grade=" + value + '&userId=' + this.userInfo.sysUser
					// 		.userId,
					// })
				}

			},
		}
	}
</script>
<style lang="scss" scoped>
	* {
		// outline: 1px solid red !important;
	}

	page {
		background-color: #F7F7F7;
	}

	.headers {
		position: fixed;
		top: 0;
		left: 0;
		height: auto;
		width: 100%;
		z-index: 99;
		padding: 30rpx;
		padding-top: 50px;

		text {
			font-size: 36rpx;
			font-weight: bold;
			color: #fff;
		}

		.right {
			position: absolute;
			right: 30rpx;

			image {
				width: 28rpx;
				height: 28rpx;
				margin-right: 4rpx;
			}

			text {
				font-weight: 400;
				color: #fff;
				font-size: 24rpx;
			}
		}
	}

	.homeBackground {
		height: 177px;
		width: 100%;
		background-image: url("/static/home/back.png");
		background-size: 100% 100%;
	}

	.dailyData-block {
		width: 100%;
		margin-top: -136rpx;
		background-image: url("/static/home/aaa.png");
		background-size: 100% 100%;
		backdrop-filter: blur(2rpx);
		padding: 20rpx 40rpx;

		// background: rgba(255, 255, 255, 0.2);
		// border-radius: 16px;
		// box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
		// backdrop-filter: blur(30px);
		// border: 1px solid rgba(255, 255, 255, 1);
		.title {
			position: relative;
			display: inline-block;

			.search {
				text {
					font-size: 30rpx;
					color: #fff;
					font-weight: 400;
				}

				i {
					margin-left: 9rpx;
					display: inline-block;
					width: 0;
					height: 0;
					border: 8rpx solid;
					border-color: #fff;
					border-bottom: 8rpx solid transparent;
					border-right: 8rpx solid transparent;
					border-left: 8rpx solid transparent;
				}
			}

			text {
				color: #fff;
				font-weight: bold;
				font-size: 36rpx;
				margin-left: 10rpx;
			}



			.image3 {
				width: 100%;
				height: 20rpx;
				position: absolute;
				bottom: 0;
				left: 4rpx;
			}

		}

		.image2 {
			width: 138rpx;
			height: 138rpx;
			position: absolute;
			top: -50rpx;
			right: 22rpx;
		}

		.data {
			.view {
				width: 50%;

				text:first-child {
					font-size: 46rpx;
					color: #333;
					font-weight: bold;
				}

				text:last-child {
					font-size: 24rpx;
					color: #666;
				}
			}
		}
	}

	.statistics {
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin-top: 25rpx;

		.count {
			padding: 34rpx 30rpx;
			box-sizing: border-box;

			image {
				width: 100%;
				height: 120rpx;
			}
		}

		.data {
			position: relative;
			padding: 30rpx;
			box-sizing: border-box;
			background-color: #FBFBFB;
			border-radius: 8rpx;

			.view {
				width: 49%;

				>:nth-child(1) {
					font-size: 36rpx;
					color: #333;
					font-weight: bold;
					margin-bottom: 4rpx;
				}

				>:nth-child(2) {
					font-size: 22rpx;
					color: #999;
				}

				.frozen {
					width: 28rpx;
					height: 28rpx;
					margin-top: 4rpx;
				}

				//转入按钮
				.commissionIn {
					padding: 0 12rpx;
					box-sizing: border-box;
					border-radius: 30rpx 30rpx 30rpx 30rpx;
					border: 1rpx solid #2D6DFF;
					font-size: 20rpx;
					color: #2D6DFF;
					margin-top: 4rpx;
					line-height: normal;
				}
			}
		}


	}

	::v-deep {
		.u-tab-bar {
			background: linear-gradient(90deg, #2DD9FF 0%, #2D6DFF 100%) !important;
			border-radius: 6rpx;
		}
	}

	.ShowModalCode-style {
		text:first-child {
			display: block;
			font-weight: 600;
			font-size: 16px;
			color: #333333;
			border: 1px solid #EEEEEE;
			padding: 15px;
			text-align: center;
		}
	}

	.ShowModalCode-con {
		padding: 30px;
		text-align: center;

		image {
			margin: 0 auto;
			margin-top: 15px;
		}
	}

	.ShowModalCode-business {
		display: block;
		font-weight: 600;
		font-size: 16px;
		color: #333333;
		// border: 1px solid #EEEEEE;
		padding: 15px;
		text-align: center;
	}

	.ShowModalCode-sumbit {
		background: linear-gradient(132deg, #2DD9FF 0%, #2D6DFF 100%);
		border-radius: 5px 5px 5px 5px;
		height: 40px;
		line-height: 40px;
		font-size: 16px;
		color: #FFFFFF;
		margin: 15px;
		text-align: center;
	}

	.uni-list {
		flex: 1;
	}

	.uni-list-item:first-child {
		/* #ifndef APP-NVUE */
		// display: flex;
		/* #endif */
		flex: 1;
		flex-direction: row;
		background-color: #FFFFFF;
		border-bottom-style: solid;
		border-bottom-width: 1px;
		border-bottom-color: #eee;
	}


	.uni-list-item__container {
		padding: 12px 15px;
		width: 100%;
		flex: 1;

		position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		box-sizing: border-box;
		/* #endif */
		flex-direction: row;
		justify-content: space-between;
		align-items: center;

	}

	.uni-list-item__notestext {
		padding: 0 15px 15px 15px;
		font-size: 15px;
		color: #666666;
	}

	.uni-list-item__content-title {
		font-size: 17px;
		color: #333333;
	}

	//我的收益
	.earnings {
		background: #FFFFFF;
		padding: 25rpx 30rpx;
		box-sizing: border-box;
		border-radius: 20rpx 20rpx 20rpx 20rpx;

		.btn {
			padding: 3rpx 12rpx;
			box-sizing: border-box;
			background: linear-gradient(132deg, #2DD9FF 0%, #2D6DFF 100%);
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			font-size: 22rpx;
			color: #fff;
		}

		.income {
			width: 36rpx;
			height: 36rpx;
		}

		image {
			width: 40rpx;
			height: 40rpx;
		}

		.incomeText {
			width: 122rpx;
			height: 28rpx;
			margin-right: 4rpx;
		}

	}

	.roleCommInClass {
		width: 600rpx;
		border-radius: 10rpx;
		box-sizing: border-box;
		font-size: 26rpx;

		.title {
			font-size: 32rpx;
			color: #333;
		}

		.content {
			text:nth-child(1) {
				font-size: 28rpx;
				color: #333;
			}

			text:nth-child(2) {
				font-size: 26rpx;
				color: #666;
			}

		}

	}

	.roleCommInClass-footer {
		width: 100%;
		border-top: 1rpx solid #eee;

		view {
			width: 49%;
			padding: 24rpx;
			box-sizing: border-box;

		}

		view:first-child {
			border-right: 1rpx solid #eee;
		}

		view:last-child {
			color: #2D6DFF;
		}
	}

	// 购买等级
	.purchaseLevels {
		position: relative;
		background: linear-gradient(180deg, #FFD581 0%, #FFFFFF 70%);
		border-radius: 20rpx;
		margin: 20rpx 30rpx;

		.purchaseLevel {
			width: 99.7%;
			margin-top: 2rpx;
			padding: 20rpx 30rpx;
			box-sizing: border-box;
			background: linear-gradient(0deg, #fff 20%, #FFF6EC 100%);
			border-radius: 20rpx;

		}

		.header {
			.star {
				width: 27rpx;
				height: 22rpx;
			}

			.title {
				position: relative;
				margin-left: 2rpx;
				margin-right: 2rpx;
				text-align: center;
				font-size: 30rpx;
				color: #333;
				font-weight: bold;

				text {
					position: relative;
					z-index: 9;
					margin: 0 4rpx;
				}

				.line {
					position: absolute;
					bottom: 6rpx;
					left: 0;
					right: 0;
					margin: auto;
					width: 90%;
					height: 13rpx;
					background: #FFE262;
					border-radius: 0rpx 0rpx 0rpx 0rpx;
				}
			}
		}

		// 红包样式
		.redPacket {
			position: relative;
			padding: 15rpx;
			box-sizing: border-box;
			background: #FFF0E8;
			border-radius: 20rpx 20rpx 20rpx 20rpx;

			.redPacket-img {
				width: 70rpx;
				height: 70rpx;
			}

			.lock {
				position: absolute;
				bottom: 0;
				right: 0;
				padding: 5rpx;
				z-index: 9;
				box-sizing: border-box;
				background: rgba(255, 163, 117, 0.3);
				border-radius: 20rpx 0rpx 20rpx 0rpx;
				backdrop-filter: blur(10rpx);

				.lock-img {
					width: 30rpx;
					height: 30rpx;
				}
			}
		}

		/* 锁定金额 */
		.redPacket-data {
			.sum {
				font-size: 36rpx;
				color: #F74141;
				font-weight: bold;
			}

			.days {
				font-size: 30rpx;
				color: #666;
			}
		}

		/* 去解锁按钮 */
		.btn {
			padding: 8rpx 20rpx;
			box-sizing: border-box;
			background: linear-gradient(132deg, #2DD9FF 0%, #2D6DFF 100%);
			border-radius: 50rpx 50rpx 50rpx 50rpx;
			font-size: 28rpx;
			color: #fff;
			line-height: 1.5;
		}

		.taskCarousel {
			width: 100%;

			.swiper {
				height: 200rpx;
			}

			.taskitem {
				width: 100%;
				padding: 10rpx;
				box-sizing: border-box;

				.task-icon {
					background: #F1FBFF;
					border-radius: 20rpx 20rpx 20rpx 20rpx;
					padding: 15rpx;
					box-sizing: border-box;

					image {
						width: 70rpx;
						height: 70rpx;
					}
				}

				.task-progress {
					flex: 1;
					height: 100%;
					margin-left: 20rpx;
					margin-right: 16rpx;

					.title {
						font-size: 28rpx;
						color: #333;
						font-weight: bold;
						line-height: 1.2;
					}

					.progressBar {
						position: relative;
						width: 90rpx;
						height: 6rpx;
						background: #F0F0F0;
						border-radius: 100px;
						overflow: hidden;

						.jindu {
							position: absolute;
							left: 0;
							top: 0;
							height: 6rpx;
							background: #FFA008;
							border-radius: 100px;
						}
					}

					.task-data {
						font-size: 26rpx;

						text:nth-child(1) {
							color: #FFA008;
						}

						text:nth-child(2),
						text:nth-child(3) {
							color: #999999;
						}
					}

				}

				.task-btn {
					padding: 8rpx 20rpx;
					box-sizing: border-box;
					background: linear-gradient(132deg, #2DD9FF 0%, #2D6DFF 100%);
					border-radius: 50rpx 50rpx 50rpx 50rpx;
					font-size: 28rpx;
					color: #fff;
					line-height: 1.5;
				}

				.task-btn1 {
					padding: 8rpx 20rpx;
					box-sizing: border-box;
					background: transparent;
					border-radius: 50rpx 50rpx 50rpx 50rpx;
					font-size: 28rpx;
					color: #2D74FF;
					line-height: 1.5;
				}
			}

			.taskitem:last-child {
				margin-bottom: 13rpx;
			}
		}
	}

	::v-deep {
		uni-swiper .uni-swiper-dots-horizontal .uni-swiper-dot {
			width: 6rpx;
			height: 6rpx;
			background: #D9D9D9;
		}

		uni-swiper .uni-swiper-dots-horizontal .uni-swiper-dot-active {
			width: 10rpx;
			background: linear-gradient(132deg, #2DD9FF 0%, #2D6DFF 100%);
		}
	}
</style>