<template>
	<!-- 禁止滚动穿透 -->
	<page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
	<view class="main">
		<view class="one" v-if="user.role!='Patient'">
			<view class="one_1">群组成员({{total||0}})</view>
			<view class="one_2">
				<view class="list" v-for="(item, index) in personList" :key="index" @tap="toChat(item,'1')">
					<view class="url">
						<image class="image"
							:src="item.icon&&item.icon.length>0?item.icon[0].url:config.user_url[0].url" mode="">
						</image>
					</view>
					<view class="name textOne">{{item.name||'暂无姓名'}}</view>
				</view>
			</view>
			<view class="one_3" v-if="total>20">
				<view class="more" @tap="toMore">查看更多群成员 <text class="iconfont icon-dayuhao"></text></view>
			</view>
		</view>
		<view class="two">
			<view class="two_1">医生信息</view>
			<view class="two_2">
				<image class="image"
					:src="doctorInfo.icon&&doctorInfo.icon.length>0?doctorInfo.icon[0].url:config.user_url[0].url"
					mode="">
				</image>
				<view class="name textOver">姓名：{{doctorInfo.name||'暂无'}}</view>
				<view class="other">
					<view class="other_1 textOne">
						<text>手机号：</text>{{doctorInfo.mobile||'暂无'}}
					</view>
					<view class="other_1 textOne">
						<text>医院名称：</text>{{doctorInfo.hos_name||'暂无'}}
					</view>
					<view class="other_1 textOne">
						<text>科室名称：</text>{{doctorInfo.dept_name||'暂无'}}
					</view>
					<view class="other_1 textOne">
						<text>职称：</text>{{doctorInfo.post||'暂无'}}
					</view>
					<view class="other_1 textOne">
						<text>职务：</text>{{doctorInfo.title||'暂无'}}
					</view>
					<view class="other_1 textOne">
						<text>简介：</text>{{doctorInfo.content||'暂无'}}
					</view>
				</view>
				<view class="bottom" v-if="user.role=='Patient'">
					<button class="button" size="mini" type="primary" @tap="toChat(doctorInfo,'0')">发起聊天</button>
				</view>
			</view>
		</view>
		<view class="thr">
			<view class="thr_1">群简介</view>
			<view class="thr_2">{{info.content||'暂无'}}</view>
		</view>
		<!-- 查看更多成员 -->
		<uni-popup ref="popup" background-color="#fff" type="bottom" :is-mask-click="false" @change="change">
			<view class="popup">
				<view class="close">
					<text>群成员</text>
					<text @click="toClose" class="iconfont icon-shanchu"></text>
				</view>
				<view class="info_1">
					<scroll-view scroll-y="true" class="scroll-view">
						<view class="list-scroll-view">
							<view class="list" v-for="(item, index) in list" :key="index" @tap="toChat(item,'1')">
								<view class="url">
									<image class="image"
										:src="item.icon&&item.icon.length>0?item.icon[0].url:config.user_url[0].url"
										mode="">
									</image>
								</view>
								<view class="name textOne">{{item.name||'暂无姓名'}}</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				user: {},
				config: {},
				info: {},
				// 部分群成员
				personList: [],
				// 全部群成员
				list: [],
				doctorInfo: {},
				total: 0,
				skip: 0,
				limit: 20,
				// 禁止滚动穿透
				show: false
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e && e.id || '');
			uni.setNavigationBarTitle({
				title: e && e.title || '群组'
			});
			await that.searchToken();
			await that.searchConfig();
			await that.search();
		},
		methods: {
			// 禁止滚动穿透
			change(e) {
				const that = this;
				that.show = e.show
			},
			// 用户信息
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) {
						const user = that.$jwt(res);
						that.$set(that, `user`, user);
					}
				} catch (e) {}
			},
			searchConfig() {
				const that = this;
				try {
					const res = uni.getStorageSync('config');
					if (res) that.$set(that, `config`, res);
				} catch (e) {}
			},
			async search() {
				const that = this;
				if (that.id) {
					const res = await that.$api(`/group/${that.id}`, 'GET', {})
					if (res.errcode == '0') {
						that.$set(that, `info`, res.data)
						that.$set(that, `total`, res.data.patients.length)
						that.$set(that, `doctorInfo`, res.data.doctor)
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none'
						});
					}
					// 群成员
					let info = {
						skip: that.skip,
						limit: that.limit,
						groupId: that.id
					}
					const arr = await that.$api(`/group/getPaitentList`, 'GET', {
						...info
					})
					if (arr.errcode == '0') {
						that.$set(that, `personList`, arr.data)
					} else {
						uni.showToast({
							title: arr.errmsg,
							icon: 'none'
						});
					}
				}
			},
			// 好友聊天
			toChat(item, type) {
				const that = this;
				if (type == '0') {
					uni.navigateTo({
						url: `/pagesHome/friend/index?doctorId=${item.id||item._id}&groupId=${that.id}&patientId=${that.user._id}&title=${item.name}`
					})
				} else {
					uni.navigateTo({
						url: `/pagesHome/friend/index?patientId=${item.id||item._id}&doctorId=${that.user._id}&groupId=${that.id}&title=${item.name}`
					})
				}
			},
			// 查看更多成员
			async toMore() {
				const that = this;
				// 群成员
				const res = await that.$api(`/group/getPaitentList`, 'GET', {
					groupId: that.id
				})
				if (res.errcode == '0') that.$set(that, `list`, res.data);
				that.$refs.popup.open()
			},
			// 关闭弹框
			toClose() {
				const that = this;
				that.$refs.popup.close();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		padding: 2vw;
		background-color: var(--f9Color);

		.one {
			background-color: var(--mainColor);

			.one_1 {
				text-align: center;
				padding: 2vw 0;
				font-size: var(--font16Size);
				font-weight: bold;
			}

			.one_2 {
				display: flex;
				flex-wrap: wrap;

				.list {
					display: flex;
					flex-direction: column;
					align-items: center;
					width: 15vw;
					margin: 2vw;

					.image {
						width: 15vw;
						height: 15vw;
						border-radius: 2vw;
					}

					.name {
						margin: 1vw 0 0 0;
						font-size: var(--font12Size);
						color: var(--f85Color);
					}
				}
			}

			.one_3 {
				.more {
					text-align: center;
					padding: 4vw;
					font-size: var(--font14Size);
					color: var(--f69Color);
				}
			}
		}

		.two {
			padding: 2vw;
			margin: 2vw 0;
			background-color: var(--mainColor);

			.two_1 {
				text-align: center;
				font-size: var(--font16Size);
				font-weight: bold;
			}

			.two_2 {
				padding: 2vw 0;

				.image {
					width: 20vw;
					height: 20vw;
					border-radius: 2vw;
				}

				.name {
					font-size: var(--font14Size);
					font-weight: bold;
				}

				.other {
					font-size: var(--font14Size);
					color: var(--f69Color);

					.other_1 {
						margin: 1vw 0 0 0;
					}
				}

				.bottom {
					text-align: center;

					.button {
						background-color: var(--f3CColor);
						color: var(--mainColor);
						font-size: var(--font14Size);
					}
				}
			}
		}

		.thr {
			padding: 2vw;
			margin: 2vw 0;
			background-color: var(--mainColor);

			.thr_1 {
				text-align: center;
				font-size: var(--font16Size);
				font-weight: bold;
			}

			.thr_2 {
				padding: 2vw 0;
				font-size: var(--font14Size);
				color: var(--f69Color);
			}
		}

		.uni-popup {
			z-index: 9999 !important;
		}

		.popup {
			display: flex;
			flex-direction: column;
			width: 100vw;
			height: 60vh;
			background-color: var(--f9Color);

			.close {
				display: flex;
				justify-content: space-between;
				padding: 2vw;

				text:first-child {
					font-size: var(--font16Size);
					font-weight: bold;
				}
			}

			.info_1 {
				position: relative;
				display: flex;
				flex-direction: column;
				height: 54vh;
				padding: 2vw;

				.list {
					display: flex;
					flex-direction: column;
					align-items: center;
					width: 15vw;
					margin: 2vw;

					.image {
						width: 15vw;
						height: 15vw;
						border-radius: 2vw;
					}

					.name {
						margin: 1vw 0 0 0;
						font-size: var(--font12Size);
						color: var(--f85Color);
					}
				}
			}
		}

		.scroll-view {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;

			.list-scroll-view {
				display: flex;
				flex-wrap: wrap;
				padding: 2vw;
			}
		}

	}
</style>