<template>
	<view class="page">
		<u-navbar title="旅行社" :border-bottom="false" :background="bgc" back-icon-color="#262B37" title-color='#262B37'
			title-size='36' height='36' id="navbar" :custom-back="btnfh">
		</u-navbar>
        
		<!-- 旅行社详情卡片 -->
		<view class="agency-detail-card" @click="btnxq">
			<image class="agency-detail-image" :src="agencyDetail.picture" mode="aspectFill"></image>
			<view class="agency-detail-info">
				<view class="agency-detail-title">{{ agencyDetail.name }} 				<u-icon name="arrow-right" size="28" color="#000"></u-icon> </view>
				<view class="agency-detail-desc">{{ agencyDetail.description == null ? '暂无简介' : agencyDetail.description }}</view>
				<u-rate :count="5" active-color="#FFB400" size="24" inactive-color="#b2b2b2" v-model="agencyDetail.averageRating" readonly></u-rate>
			</view>
		</view>

		<!-- 导游推荐区域 -->
		<view class="guide-recommendation">
			<view class="section-header">
				<view class="green-bar"></view>
				<text class="section-title">导游推荐</text>
			</view>
			
			<view class="guide-list">
				<view class="guide-item" v-for="(guide, index) in guideList" :key="index" @click="goToGuideDetail(guide)">
					<image class="guide-avatar" :src="guide.photo" mode="aspectFill"></image>
					<view class="guide-info">
						<view class="guide-name">{{ guide.name }}</view>
						<view class="guide-desc">{{ guide.description == null ? '暂无简介' : guide.description }}</view>
					</view>
				</view>
			</view>
			<view class="" style="width: 100%;margin-top: 30rpx;color: #ccc;text-align: center;" v-if="guideList.length == 0">
				暂无推荐导游...
			</view>
		</view>

		<!-- 旅行社评价区域 -->
		<view class="agency-comment-section">
			<view class="section-header agency-comment-header">
				<view class="" style="display: flex;align-items: center;">
					<view class="green-bar"></view>
					<text class="section-title">评价（{{ total || 0 }}）</text>
				</view>
				<view class="more-comment" @click="btndp">
					更多评价
					<u-icon name="arrow-right" color="#1EC28B" size="28"></u-icon>
				</view>
			</view>
			<view class="comment-list" v-if="plarr.length > 0">
				<view class="comment-item" v-for="(item, index) in plarr" :key="index">
					<view class="comment-top">
						<view class="comment-user">
							<image class="comment-avatar" :src="item.userAvatar" mode="aspectFill"></image>
							<view class="comment-user-info">
								<view class="comment-nickname">
									{{ item.nickName }}
								</view>
								<u-rate :count="5" active-color="#E7322C" size="24" inactive-color="#b2b2b2" v-model="item.rating" readonly></u-rate>
							</view>
						</view>
						<view class="comment-time">
							{{ item.createTime }}
						</view>
					</view>
					<view class="comment-content">
						{{ item.content }}
					</view>
					<view class="comment-images" v-if="item.mediaUrl">
						<image v-for="(val, idx) in item.mediaUrl.split(',')" :key="idx" :src="val" mode="aspectFill"></image>
					</view>
					<view class="comment-all" @click="btndp">
						全部{{ total }}条评论
						<u-icon name="arrow-right" color="#3D3D3D" size="28"></u-icon>
					</view>
				</view>
			</view>

			<view class="no-comment" v-else>
				暂无评价，快来抢沙发～
			</view>

			<!-- 写评价悬浮按钮 -->
			<image
				class="add-comment-btn"
				@click="btnaddpj"
				src="https://api.ccttiot.com/gR560ieYsn1o129725c14b972b2414473797127255c3.png"
				mode=""></image>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				agencyDetail: {},
				guideList: [],
				id:'',
				obj:{},
				fanhui:'',
				plarr:[],
				total:0
			}
		},
		onLoad(option) {
            console.log(option);
			this.id = option.id
			this.getxq()
			this.getdylist()
			this.getpinlun()
			if(option && option.fanhui){
				this.fanhui = option.fanhui
			}
		},
		// 分享到好友（会话）
		onShareAppMessage: function() {
			return {
				title: '玩转福鼎',
				path: '/page_fenbao/daoyou/lvxingshe?id=' + this.id + '&fanhui=1'
			}
		},
		// 分享到朋友圈  
		onShareTimeline: function() {
			return {
				title: '玩转福鼎',
				query: '',
				path: '/page_fenbao/daoyou/lvxingshe?id=' + this.id + '&fanhui=1'
			}
		},
		methods: {
			btnfh(){
				if(this.fanhui == 1){
					uni.reLaunch({
						url:'/pages/index/index'
					})
				}else{
					uni.navigateBack()
				}
			},
			// 请求旅行社详情
			getxq(){
				this.$u.get(`/app/travelAgency/detail/${this.id}`).then((res) => {
					if(res.code == 200){
						this.agencyDetail = res.data
					}
				})
			},
			// 查询推荐导游列表
			getdylist(){
				this.$u.get(`/app/tourGuide/list?pageNum=1&pageSize=999&agencyId=${this.id}`).then((res) => {
					if(res.code == 200){
						this.guideList = res.rows
					}
				})
			},
			
			// 这里可以添加跳转到导游详情页的逻辑
			goToGuideDetail(guide) {
				uni.navigateTo({
					url:'/page_fenbao/daoyou/daoyouxq?id=' + guide.id
				})
			},
			// 点击查看旅行社详情
			btnxq(){
				uni.navigateTo({
					url:'/page_fenbao/daoyou/lvxingshexq?id=' + this.id
				})
			},
			// 查询旅行社评价列表（根据旅行社id，类型为4）
			getpinlun(){
				this.$u.get(`/app/comment/list?bstId=${this.id}&bstTypes=4&pageNum=1&pageSize=1`).then((res) => {
					if(res.code === 200){
						this.plarr = res.rows || []
						this.total = res.total || 0
					}
				})
			},
			// 查看全部评价
			btndp(){
				uni.navigateTo({
					url:'/page_fenbao/daoyou/lvxingshe-dianpin?id=' + this.id
				})
			},
			// 写评价（评价旅行社）
			btnaddpj(){
				uni.navigateTo({
					url:'/page_fenbao/jiudian/addpj?btsid=' + this.id + '&type=4'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.page {
		background: #fff;
		min-height: 100vh;
	}

	// 旅行社详情卡片样式
	.agency-detail-card {
		display: flex;
		background: #fff;
		margin: 20rpx 30rpx;
		padding: 30rpx;
		border-radius: 15rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
		position: relative;
	}

	.agency-detail-image {
		width: 200rpx;
		height: 200rpx;
		border-radius: 15rpx;
		margin-right: 30rpx;
	}

	.agency-detail-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.agency-detail-title {
		font-size: 36rpx;
		font-weight: 600;
		color: #262B37;
		margin-bottom: 15rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.agency-detail-desc {
		font-size: 26rpx;
		color: #666;
		line-height: 1.4;
		margin-bottom: 20rpx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		overflow: hidden;
	}

	.arrow-icon {
		position: absolute;
		right: 30rpx;
		top: 50%;
		transform: translateY(-50%);
	}

	// 导游推荐区域样式
	.guide-recommendation {
		margin: 40rpx 30rpx 0;
	}

	.section-header {
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.green-bar {
		width: 8rpx;
		height: 40rpx;
		background: #4CAF50;
		border-radius: 4rpx;
		margin-right: 20rpx;
	}

	.section-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #262B37;
	}

	.guide-list {
		background: #fff;
		border-radius: 15rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.guide-item {
		display: flex;
		padding: 30rpx;
		border-bottom: 1rpx solid #F5F5F5;
		
		&:last-child {
			border-bottom: none;
		}
		
		&:active {
			background: #F8F8F8;
		}
	}

	.guide-avatar {
		width: 176rpx;
		height: 176rpx;
		border-radius: 10rpx;
		margin-right: 30rpx;
	}

	.guide-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.guide-name {
		font-size: 32rpx;
		font-weight: 600;
		color: #262B37;
		margin-bottom: 15rpx;
	}

	.guide-desc {
		font-size: 26rpx;
		color: #666;
		line-height: 1.4;
	}

	/* 旅行社评价区域样式 */
	.agency-comment-section {
		margin: 40rpx 30rpx 40rpx;
		position: relative;
		padding-bottom: 160rpx;
	}

	.agency-comment-header {
		justify-content: space-between;
	}

	.more-comment {
		font-size: 26rpx;
		color: #1EC28B;
		display: flex;
		align-items: center;
	}

	.comment-summary {
		width: 710rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 10rpx;
	}

	.score-box {
		display: flex;
		align-items: center;
	}

	.score-number {
		font-weight: 600;
		font-size: 64rpx;
		color: #1EC28B;
		margin-right: 14rpx;
	}

	.score-text text {
		font-size: 24rpx;
		color: #606060;
		display: block;
	}

	.comment-list {
		margin-top: 28rpx;
	}

	.comment-item {
		background: #f3f3f3;
		border-radius: 20rpx;
		margin: auto;
		padding: 32rpx 24rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
	}

	.comment-top {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.comment-user {
		display: flex;
		align-items: center;
	}

	.comment-avatar {
		width: 68rpx;
		height: 68rpx;
		border-radius: 50%;
		margin-right: 14rpx;
	}

	.comment-nickname {
		font-weight: 600;
		font-size: 28rpx;
		color: #3D3D3D;
	}

	.comment-time {
		font-size: 26rpx;
		color: #606060;
	}

	.comment-content {
		font-size: 28rpx;
		color: #3D3D3D;
		margin-top: 22rpx;
		line-height: 1.6;
		word-wrap: break-word;
	}

	.comment-images {
		margin-top: 28rpx;
		display: flex;
		flex-wrap: wrap;
		gap: 10rpx;
	}

	.comment-images image {
		width: 210rpx;
		height: 210rpx;
		border-radius: 14rpx;
	}

	.comment-all {
		font-size: 28rpx;
		color: #3D3D3D;
		margin-top: 28rpx;
		width: 100%;
		text-align: center;
	}

  
	.no-comment {
		width: 100%;
		text-align: center;
		margin-top: 30rpx;
		color: #ccc;
		font-size: 26rpx;
	}

	.add-comment-btn {
		width: 120rpx;
		height: 126rpx;
		position: fixed;
		right: 30rpx;
		bottom: 560rpx;
		z-index: 99;
	}

</style>