<template>
  <view class="exchange-record">
    <!-- 自定义tabs -->
    <view class="custom-tabs">
      <view 
        v-for="(tab, index) in tabList" 
        :key="index" 
        class="tab-item" 
        @click="tabChange(index)"
      >
        <text class="tab-text" :class="{ active: currentTab === index }">{{ tab.name }}</text>
        <view v-if="currentTab === index" class="tab-line"></view>
      </view>
    </view>
    
    <!-- 兑换记录列表 -->
    <view class="record-list">
      <view 
        v-for="(item, index) in list" 
        :key="index" 
        class="record-item"
        @click="viewDetail(item)"
      >
        <image class="record-image" :src="item.image" mode="aspectFit"></image>
        <view class="record-content">
          <view class="record-info">
            <view class="title-row">
              <text class="record-title">{{ item.title }}</text>
            </view>
            <view class="record-points">
              <uv-icon name="integral" size="16" color="#218cdd"></uv-icon>
              <text class="points-text">{{ item.price }}积分</text>
            </view>
            <view class="record-time">
              <uv-icon name="clock" size="14" color="#999"></uv-icon>
              <text class="time-text">兑换时间：{{ item.createTime }}</text>
            </view>
          </view>
          <view class="record-action">
            <uv-button 
              v-if="item.status === '0'"
              type="primary" 
              size="small" 
              text="确认领取"
              shape="circle"
              @click.stop="viewDetail(item)"
            ></uv-button>
            <uv-button 
              v-else-if="item.status === '1'"
              type="success" 
              size="small" 
              text="查看详情"
              shape="circle"
              @click.stop="viewDetail(item)"
            ></uv-button>
            <uv-button 
              v-else
              type="error" 
              size="small" 
              text="已取消"
              shape="circle"
              disabled
            ></uv-button>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import MixinList from '@/mixins/list'
export default {
  mixins: [MixinList],
  data() {
    return {
      currentTab: 0,
      mixinListApi: 'user.queryOrderList',
      tabList: [
        { name: '待领取' },
        { name: '已领取' },
        { name: '系统取消' }
      ],

    }
  },
  methods: {
    mixinSetParams() {
      return {
        status: this.currentTab
      }
    },
    tabChange(index) {
      this.currentTab = index
      this.initPage()
      this.getList(true)
    },

    viewDetail(item) {
      // 查看详情逻辑 - 跳转到兑换详情页面
      let status = 'pending'
      if (this.currentTab === 1) {
        status = 'received'
      } else if (this.currentTab === 2) {
        status = 'cancelled'
      }
      
      uni.navigateTo({
        url: `/subPages/my/exchangeDetail?id=${item.id}&status=${status}`
      })
    },


  }
}
</script>

<style lang="scss" scoped>
.exchange-record {
  background-color: #f5f5f5;
  min-height: 100vh;
  
  .custom-tabs {
    display: flex;
    background-color: #fff;
    border-bottom: 1rpx solid #e5e5e5;
    
    .tab-item {
      flex: 1;
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 30rpx 0;
      cursor: pointer;
      
      .tab-text {
        font-size: 28rpx;
        color: #666;
        transition: color 0.3s;
        
        &.active {
          color: #218cdd;
          font-weight: bold;
        }
      }
      
      .tab-line {
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 60rpx;
        height: 4rpx;
        background-color: #218cdd;
        border-radius: 2rpx;
      }
    }
  }
  
  .record-list {
    padding: 20rpx;
    
    .record-item {
      display: flex;
      align-items: flex-start;
      margin-bottom: 30rpx;
      background: #fff;
      border-radius: 12rpx;
      padding: 20rpx;
      
      .record-image {
        width: 215rpx;
        height: 215rpx;
        border-radius: 8rpx;
        margin-right: 20rpx;
        flex-shrink: 0;
      }
      
      .record-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        
        .record-info {
          display: flex;
          flex-direction: column;
          margin-bottom: 20rpx;
          
          .title-row {
            margin-bottom: 10rpx;
          }
          
          .record-title {
            font-size: 22rpx;
            // font-weight: bold;
            color: #000;
            line-height: 1.4;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
          }
          
          .record-points {
            display: flex;
            align-items: center;
            margin-bottom: 8rpx;
            
            .points-text {
              font-size: 26rpx;
              color: #218cdd;
              font-weight: bold;
              margin-left: 6rpx;
            }
          }
          
          .record-time {
            display: flex;
            align-items: center;
            
            .time-text {
              font-size: 22rpx;
              color: #999;
              margin-left: 6rpx;
            }
          }
        }
        
        .record-action {
          display: flex;
          justify-content: flex-end;
          // padding-top: 10rpx;
          border-top: 1rpx solid #f0f0f0;
          
        }
      }
    }
  }
}
</style>