<template>
	<view>
		<public-module></public-module>
		<view class="headers dis a-c j-c" :style="headerStyle">
			<text>掌柜合伙人</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 ">
					<text>今日状况</text>
					<image src="/static/home/icon1.png" class="image1" mode=""></image>
					<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="statistics">
				<u-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;"></u-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 mb-3">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo1.v1}}</text>
								<text>我的管理人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo1.v2}}</text>
								<text>管理人的合伙人</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo1.v3}}</text>
								<text>我今日新增管理人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo1.v4}}</text>
								<text>今日管理人邀请的合伙人</text>
							</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 mb-3">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo2.v1}}</text>
								<text>我的合伙人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo2.v2}}</text>
								<text>合伙人的工作室</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo2.v3}}</text>
								<text>我今日新增合伙人</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo2.v4}}</text>
								<text>今日合伙人邀请的工作室</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{teamOverviewInfo.vo2.v5}}</text>
								<text>今日保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo2.v6}}</text>
								<text>今日佣金</text>
							</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 mb-3">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo3.v1}}</text>
								<text>我的工作室</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo3.v2}}</text>
								<text>工作室下的业务团队</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo3.v3}}</text>
								<text>我今日新增工作室</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo3.v4}}</text>
								<text>今日工作室邀请的团队</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{teamOverviewInfo.vo3.v5}}</text>
								<text>今日保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo3.v6}}</text>
								<text>今日佣金</text>
							</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 mb-3">
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="closePartner">
								<text>{{teamOverviewInfo.vo4.v1}}</text>
								<text>我的团队</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo4.v2}}</text>
								<text>代理人人数</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;"
								@click="todayclosePartner">
								<text>{{teamOverviewInfo.vo4.v3}}</text>
								<text>我今日新增团队</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo4.v4}}</text>
								<text>今日新增代理人</text>
							</view>
							<view class="dis f-c a-c view" style="border-right: 1rpx solid #EEEEEE;">
								<text>{{teamOverviewInfo.vo4.v5}}</text>
								<text>今日保费</text>
							</view>
							<view class="dis f-c a-c view">
								<text>{{teamOverviewInfo.vo4.v6}}</text>
								<text>今日佣金</text>
							</view>
						</view>
					</template>
					<view class="earnings dis a-c j-s " @click="myEarnings">
						<view class="dis a-c ">
							<image src="/static/home/wallet.png" mode=""></image>
							<text>我的收益</text>
						</view>
						<u-icon name="arrow-right" size="30" color="rgba(35,40,50,0.5)"></u-icon>
					</view>
				</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;margin: 0 10rpx;">个代</text> 模式，业务员出单后，业务员的
					<text> <strong>佣金都会归到自己账户内</strong> </text>。</text>
				<text v-else>您选择的 <text style="color: #007AFF;">渠道</text> 模式，业务员出单后，业务员的
					<text> <strong>佣金都会归到团队长账户内由团队长进行分配</strong></text>。</text>
			</view>

		</u-modal>
	</view>
</template>
<script>
	import myDatePicker from '../components/todaydate-picker.vue';
	import QR from "@/common/wxqrcode.js"
	import {
		mapState,
		mapMutations
	} from "vuex"
	import {
		vShow
	} from "vue"
	export default {
		computed: {
			...mapState(['userInfo', "userCheckInfo"]),
		},
		components: {
			myDatePicker
		},
		data() {
			return {
				promptshow: false, //提示
				personTypeshow: false, //业务类型弹窗
				teamOverviewInfo: {}, //页面展示数据
				todayOverview: {}, //今日数据
				teamOverview: [{
						name: '我是创始人'
					}, {
						name: '我是管理人'
					},
					{
						name: '我是合伙人'
					},
					{
						name: '我是工作室'
					}
				],
				current: 0,
				showData: '全部数据',
				ShowModalCode: false,
				ShowModalCode1: false,
				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,
			}
		},
		async onShow(e) {
			this.type = uni.getStorageSync('type')
			this.showData = '全部数据',
				this.getList()

			// let res = await this.$http.post('/APPPartner/getHomePage', {
			// 	type: uni.getStorageSync('type'),
			// });
			// if (res.code == '200') {
			// 	this.totalList = res.data
			// }

		},

		methods: {
			//业务来源确定事件
			promptshowconfirm() {
				this.promptshow = false;
				this.ShowModalCodebusiness = false;
				uni.navigateTo({
					url: "/pages/institutional/invitationCode?grade=" + this.grade + "&deptSource=" + this
						.deptSource + '&userId=' + this.userInfo.sysUser.userId,
				})
				// 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) {
				const info = this.teamOverview[index];
				this.teamOverviewInfo = info;
				this.current = index;
			},
			async getList(beginTime, endTime) {
				let params = {
					type: this.type,
					"endTime": endTime || '',
					"beginTime": beginTime || '',
				}
				let res = await this.$http.post('/newAppPartner/getHomePage', params); //统计数据
				if (res.code == '200') {
					this.todayOverview = res.data.todayOverview; //今日数据
					this.teamOverview = res.data.teamOverview; //选项卡
					this.teamOverview.map(val => {
						val.gradeName = "我是" + val.gradeName;
						return val;
					})
					this.teamOverviewInfo = res.data.teamOverview[0]; //页面赋值第一条数据
				}
			},
			//业务来源确定
			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"
				})
			},
			//邀请码
			invitationCode(value) {
				this.grade = value;
				if (value == 4) { //区分合伙人和工作室  4==工作室
					this.ShowModalCodebusiness = true;
				} else {
					uni.navigateTo({
						url: "/pages/institutional/invitationCode?grade=" + value,
					})
				}
				// uni.navigateTo({
				// 	url: "/pages/index/applypartner?grade=" + value,
				// })
			},
		}
	}
</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;

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

			.image1 {
				width: 16rpx;
				height: 16rpx;
				position: absolute;
				top: 0;
				right: -20rpx;
			}

			.image3 {
				width: 166rpx;
				height: 20rpx;
				position: absolute;
				bottom: 0;
				left: 0;
			}

		}

		.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: 15rpx;

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

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

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

			.view {
				width: 49%;

				text:first-child {
					font-size: 36rpx;
					color: #333;
					font-weight: bold;
					margin-bottom: 4rpx;
				}

				text:last-child {
					font-size: 22rpx;
					color: #999;
				}
			}
		}

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

			text {
				font-size: 30rpx;
				color: #333;
				margin-left: 14rpx;
			}
		}
	}

	::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;
	}
</style>