<template>
	<view style="height: 100%;width: 100%; padding: 20rpx 30rpx;">
		<view class="list" v-for="item,index in doctorList" :key='index' @click.stop="clicklist" :data-id="item.id"
		 :data-index="index">
			<!-- 头像 -->
			<view class="portrait">
				<view style="padding-top: 20rpx;">
					<image class="img" :src="item.avatar"></image>
					<view class="bun_true" @click.stop="follow" :data-index="index" :data-id="item.id" v-if="item.is_collect==0">关注</view>
					<view class="bun_false" @click.stop="follow" :data-index="index" :data-id="item.id" v-else>已关注</view>
				</view>
			</view>
			<!-- 文字 -->
			<view class="text">
				<!-- 名字+标签 -->
				<view class="name">
					<view style="margin-right: 15rpx;">{{item.name}}</view>
					<view class="label" v-for="(itm,idx) in item.label_texts" :key="index">{{itm.label_name}}</view>
				</view>
				<!-- 科室 -->
				<view class="department">
					<text>科室:</text>
					<text style="color: #333333;">{{item.office.name||'暂无'}}</text>
					<text style="color: #333333;">{{item.qualification.name||'暂无'}}</text>
				</view>
				<!-- 选项 -->
				<view class="option">
					<view v-if="item.is_chat==1">图文</view>
					<view v-if="item.is_phone==1">电话</view>
					<view v-if="item.is_appoint==1">门诊</view>
				</view>
			</view>
		</view>
		<u-empty text="暂无数据" :show="show" mode="order" margin-top="250"></u-empty>
		<u-no-network></u-no-network>
		<view class="cu-tabbar-height"></view>
		<view class="cu-tabbar-height"></view>
	</view>
</template>

<script>
	export default {
		mounted() {
			this.gethome_doctor()
		},
		data() {
			return {
				//关注
				isfollow: false,
				//协议
				num: 1,
				imgitem: {
					istrue: false,
					name: "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
				},
				tcID: '套餐一', //ID
				tcTime: '一年', //套餐有效期
				tcContent: { //套餐内容
					content: '套餐一包含包含疫苗接种、门诊预约、儿保预约三项服务', //内容
					scope: '使用范围：家医团队可用，有效期内无限次、300元额度以内门诊预约与儿保预约无限制', //范围
					giving: '赠送XXXX保险：保险介绍' //赠送
				},
				tcTeam: [],
				doctorList: [],
				pageindex: 1,
				show:false
			}
		},
		onReachBottom() {
			this.gethome_doctor()
		},
		methods: {
			//关注
			follow: async function(e) {
				let res = await this.$request.post("/api/v1/collection/submitCollect", {
					type: 1,
					relation_id: e.currentTarget.dataset.id
				})
				if (res.status == 0) {
					if (res.data.is_collect == 0) {
						uni.showToast({
							title: "取消成功",
							icon: "none"
						})
						this.doctorList[e.currentTarget.dataset.index].is_collect = res.data.is_collect
					} else {
						uni.showToast({
							title: "关注成功",
							icon: "none"
						})
						this.doctorList[e.currentTarget.dataset.index].is_collect = res.data.is_collect
					}
				}
			},
			gethome_doctor: async function() {
				let res = await this.$request.post("/api/v1/docter/docterList", {
					page: this.pageindex,
					is_pack_docter:1
				})
				console.log(res)
				if (res.status == 0) {
					if (this.pageindex > res.data.last_page) {
						uni.showToast({
							title: "没有更多了",
							icon: "none"
						})
					} else {
						this.doctorList = this.doctorList.concat(res.data.data)
						this.pageindex++
					}
				}
				if (this.doctorList.length == 0) {
					this.show = true
				} else {
					this.show = false
				}
				console.log(this.doctorList)
			},
			clicklist(e) {
				uni.navigateTo({
					url: "../doctor_related/doctor_info?id=" + e.currentTarget.dataset.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.list {
		margin: 20rpx 0 10rpx 0;
		display: flex;
		width: 100%;
		height: 200rpx;
		border-radius: 15rpx;
		background-color: #FFFFFF;
		box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.08);

		.portrait {
			width: 30%;
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;



			.img {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}

			.bun_true {
				text-align: center;
				width: 80rpx;
				height: 36rpx;
				background-color: #D92975;
				margin: 0 10rpx;
				border-radius: 60rpx;
				position: relative;
				top: -20rpx;
				font-size: 20rpx;
				color: #FFFFFF;
				padding: 3rpx 0;
			}

			.bun_false {
				border: 1rpx solid #D92975;
				text-align: center;
				width: 80rpx;
				height: 36rpx;
				background-color: #FFFFFF;
				margin: 0 10rpx;
				border-radius: 60rpx;
				position: relative;
				top: -20rpx;
				font-size: 20rpx;
				color: #D92975;
				padding: 3rpx 0;
			}
		}

		//文字
		.text {
			width: 70%;
			height: 100%;

			padding: 20rpx 0;

			//名字+标签
			.name {
				font-size: 30rpx;
				font-weight: bold;
				display: flex;
				align-items: center;

				.label {
					font-weight: 400;
					margin-right: 15rpx;
					background-color: #E5F5FF;
					color: #0B73B9;
					width: 100rpx;
					height: 28rpx;
					font-size: 20rpx;
					border-radius: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}

			//科室
			.department {
				padding: 20rpx 0;
				color: #666666;

				text {
					margin-right: 15rpx;
				}
			}

			// 选项
			.option {
				display: flex;

				view {
					background-color: #E4E4E4;
					width: 100rpx;
					height: 48rpx;
					border-radius: 12px;
					margin-right: 15rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}
	}
</style>
