<template>
  <view class="order-container">
    <!-- 状态切换 -->
    <view class="tab-bar">
      <view 
        v-for="(tab, index) in tabs" 
        :key="index"
        class="tab-item"
        :class="{ active: currentTab === index }"
        @click="switchTab(index)"
      >
        {{ tab }}
      </view>
    </view>

    <!-- 订单列表 -->
    <view class="order-list">
      <view class="order-item" v-for="(order, index) in orderList" :key="index">
        <view class="order-header">
          <text class="order-no">订单号：{{ order.orderNo }}</text>
          <text class="order-status" :class="order.status">{{ order.statusText }}</text>
        </view>
        <view class="order-content">
          <view class="device-info">
            <text class="device-name">共享风扇</text>
            <text class="device-id">设备号：{{ order.deviceId }}</text>
          </view>
          <view class="time-info">
            <view class="time-item">
              <text class="label">开始时间：</text>
              <text class="value">{{ order.startTime }}</text>
            </view>
            <view class="time-item">
              <text class="label">结束时间：</text>
              <text class="value">{{ order.endTime || '-' }}</text>
            </view>
          </view>
          <view class="price-info">
            <text class="amount">￥{{ order.amount }}</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 无数据提示 -->
    <view class="empty-tip" v-if="orderList.length === 0">
      <view class="empty-icon"></view>
      <text>暂无订单记录</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      currentTab: 0,
      tabs: ['全部', '使用中', '已完成'],
      orderList: [
        {
          orderNo: 'ORDER202403200001',
          status: 'using',
          statusText: '使用中',
          deviceId: 'FAN001',
          startTime: '2024-03-20 15:30',
          endTime: '',
          amount: '2.00'
        },
        {
          orderNo: 'ORDER202403190001',
          status: 'finished',
          statusText: '已完成',
          deviceId: 'FAN002',
          startTime: '2024-03-19 13:00',
          endTime: '2024-03-19 15:00',
          amount: '4.00'
        }
      ]
    }
  },
  methods: {
    switchTab(index) {
      this.currentTab = index
      // TODO: 根据状态获取订单列表
    }
  }
}
</script>

<style lang="scss" scoped>
.order-container {
  min-height: 100vh;
  background: #f8f8f8;

  .tab-bar {
    display: flex;
    background: #fff;
    padding: 20rpx 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);

    .tab-item {
      flex: 1;
      text-align: center;
      font-size: 28rpx;
      color: #666;
      position: relative;
      padding: 20rpx 0;

      &.active {
        color: #1976D2;
        font-weight: 500;

        &::after {
          content: '';
          position: absolute;
          bottom: 0;
          left: 50%;
          transform: translateX(-50%);
          width: 40rpx;
          height: 4rpx;
          background: #1976D2;
          border-radius: 2rpx;
        }
      }
    }
  }

  .order-list {
    padding: 20rpx;

    .order-item {
      background: #fff;
      border-radius: 20rpx;
      margin-bottom: 20rpx;
      padding: 30rpx;
      box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);

      .order-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 20rpx;
        border-bottom: 1rpx solid #f5f5f5;

        .order-no {
          font-size: 26rpx;
          color: #666;
        }

        .order-status {
          font-size: 26rpx;
          
          &.using {
            color: #1976D2;
          }
          
          &.finished {
            color: #4CAF50;
          }
        }
      }

      .order-content {
        padding-top: 20rpx;

        .device-info {
          margin-bottom: 20rpx;

          .device-name {
            font-size: 32rpx;
            color: #333;
            font-weight: 500;
            margin-right: 20rpx;
          }

          .device-id {
            font-size: 26rpx;
            color: #999;
          }
        }

        .time-info {
          .time-item {
            font-size: 26rpx;
            color: #666;
            margin-bottom: 10rpx;

            .label {
              color: #999;
            }
          }
        }

        .price-info {
          text-align: right;
          margin-top: 20rpx;

          .amount {
            font-size: 36rpx;
            color: #FF9800;
            font-weight: 500;
          }
        }
      }
    }
  }

  .empty-tip {
    padding: 100rpx 0;
    text-align: center;
    color: #999;
    font-size: 28rpx;

    .empty-icon {
      width: 200rpx;
      height: 200rpx;
      margin: 0 auto 20rpx;
      background: #f0f0f0;
      border-radius: 50%;
    }
  }
}
</style> 