<template>
	<view class="asset-detail">
		<!-- 顶部导航栏 -->
		<!--   <customNavbar
      title="资产详情" ref="navbar"/> -->

		<!-- <u-navbar title="资产详情" :autoBack="true" :background="background" title-color="#2D2B2C"
			back-icon-color="#2D2B2C">
		</u-navbar> -->
		<!-- 图片展示区 -->
		<view class="image-section" :style="{ paddingTop: navTotalHeight + 'px' }">
			<u-icon name="arrow-left" color="#000000" size="24px" @click="back"></u-icon>
			<image src="/static/30091712.jpg"></image>
			<!-- <AssetGallery
	  :insideImages="asset.images"
	  :vrImage="asset.vrImage"
	  :vrSrc="asset.vr"
	  :videos="asset.videos"
	  :plans="asset.plans"
	  :adImage="asset.adImage"
	  @vr-click="viewVR"
	  @video-play="playVideo"
	  @ad-click="onAdClick"
	/> -->
		</view>

		<!-- 资产基本信息 -->
		<view class="container">
			<view class="basic-info">
				<view class="info-header">
					<view class="category-tag">{{ asset.category }}</view>
					<view class="asset-name">{{ asset.name }}</view>
				</view>
				<view class="rent-price">¥1500/月</view>
				<view class="community-info">
					<text class="label">所属小区：</text>
					<text>{{ asset.community }}</text>
				</view>
				<view class="address-info">
					<text class="label">地址：</text>
					<text>{{ asset.address }}</text>
				</view>
				<button class="vr-btn" @click="viewVR">查看VR图</button>
			</view>

			<!-- 地图位置 -->
			<view class="map-container">
				<map :latitude="asset.lat" :longitude="asset.lng" :markers="markers"
					style="width: 92%; height: 300rpx;"></map>
			</view>

			<!-- 资产信息表格 -->
			<view class="asset-info-table">
				<view class="table-title">资产信息</view>
				<view class="table-content">
					<view class="table-row">
						<view class="row-item">
							<view class="item-label">编号</view>
							<view class="item-value">{{ asset.code }}</view>
						</view>
						<view class="row-item">
							<view class="item-label">面积</view>
							<view class="item-value">105㎡</view>
						</view>
					</view>
					<view class="table-row">
						<view class="row-item">
							<view class="item-label">类别</view>
							<view class="item-value">{{ asset.category }}</view>
						</view>
						<view class="row-item">
							<view class="item-label">价值</view>
							<view class="item-value">¥{{ formatMoney(asset.value) }}</view>
						</view>
					</view>
					<view class="table-row">
						<view class="row-item full-width">
							<view class="item-label">权属</view>
							<view class="item-value">{{ asset.owner }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 预约弹窗 -->
		<u-popup v-model="showReserve" mode="bottom" border-radius="20">
			<view class="popup-content">
				<text class="popup-title">预约看房</text>
				<u-input v-model="reserveName" placeholder="请输入姓名" />
				<u-input v-model="reservePhone" placeholder="请输入电话" />
				<u-button type="primary" @click="submitReserve">提交预约</u-button>
			</view>
		</u-popup>

		<!-- 底部导航栏 -->
		<assetBottomBar v-if="asset.status === 0" :phone="asset.contact" @reserve="showReserve = true" />
	</view>
</template>

<script>
	import mycard from '../../components/card/mycard.vue';
	import assetBottomBar from '../../components/bottom/assetBottomBar.vue';
	import AssetGallery from '../../components/gallery/AssetGallery.vue'
	export default {
		components: {
			mycard,
			assetBottomBar,
			AssetGallery
		},
		data() {
			// 静态资产数据
			const staticAsset = {
				name: '',
				community: '',
				code: '',
				category: '',
				area: 0,
				value: 0,
				rent: 0,
				owner: '',
				address: '',
				lat: 0,
				lng: 0,
				images: [],
				vrImage: '',
				vr: '',
				videos: [],
				plans: [],
				adImage: '',
				remark: '',
				isFavorite: false,
				status: 0,
				contact: ''
			};

			return {
				// 控制预约弹窗显示
				showReserve: false,
				navTotalHeight: 0,
				// 预约表单数据
				reserveName: '',
				reservePhone: '',
				assetId: null,
				// 直接使用静态数据
				asset: staticAsset,
				// 根据静态数据初始化标记
				markers: [{
					id: 1,
					latitude: staticAsset.lat,
					longitude: staticAsset.lng,
					title: staticAsset.name,
				}, ],
				background: {
					backgroundColor: '#ffffff',
					// 渐变色
					// backgroundImage: 'linear-gradient(-90deg, #F9DED9 0%, #F8DFC0 99%);'
				},
			};
		},
		onLoad(options) {
			this.assetId = options.id || 'A001';
			// 静态数据初始化
			this.loadAssetDetail();
			// this.recordView();
		},
		mounted() {
			// const navbar = this.$refs.navbar;
			// const navHeight = navbar.navContentHeight; // 直接拿子组件 data
			// this.navTotalHeight = navHeight; // 加上额外间距

		},
		methods: {
			// 模拟接口请求
			loadAssetDetail() {
				setTimeout(() => {
					console.log("fork数据")
					this.asset = {
						name: '广州市中心写字楼A栋',
						community: '天河国际商务区',
						code: 'GDZC2025001',
						category: '商业用房',
						area: 1250.5,
						value: 28000000,
						rent: 88000,
						owner: '广州市国资委',
						address: '广州市天河区体育西路88号',
						lat: 23.135,
						lng: 113.327,
						images: [{
							image: '/static/img/index/swiper/swiper3.jpg'
						}],
						remark: '该资产目前用于办公出租，维护状态良好。',
						isFavorite: false,
						status: 0
					};
					this.markers = [{
						id: 1,
						latitude: this.asset.lat,
						longitude: this.asset.lng,
						title: this.asset.name,
					}, ];
				}, 300);
			},
			formatMoney(num) {
				return Number(num).toLocaleString();
			},
			toggleFavorite() {
				this.asset.isFavorite = !this.asset.isFavorite;
				uni.showToast({
					title: this.asset.isFavorite ? '已收藏' : '取消收藏',
					icon: 'success',
				});
			},
			contactManager() {
				uni.makePhoneCall({
					phoneNumber: '400-123-4567',
				});
			},
			viewVR() {
				uni.showToast({
					title: '打开卫星图...',
					icon: 'none',
				});
				// 可扩展：跳转到 VR 页面或调用地图 API
			},
			submitReserve() {
				console.log('提交预约看房申请')
				this.showReserve = false;
			},
			recordView(assetId) {
				let lifeData = uni.getStorageSync('lifeData');
				let token = lifeData.vuex_token
				let url = "/assets/viewRecord";
				this.$u.get(url, {}, {
					'WT': token
				}).then(obj => {

				});
			},
			back(){
				// let pages = getCurrentPages();
				// let beforePage = pages[pages.length - 2];
				
				uni.navigateBack({
					// delta: 1,
					success: function() {
						// beforePage.onLoad(beforePage
						// 	.options); // 执行前一个页面的onLoad方法
					}
				})
			},
		},
	};
</script>

<style scoped>
	.image-section >>> .u-icon{
		position: absolute;
		z-index: 99;
		top: 80rpx;
		left: 36rpx;
	}
</style>

<style lang="scss" scoped>
	.asset-detail {
		background-color: #f7f8fa;
		min-height: 100vh;
		padding-bottom: 120rpx;
		padding-top: 0;
		/* 不再需要固定的顶部内边距，由动态计算的 navTotalHeight 控制 */
	}

	/* 图片展示区 */
	.image-section {
		width: 100%;
		background-color: #000;
	}

	.image-section image {
		width: 100%;
		height: 740rpx;
	}

	/* 基本信息区 */
	.container {
		width: 100%;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		background-color: #ffffff;
		margin-top: -50rpx;
		position: relative;
	}

	.basic-info {
		padding: 20rpx 30rpx;
		padding-top: 50rpx;
	}

	.info-header {
		display: flex;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.category-tag {
		background-color: #FCF2F3;
		color: #E9353C;
		font-size: 24rpx;
		padding: 5rpx 15rpx;
		border-radius: 4rpx;
		margin-right: 15rpx;
	}

	.asset-name {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		flex: 1;
	}

	.rent-price {
		font-size: 36rpx;
		color: #FF2F31;
		margin: 15rpx 0;
	}

	.community-info,
	.address-info {
		font-size: 26rpx;
		color: #666;
		margin-bottom: 10rpx;
		display: flex;
		align-items: center;
	}

	.label {
		color: #999;
		margin-right: 10rpx;
	}

	.vr-btn {
		background-color: #F34038;
		color: #fff;
		border: none;
		padding: 0 14rpx;
		border-radius: 6rpx;
		font-size: 24rpx;
		margin-top: -90rpx;
		float: right;
	}

	/* 地图容器 */
	.map-container {
		width: 100%;
		overflow: hidden;
		display: flex;
		justify-content: center;
	}

	/* 资产信息表格 */
	.asset-info-table {
		padding: 20rpx 30rpx;
		margin-bottom: 20rpx;
		padding-bottom: 100rpx;
	}

	.table-title {
		font-size: 30rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 20rpx;
	}

	.table-content {
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}

	.table-row {
		display: flex;
		flex-wrap: wrap;
		gap: 20rpx;
	}

	.row-item {
		flex: 1;
		min-width: 45%;
		display: flex;
		flex-direction: column;
		gap: 5rpx;
	}

	.row-item.full-width {
		min-width: 100%;
	}

	.item-label {
		font-size: 24rpx;
		color: #999;
	}

	.item-value {
		font-size: 28rpx;
		color: #333;
		font-weight: 500;
	}

	/* 预约弹窗 */
	.popup-content {
		padding: 40rpx 30rpx;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
	}

	.popup-title {
		display: block;
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		text-align: center;
		margin-bottom: 30rpx;
	}

	.u-input {
		margin-bottom: 20rpx;
	}

	.u-button {
		margin-top: 20rpx;
		border-radius: 50rpx;
	}
</style>