<template>
	<view class="">
		<public-module></public-module>
		<view class="headers " :style="headerStyle">
			<view class="dis a-c j-start " style="padding: 0 15px;">
				<u-icon name="arrow-left" size="40" @tap="back"></u-icon>
				<text
					style="margin: auto;">{{ parentData.level ? `工作室(${chineseNumbers[parentData.level - 1]}级合伙人)` : '我的工作室' }}</text>
			</view>
		</view>

		<view class="body" style="background: #F8FAFE;margin-top: 85px;">
			<view class="partner-head">
				<seach @queryData="queryData" :directLsit='parentData' />
			</view>
			<!-- <card :cardData='directLsit'></card> -->
			<block v-for="(item, index) in directLsit" :key="index">
				<view class="card">
					<view style="padding: 10px 15px 0 10px">
						<view class="dis j-s card-title">
							<view>
								<text style="font-size: 16px;">{{ item.deptName }}({{ item.userName }})</text>
								<!-- <image v-if="parentData.partnerType==1 " style="display: inline-block; width: 45px;height:18px;vertical-align: sub;" src="/static/icon/jibie1.png" mode=""></image>
							<image v-if="parentData.partnerType==2 "  style="display: inline-block; width: 45px;height:18px;vertical-align: sub;" src="/static/icon/jibie.png" mode=""></image>
							<image v-if="parentData.partnerType==3"  style="display: inline-block; width: 45px;height:18px;vertical-align: sub;" src="/static/icon/jibie3.png" mode=""></image>
							<image v-if="parentData.partnerType==4"  style="display: inline-block; width: 45px;height:18px;vertical-align: sub;" src="/static/icon/jibie4.png" mode=""></image> -->
							</view>
							<text v-if="item.teamManNum > 0" @click="detail(item)">详情
								<image style="display: inline-block; width: 9px;height:9px;vertical-align: -1px;"
									src="/static/icon/right.png" mode=""></image>
							</text>
						</view>
						<view style="padding:0 15px;font-size: 10px;
					color: #666666;font-weight: 600;">下级团队共计
							<text style="font-size: 12px;color: #333333;font-weight: 600;">{{ item.deptNum }}</text>
							个
						</view>
						<view class="card-con dis j-c a-c">
							<view>
								<text>{{ item.suggestName || '未设置' }}</text>
								<text>推荐人</text>
							</view>
							<view>
								<text>{{ item.teamManNum }}</text>
								<text>会员总人数</text>
							</view>
							<view>
								<text>{{ item.sumPremium }}</text>
								<text>总保费</text>
							</view>
							<view style="border-right:none">
								<text>{{ item.extractFee }}</text>
								<text>总佣金</text>
							</view>
						</view>
					</view>
				</view>

			</block>
			<!-- <u-loadmore style="margin-top: 5px;" v-if="directLsit.length!=0" :status="status" />
			<o-empty v-if="directLsit.length==0" /> -->

		</view>
		<view id="_drag_button" class="drag" :style="'left: ' + left + 'px; top:' + top + 'px;'"
		@touchmove.stop.prevent="touchmove" @touchend="touchend">
			<image src="/static/code.png" mode="" @click.stop.prevent="btnClick"></image>
			<text>招募码</text>
		</view>
		<u-popup v-model="ShowModalCodebusiness" mode="bottom" border-radius="15">
			<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-popup v-model="ShowModalCode1" mode="bottom" border-radius="15">
			<view class="ShowModalCode-style ">
				<text>{{deptSource==1?'渠道':'个代'}}工作室招募码</text>
				<view class=" ShowModalCode-con">
					<view>扫码加入</view>
					<image :src="workImg" mode="widthFix" lazy-load style="width: 150px;"></image>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
import myDatePicker from '../components/date-picker.vue';
import seach from '../components/seach.vue';
import QR from "@/common/wxqrcode.js"
import {
	mapState,
	mapMutations
} from "vuex"
// import card from '../components/card.vue'
export default {
	components: { myDatePicker, seach },
	data() {
		return {
			ShowModalCodebusiness:false,
			ShowModalCode1:false,
			styles: [{
				value: '1',
				text: '渠道',
				notestext: '团队长加出单员模式，无分销模式，结费都在团队长处。',
				checked: true
			},
			{
				value: '2',
				notestext: '团队长加代理人模式，三级分销模式，结费方式为个人，有佣金。',
				text: '个代'
			}
			],
			deptSource: 1,
			workImg:'',
			top: 0,
			left: 0,
			width: 0,
			height: 0,
			offsetWidth: 0,
			offsetHeight: 0,
			windowWidth: 0,
			windowHeight: 0,
			isMove: true,
			edge: 10,
			startShow: false,
			year: [{
				lable: '日',
				startShow: false
			}, {
				lable: '月',
				startShow: false
			}, {
				lable: '季',
				startShow: false
			}, {
				lable: '年',
				startShow: false
			}, {
				lable: '自定义',
				startShow: false
			}],
			chineseNumbers: ['一', '二', '三', '四', '五', '六', '七', '八', '九'],
			headerStyle: {
				backgroundColor: 'transparent',
				backgroundImage: 'url("/static/beijing (2).png")',
				backgroundSize: 'cover',
				backgroundPosition: '',
				boxShadow: ''
				// 其他样式属性...
			},
			teamTabIndex: 0,
			directLsit: [],
			source: 0,
			totalPages: 0,
			totalSize: 0,
			status: 'loadmore',
			pageRequest: { //查询的默认条件
				pageNum: 1,
				pageSize: 20,
				userName: ''
			},
			parentData: {}
		}
	},
	computed: {
		...mapState(['userInfo', "userCheckInfo",]),
	},
	async onLoad(e) {
		this.parentData = JSON.parse(decodeURIComponent(e.key));
		// this.parentData.partnerType=this.parentData.level+1
		console.log(this.parentData)
		this.queryData()

	},
	mounted() {
		const sys = uni.getSystemInfoSync();

		this.windowWidth = sys.windowWidth;
		this.windowHeight = sys.windowHeight;

		// #ifdef APP-PLUS
		this.existTabBar && (this.windowHeight -= 50);
		// #endif
		if (sys.windowTop) {
			this.windowHeight += sys.windowTop;
		}
		const query = uni.createSelectorQuery().in(this);
		query.select('#_drag_button').boundingClientRect(data => {
			this.width = data.width;
			this.height = data.height;
			this.offsetWidth = data.width / 2;
			this.offsetHeight = data.height / 2;
			this.left = this.windowWidth - this.width - this.edge;
			if (this.bottomPx * 1 > 0) {
				this.top = this.windowHeight - this.height - this.bottomPx;
			} else {
				this.top = this.windowHeight - this.height - this.edge;
			}

		}).exec();
		//避免部分情况下图片加载延迟导致高度渲染出错
		setTimeout(() => {
			const query = uni.createSelectorQuery().in(this);
			query.select('#_drag_button').boundingClientRect(data => {
				this.width = data.width;
				this.height = data.height;
				this.offsetWidth = data.width / 2;
				this.offsetHeight = data.height / 2;
				this.left = this.windowWidth - this.width - this.edge;
				if (this.bottomPx * 1 > 0) {
					this.top = this.windowHeight - this.height - this.bottomPx;
				} else {
					this.top = this.windowHeight - this.height - this.edge;
				}
			}).exec();
		}, 200);
	},
	methods: {
		styleChange(e) {
			this.deptSource = e.detail.value
		},
		btnClick() {
			this.ShowModalCodebusiness = true
			this.deptSource = 1
		},
		ShowModalCodeSumbit(){
			this. ShowModalCode1 = true
			this.workImg = QR.createQrCodeImg(this.$base.h5BaseUrl + "/#/pages/index/applystudio?deptSource=" + this.deptSource + '&userId=' + this.userInfo.sysUser.userId, {
				size: parseInt(200) //二维码大小  
			})
		},
		touchmove(e) {
				// 单指触摸
				if (e.touches.length !== 1) {
					return false;
				}
				if (!this.isMove) {
				}
				this.isMove = true;

				this.left = e.touches[0].clientX - this.offsetWidth;

				let clientY = e.touches[0].clientY - this.offsetHeight;
				// #ifdef H5
				clientY += this.height;
				// #endif
				let edgeBottom = this.windowHeight - this.height - this.edge;

				// 上下触及边界
				if (clientY < this.edge) {
					this.top = this.edge;
				} else if (clientY > edgeBottom) {
					this.top = edgeBottom;
				} else {
					this.top = clientY
				}

			},
			touchend(e) {
				if (this.isDock) {
					let edgeRigth = this.windowWidth - this.width - this.edge;

					if (this.left < this.windowWidth / 2 - this.offsetWidth) {
						this.left = this.edge;
					} else {
						this.left = edgeRigth;
					}

				}
				if (this.isMove) {
					this.isMove = false;

				}

			},
		back() {
			uni.navigateBack({
				delta: 1, // 返回的页面数，如果是1表示返回上一页
				success: function () { }
			});

		},
		detail(item) {
			uni.navigateTo({
				url: "/pages/institutional/institutional?key=" + encodeURIComponent(JSON.stringify(item))
			})
		},
		onReachBottom() {
			if (this.pageRequest.pageNum >= this.totalPages) return;
			this.status = 'loading';
			this.pageRequest.pageNum = ++this.pageRequest.pageNum;
			setTimeout(async () => {
				let res = await this.$http.post('/sysPartner/querySysPartnerAPPPage', {
					...this.pageRequest,
					source: this.source
				});
				if (res.code == '200') {
					this.totalSize = res.data.totalSize;
					this.directLsit = [...this.directLsit, ...res.data.content];
				}
				if (this.pageRequest.pageNum >= this.totalPages) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},

		async queryData(data) {
			let params = {
				beginTime: data && data.beginTime || '',
				endTime: data && data.endTime || '',
				leaderIds: this.parentData.leaderIds,
				level: this.parentData.partnerType + 1 || this.parentData.level + 1,
				industrySector: data && data.industrySector || '',
				// ...this.pageRequest
			}
			let res = await this.$http.post('/APPPartner/partnerLeaderInfo', params);
			if (res.code == '200') {
				this.directLsit = res.data.partnerInfoVoList
				this.parentData = { ...this.parentData, ...res.data }
				this.totalPages = res.data.totalPages;
				this.totalSize = res.data.totalSize;
				if (this.pageRequest.pageNum >= res.data.totalPages) this.status = 'nomore';
				else this.status = 'loadmore';

			}
		},
		onShowDatePicker() { //显示
			this.showDatePicker = true;
		},
	}

}
</script>

<style lang="scss" scoped>
.headers {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	z-index: 999999;
	padding-top: 40px;
	height: 85px;

	text {
		font-size: 18px;
		font-weight: bold;
	}
}

.partner-head {
	background: #FFFFFF;
	color: #333333;
	font-size: 14px;

	i {
		margin-left: 2px;
		display: inline-block;
		width: 0;
		height: 0;
		border: 4px solid;
		border-color: #666666;
		border-bottom: 4px solid transparent;
		border-right: 4px solid transparent;
		border-left: 4px solid transparent;
	}

	.search-data {
		color: #666666;

		.active {
			color: #FFFFFF;
			background: linear-gradient(132deg, #2DD9FF 0%, #2D6DFF 100%);
		}

		text {
			// width: 25px;
			// height: 25px;
			// text-align: center;
			padding: 5px 8px;
			border: 1px solid #EEEEEE;
		}
	}
}

.sum-insurance {
	padding: 10px 0;

	view {
		text-align: center;
		width: 33.33%;
		border-right: 1px solid #EEEEEE;

		text {
			display: block;
		}

		text:first-child {
			font-weight: 600;
			font-size: 18px;
			color: #333333;
		}

		text:last-child {
			font-size: 10px;
			color: #999999;
		}
	}
}

.card {
	background: #FFFFFF;
	border-radius: 5px 5px 5px 5px;
	margin: 10px;
	background-image: url("/static/card.png");
	background-size: 100% 100%;
	border-top: 1px solid;
	border-image: linear-gradient(270deg, rgba(45, 217, 255, 0), rgba(45, 217, 255, 1), rgba(45, 217, 255, 0)) 1 1;

	.card-title {
		padding: 10px 15px;

		text:first-child {
			font-weight: 600;
			font-size: 16px;
			color: #333333;
		}

		text:last-child {
			font-size: 12px;
			color: #666666;
		}
	}

	.card-con {
		padding: 10px 0;

		view {
			text-align: center;
			width: 33.33%;
			border-right: 1px solid #EEEEEE;

			text {
				display: block;
			}

			text:first-child {
				font-weight: 600;
				font-size: 16px;
				color: #333333;
				line-height: 18px;
			}

			text:last-child {
				font-size: 10px;
				color: #999999;
			}
		}
	}

}

.drag {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	min-height: 80rpx;
	position: fixed;
	z-index: 999999;
	font-size: 12px;
	color: #FFFFFF;
	width: 50px;
	height: 50px;
	padding-top: 2px;
	background: linear-gradient(132deg, #2DD9FF 0%, #2D6DFF 100%);
	border-radius: 3px 3px 3px 3px;

	image {
		display: inline-block;
		width: 23px;
		height: 23px;
	}

	&.transition {
		transition: left .3s ease, top .3s ease;
	}

}
.ShowModalCode-business {
	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;
	}
}

.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;
}

.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;
}
.ShowModalCode-style {
	text:first-of-type {
		display: block;
		font-weight: 600;
		font-size: 16px;
		color: #333333;
		border: 1px solid #EEEEEE;
		padding: 15px;
		text-align: center;
	}
}
.popup-code {
	text {
		display: block;
		border-bottom: 1px solid #EEEEEE;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 16px;
		color: #666666;
	}
}

</style>
