<template>
	<view class="page">
		<u-navbar title="提现记录" :border-bottom="false" :background="bgc" back-icon-color="#262B37" title-color='#262B37'
			title-size='36' height='36' id="navbar">
		</u-navbar>
        <view class="status-tabs">
              <view class="tab-item" :class="{ 'active': activeTab === 0 }" @click="changeTab(0)">
                全部
              </view>
              <view class="tab-item" :class="{ 'active': activeTab === 1 }" @click="changeTab(1)">
                待审核
              </view>
              <view class="tab-item" :class="{ 'active': activeTab === 2 }" @click="changeTab(2)">
                已审核
              </view>
			  <view class="tab-item" :class="{ 'active': activeTab === 3 }" @click="changeTab(3)">
			    提现失败
			  </view>
            </view>
            
            <!-- 提现记录列表 -->
            <scroll-view 
              @scrolltolower="handqixing" scroll-y
              class="record-list">
              <!-- 第一条记录：已打款 -->
              <view class="record-card" v-for="(item,index) in list" :key="index">
                <view class="record-header">
                  <view class="user-info">
                    <view class="user-role">{{item.no}}</view>
                  </view>
                  <!-- <view class="status-badge status-success">已打款</view> -->
				  <text class="status-badge status-success" v-if="item.status == 'WAIT_VERIFY'">提现中</text>
				  <text class="status-badge status-success" v-if="item.status == 'PAYING'">打款中</text>
				  <text class="status-badge status-success" v-if="item.status == 'SUCCESS'">已打款</text>
				  <text class="status-badge status-success" v-if="item.status == 'REJECTED'">已驳回</text>
				  <text class="status-badge status-success" v-if="item.status == 'FAILED'">打款失败</text>
                </view>
                <view class="record-details">
                  <view class="detail-row">
                    <view class="detail-label">提现金额(元)</view>
                    <view class="detail-value" style="color: #4297F3;">￥{{item.amount.toFixed(2)}}</view>
                  </view>
                  <view class="detail-row">
                    <view class="detail-label">实际到账(元)</view>
                    <view class="detail-value" style="color: #4297F3;">￥{{item.arrivalAmount.toFixed(2)}}</view>
                  </view>
                  <view class="detail-row">
                    <view class="detail-label">收款方式</view>
                    <view class="detail-value">{{item.channelName}}</view>
                  </view>
                  <view class="detail-row">
                    <view class="detail-label">申请日期</view>
                    <view class="detail-value">{{item.createTime}}</view>
                  </view>
                </view>
              </view>
			  <view class="" style="width: 100%;text-align: center;margin-top: 30rpx;color: #ccc;">
			  	  当前没有更多数据了...
			  </view>
            </scroll-view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				userId:'',
				pageNum:1,
				activeTab: 0, // 当前选中的标签
				scrollHeight: 0 ,// 滚动区域高度
				list:[],
				total:0
			}
		},
		onLoad(option) {
            this.userId = option.userId
			this.getlist()
			this.calculateScrollHeight()
		},
		 onReady() {
		    // 确保获取正确的窗口高度
		    setTimeout(() => {
		      this.calculateScrollHeight()
		    }, 100)
		  },
		methods: {
			// 上拉加载更多
			handqixing(){
				if(this.total > this.list.length){
					this.getlist()
				}
				console.log('11');
			},
			// 请求提现记录
			getlist() {
				let type = ''
				if(this.activeTab == 0){
					type = ''
				}else if(this.activeTab == 1){
					type = '&status=WAIT_VERIFY'
				}else if(this.activeTab == 2){
					type = '&statusList=PAYING,SUCCESS'
				}else if(this.activeTab == 3){
					type = '&statusList=REJECTED,FAILED'
				}
				this.$u.get(`/bst/withdraw/list?pageNum=${this.pageNum}&pageSize=20&orderByColumn=createTime&isAsc=desc&userId=${this.userId}` + type).then((res) => {
					if (res.code == 200) {
						this.total = res.total
						if(this.pageNum == 1){
							this.list = res.rows
							this.pageNum++
						}else{
							this.list = this.list.concat(res.rows)
							this.pageNum++
						}
					}
				})
			},
			// 切换标签
			    changeTab(index) {
			      this.activeTab = index
				  this.pageNum = 1
				  this.getlist()
			      // 这里可以根据标签筛选数据
			      console.log('切换到标签:', index)
			    },
			    
			    // 计算滚动区域高度
			    calculateScrollHeight() {
			      const systemInfo = uni.getSystemInfoSync()
			      const windowHeight = systemInfo.windowHeight
			      
			      // 获取页面各元素高度
			      const query = uni.createSelectorQuery().in(this)
			      query.select('.page-header').boundingClientRect()
			      query.select('.status-tabs').boundingClientRect()
			      query.exec(res => {
			        const headerHeight = res[0]?.height || 50
			        const tabsHeight = res[1]?.height || 44
			        
			        // 计算剩余可用高度
			        this.scrollHeight = windowHeight - headerHeight - tabsHeight - 20 // 20为底部安全距离
			      })
			    }
		}
	}
</script>

<style lang="scss">
page {
  min-height: 100vh;
  background-color: #f5f5f5; // 浅灰色背景
  box-sizing: border-box;
  
  .page-header {
    padding: 40rpx 0 30rpx;
    
    .page-title {
      font-size: 36rpx;
      font-weight: bold;
      color: #333;
    }
  }
  
  .status-tabs {
    display: flex;
    background-color: #fff;
	width: 750rpx;
    border-radius: 12rpx;
    padding: 4rpx;
    margin-bottom: 30rpx;
	padding-top: 20rpx;
    .tab-item {
      flex: 1;
      text-align: center;
      padding: 20rpx 0;
      font-size: 28rpx;
      color: #666;
      border-radius: 8rpx;
      transition: all 0.3s ease;
      
      &.active {
        background-color: #4297F3;
        color: #fff;
        font-weight: 500;
        box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.1);
      }
    }
  }
  
  .record-list {
	  height: 79vh;
	  overflow: scroll;
    .record-card {
	  width: 710rpx;
	  margin: auto;
      background-color: #fff;
      border-radius: 16rpx;
      padding: 30rpx;
      margin-bottom: 20rpx;
      box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
      
      .record-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 20rpx;
        border-bottom: 1rpx solid #eee;
        margin-bottom: 20rpx;
        
        .user-info {
          .user-role {
            font-size: 24rpx;
            color: #999;
            margin-bottom: 4rpx;
          }
          
          .user-name {
            font-size: 32rpx;
            font-weight: bold;
            color: #333;
          }
        }
        
        .status-badge {
          padding: 6rpx 16rpx;
          border-radius: 20rpx;
          font-size: 24rpx;
          font-weight: 500;
          
          &.status-success {
            background-color: rgba(52, 152, 219, 0.1);
            color: #3498db; // 蓝色状态
          }
          
          &.status-pending {
            background-color: rgba(52, 73, 94, 0.1);
            color: #34495e; // 深蓝色/灰色状态
          }
        }
      }
      
      .record-details {
        .detail-row {
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-bottom: 20rpx;
          
          &:last-child {
            margin-bottom: 0;
          }
          
          .detail-label {
            font-size: 28rpx;
            color: #666;
            flex-shrink: 0;
          }
          
          .detail-value {
            font-size: 28rpx;
            color: #333;
            font-weight: 500;
            text-align: right;
            flex: 1;
            margin-left: 20rpx;
            word-break: break-all;
            
            &.status-text {
              &.success {
                color: #3498db; // 蓝色
              }
              
              &.pending {
                color: #34495e; // 深蓝色/灰色
              }
            }
          }
        }
      }
    }
  }
}
</style>