<template>
  <view class="asset-detail">
    <!-- 顶部导航栏 -->
   <customNavbar
      title="不动资产详情"
    ></customNavbar>
    <!-- 顶部信息块 -->
    <view class="top-block u-flex u-row-between u-p-20">
      <!-- 左侧轮播图 -->
      <view class="left-swiper">
        <u-swiper
          :list="asset.images"
          height="220"
          border-radius="12"
          autoplay
          interval="3000"
        ></u-swiper>
      </view>

      <!-- 右侧信息块 -->
      <view class="right-info u-flex u-flex-col u-justify-between">
        <view>
          <view class="asset-name">{{ asset.name }}</view>
          <view class="asset-community">所属小区：{{ asset.community }}</view>
          <view class="asset-rent">租金：<text class="price">¥{{ formatMoney(asset.rent) }}/月</text></view>
        </view>

        <view class="btn-group">
          <u-button
            size="mini"
            type="primary"
            icon="map"
            @click="viewVR"
          >
            查看VR图
          </u-button>
        </view>
      </view>
    </view>

    <view class="content">
<!-- 基本信息 -->
    <mycard title="资产信息">
      <view class="info-list">
        <u-cell-group>
          <u-cell-item title="资产编号" :value="asset.code" :arrow="false"/>
          <u-cell-item title="资产类别" :value="asset.category" :arrow="false"/>
          <u-cell-item title="资产面积" :value="asset.area + '㎡'" :arrow="false"/>
          <u-cell-item title="资产价值" :value="'¥' + formatMoney(asset.value)" :arrow="false"/>
          <u-cell-item title="权属单位" :value="asset.owner" :arrow="false"/>
        </u-cell-group>
      </view>
    </mycard>

    <!-- 位置信息 -->
    <mycard title="位置信息" >
      <view class="map-section">
        <u-cell-group>
          <u-cell-item title="地址" :value="asset.address" :arrow="false"/>
        </u-cell-group>

        <map
          :latitude="asset.lat"
          :longitude="asset.lng"
          :markers="markers"
          style="width: 100%; height: 300rpx; border-radius: 12rpx; margin-top: 20rpx;"
        ></map>
      </view>
    </mycard>

    <!-- 备注信息 -->
    <mycard title="备注信息">
      <view class="remark">
        {{ asset.remark || '暂无备注信息' }}
      </view>
    </mycard>
    </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 :phone="asset.contact" @reserve="showReserve = true" />
  </view>
</template>

<script>
import mycard from '../../components/card/mycard.vue';
import assetBottomBar from '../../components/bottom/assetBottomBar.vue';

export default {
  components:{
    mycard,
    assetBottomBar
  },
  data() {
    return {
         // 控制预约弹窗显示
      showReserve: false,

      // 预约表单数据
      reserveName: '',
      reservePhone: '',
      assetId: null,
      asset: {
        name: '',
        community: '',
        code: '',
        category: '',
        area: '',
        value: '',
        rent: '',
        owner: '',
        address: '',
        lat: 0,
        lng: 0,
        images: [],
        remark: '',
        isFavorite: false,
      },
      markers: [],
    };
  },
  onLoad(options) {
    this.assetId = options.id || 'A001';
    this.loadAssetDetail();
  },
  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: [
            'https://cdn.uviewui.com/uview/swiper/swiper1.png',
            'https://cdn.uviewui.com/uview/swiper/swiper2.png',
          ],
          remark: '该资产目前用于办公出租，维护状态良好。',
          isFavorite: false,
        };
        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;
    }
  },
};
</script>

<style lang="scss" scoped>
.asset-detail {
  background-color: #f7f8fa;
  min-height: 100vh;
  padding-bottom: 120rpx;
  padding-top: 175rpx; /* 给导航栏留空间 */
  .top-block {
    background-color: #fff;
    border-radius: 16rpx;
    margin: 20rpx;
    box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);

    .left-swiper {
      width: 45%;
    }

    .right-info {
      width: 50%;
      padding-left: 20rpx;

      .asset-name {
        font-size: 32rpx;
        font-weight: bold;
        color: #333;
        margin-bottom: 10rpx;
      }

      .asset-community {
        font-size: 26rpx;
        color: #666;
        margin-bottom: 10rpx;
      }

      .asset-rent {
        font-size: 26rpx;
        color: #444;

        .price {
          color: #e54d42;
          font-weight: bold;
          margin-left: 4rpx;
        }
      }

      .btn-group {
        margin-top: 20rpx;
        align-self: flex-start;
      }
    }
  }

.content {
  padding: 20rpx;
  background-color: #f5f6fa;
  min-height: 100vh;
  padding-bottom: 140rpx; /* 避免内容被遮住 */

  .info-list {
    padding: 10rpx 20rpx;
    background-color: #ffffff;
    border-radius: 12rpx;
    box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
  }

  .map-section {
    padding: 10rpx 20rpx 20rpx;
    background-color: #ffffff;
    border-radius: 12rpx;
    box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;

    map {
      width: 100%;
      height: 320rpx;
      border-radius: 12rpx;
      margin-top: 20rpx;
      overflow: hidden;
    }
  }

  .remark {
    padding: 20rpx;
    font-size: 28rpx;
    color: #555;
    line-height: 1.6;
    background-color: #ffffff;
    border-radius: 12rpx;
    box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
  }
}

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