<template>
  <view class="lease-page">
    <!-- 头部区域 -->
    <custom-nav-bar2 color="#FFDECB" title="租赁申请"></custom-nav-bar2>
    <view class="header">
      <image
        :src="commonEnum.FIRE_BACKGROUND_FULL"
        class="fire-background-full"
        mode="aspectFill"
      ></image>
    </view>

    <!-- 主要内容区域 -->
    <view class="main-content">
      <!-- 租赁信息表单 -->
      <view class="form-section">
        <view class="section-header">
          <view class="section-indicator"></view>
          <text class="section-title">填写租赁信息</text>
        </view>

        <view class="form-fields">
          <!-- 姓名 -->
          <view class="form-item">
            <text class="field-label">姓名</text>
            <input v-model="formData.name" class="field-input" placeholder="请输入姓名" />
          </view>

          <!-- 手机号 -->
          <view class="form-item">
            <text class="field-label">手机号</text>
            <input
              v-model="formData.phone"
              class="field-input"
              placeholder="请填写手机号"
              type="number"
            />
          </view>

          <!-- 地址 -->
          <map-location
            v-model="formData.address"
            label="地址"
            placeholder="请输入或选择收货地址"
            @location-success="onLocationSuccess"
            @location-error="onLocationError"
            @use-location="onUseLocation"
            @map-opened="onMapOpened"
          />

          <!-- 详细位置 -->
          <view class="form-item">
            <text class="field-label">详细位置</text>
            <input v-model="formData.detailAddress" class="field-input" placeholder="例:6栋201室" />
          </view>

          <!-- 租赁设备 -->
          <view class="form-item">
            <text class="field-label">租赁设备</text>
            <view class="selector" @click="selectEquipment">
              <text class="selector-text">{{ formData.equipment || '选择设备类型' }}</text>
              <text class="arrow-icon">></text>
            </view>
          </view>

          <!-- 租赁周期 -->
          <view class="form-item">
            <text class="field-label">租赁周期</text>
            <view class="selector" @click="selectPeriod">
              <text class="selector-text">{{ formData.period || '1年' }}</text>
              <text class="arrow-icon">></text>
            </view>
          </view>
        </view>
      </view>

      <!-- 支付区域 -->
      <view class="payment-section">
        <button class="pay-button" @click="handlePayment">立即支付 ¥{{ totalAmount }}</button>

        <view class="payment-details">
          <view class="details-header" @click="toggleDetails">
            <text class="details-title">明细</text>
            <view :class="{ expanded: showDetails }" class="arrow-wrapper">
              <image :src="commonEnum.DOWN_ARROW" class="details-arrow"></image>
            </view>
          </view>

          <view v-if="showDetails" class="details-content">
            <view class="detail-item">
              <text class="detail-label">租金</text>
              <text class="detail-value">¥{{ totalAmount }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <!-- 底部导航已由系统tabBar处理 -->
  </view>
</template>

<script>
import commonEnum from '../../enum/commonEnum'
import MapLocation from '@/components/map-location/map-location.vue'

export default {
  name: 'LeasePage',
  components: {
    MapLocation
  },
  computed: {
    commonEnum() {
      return commonEnum
    },
  },
  onLoad() {
    // 页面加载时获取当前位置
    //this.getCurrentLocation()
  },
  data() {
    return {
      formData: {
        name: '张珊珊',
        phone: '',
        address: '',
        detailAddress: '',
        equipment: '',
        period: '1年',
      },
      showDetails: false,
      totalAmount: '100.10',
    }
  },
  methods: {
    // 地图组件事件处理
    onLocationSuccess(location) {
      console.log('位置获取成功:', location)
      // 可以在这里处理位置获取成功后的逻辑
    },

    onLocationError(error) {
      console.error('位置获取失败:', error)
      // 可以在这里处理位置获取失败后的逻辑
    },

    onUseLocation(location) {
      console.log('使用位置:', location)
      // 可以在这里处理使用位置后的逻辑
    },

    onMapOpened() {
      console.log('地图已打开')
      // 可以在这里处理地图打开后的逻辑
    },
    selectEquipment() {
      // 选择设备逻辑
      uni.showActionSheet({
        itemList: ['节能灶', '燃烧器', '燃气灶', '电磁炉'],
        success: res => {
          const equipmentList = ['节能灶', '燃烧器', '燃气灶', '电磁炉']
          this.formData.equipment = equipmentList[res.tapIndex]
        },
      })
    },
    selectPeriod() {
      // 选择租赁周期逻辑
      uni.showActionSheet({
        itemList: ['1个月', '3个月', '6个月', '1年', '2年'],
        success: res => {
          const periodList = ['1个月', '3个月', '6个月', '1年', '2年']
          this.formData.period = periodList[res.tapIndex]
        },
      })
    },
    toggleDetails() {
      this.showDetails = !this.showDetails
    },
    handlePayment() {
      // 支付逻辑
      uni.showModal({
        title: '确认支付',
        content: `确认支付 ¥${this.totalAmount} 吗？`,
        success: res => {
          if (res.confirm) {
            uni.showToast({
              title: '支付成功',
              icon: 'success',
            })
          }
        },
      })
    },
    // 页面跳转现在由系统tabBar处理
    goToHome() {
      uni.switchTab({
        url: '/pages/index/index',
      })
    },
    goToProfile() {
      uni.switchTab({
        url: '/pages/profile/profile',
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.lease-page {
  position: relative;
  background: #f3f5f6;
  border: #120d0d solid 2rpx;
}

// 头部区域
.header {
  position: relative;
  //border: #120d0d solid 2rpx;
  background: #fedfcd;

  .fire-background-full {
    position: relative;
    left: 30rpx;
    width: 750rpx;
    height: 592rpx;
  }
}

// 主要内容区域
.main-content {
  position: relative;
  top: -220rpx;
  background: #ffffff;
  border-radius: 40rpx 40rpx 0 0;
  margin: 0 30rpx;
  padding: 40rpx;
  min-height: 60vh;
  //border: #120d0d solid 2rpx;
  //box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.3);
}

// 表单区域
.form-section {
  margin-bottom: 60rpx;
  //border: #0c1387 solid 2rpx;

  .section-header {
    display: flex;
    align-items: center;
    margin-bottom: 40rpx;
    //border: red solid 2rpx;

    .section-indicator {
      width: 8rpx;
      height: 40rpx;
      background: #f15a04;
      border-radius: 4rpx;
      margin-right: 20rpx;
    }

    .section-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
    }
  }
}

.form-fields {
  .form-item {
    //margin-bottom: 40rpx;
    display: flex;
    align-items: center;
    border-bottom: 1rpx solid #d8d8d8;

    .field-label {
      display: block;
      font-size: 28rpx;
      color: #333;
      font-weight: 400;
      flex: 1;
      //border: 2rpx solid #d81313;
    }

    .field-input {
      //border: 2rpx solid #d81313;
      flex: 3;
      height: 80rpx;
      padding: 0 20rpx;
      font-size: 28rpx;

      &:focus {
        border-color: #ff9a9e;
        background: #fff;
      }
    }
  }
}



// 选择器
.selector {
  flex: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80rpx;

  border-radius: 12rpx;
  padding: 0 20rpx;

  transition: all 0.3s ease;

  &:active {
    background: #f0f0f0;
    border-color: #ff6b6b;
  }

  .selector-text {
    font-size: 28rpx;
    color: #666;
  }

  .arrow-icon {
    font-size: 24rpx;
    color: #999;
    transition: transform 0.3s ease;
  }

  &:active .arrow-icon {
    transform: scale(1.2);
  }
}

// 支付区域
.payment-section {
  display: flex;
  flex-direction: column;

  .pay-button {
    width: 100%;
    height: 100%;
    background: #f15a04;
    color: #fff;
    border: none;
    border-radius: 10rpx;
    font-size: 32rpx;
    font-weight: bold;
    margin-bottom: 40rpx;
    box-shadow: 0 10rpx 30rpx rgba(255, 154, 158, 0.3);
  }

  .payment-details {
    .details-header {
      display: flex;
      align-items: center;

      padding: 20rpx 0;
      border-bottom: 2rpx solid #f0f0f0;

      .details-title {
        font-size: 28rpx;
        color: #f15a04;
        padding-right: 10rpx;
      }

      .arrow-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        transition: transform 0.3s ease;

        &.expanded {
          transform: rotate(180deg);
        }
      }

      .details-arrow {
        width: 20rpx;
        height: 10rpx;
      }
    }

    .details-content {
      padding: 20rpx 0;

      .detail-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20rpx;

        .detail-label {
          font-size: 28rpx;
          color: #868686;
        }

        .detail-value {
          font-size: 28rpx;
          color: #3d3d3d;
          font-weight: bold;
        }
      }
    }
  }
}

// 底部导航样式已移除，使用系统tabBar

// 动画
@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
</style>
