<view class="page-container">
  <!-- 固定顶部区域（筛选 + 统计） -->
  <view class="fixed-header">
    <view class="header-bar">
      <text class="title">我的下级</text>
      <view class="refresh-btn" bindtap="shuaxinShuju">↻</view>
    </view>

    <!-- 搜索栏 -->
    <view class="search-box">
      <input class="search-input" placeholder="搜索ID/昵称" value="{{keyword}}" bindinput="onKeywordInput" />
      <view class="search-icon" bindtap="applyFilter">🔍</view>
    </view>

    <!-- 筛选行 -->
    <view class="filter-row">
      <view class="filter-item">
        <text>账号状态</text>
        <picker mode="selector" range="{{['全部','正常','封禁']}}" bindchange="onZhanghaoChange">
          <view class="picker-trigger">
            {{zhanghaozhuangtai === null ? '全部' : (zhanghaozhuangtai === 1 ? '正常' : '封禁')}}
          </view>
        </picker>
      </view>
      <view class="filter-item">
        <text>在线状态</text>
        <picker mode="selector" range="{{['全部','在线','离线']}}" bindchange="onZaixianChange">
          <view class="picker-trigger">
            {{zaixianzhuangtai === null ? '全部' : (zaixianzhuangtai === 1 ? '在线' : '离线')}}
          </view>
        </picker>
      </view>
      <view class="filter-btn" bindtap="applyFilter">筛选</view>
    </view>

    <!-- 统计卡片 -->
    <view class="stats-cards">
      <view class="stat-item"><text class="stat-num">{{yaoqingzongshu}}</text><text class="stat-label">邀请总数</text></view>
      <view class="stat-item"><text class="stat-num">{{zaixianCount}}</text><text class="stat-label">在线</text></view>
      <view class="stat-item"><text class="stat-num">{{zhengchangCount}}</text><text class="stat-label">正常</text></view>
      <view class="stat-item"><text class="stat-num">{{fengjinCount}}</text><text class="stat-label">封禁</text></view>
    </view>
  </view>

  <!-- 可滚动列表区域（占据剩余高度） -->
  <scroll-view 
    class="list-scroll" 
    scroll-y 
    enable-back-to-top 
    bindscrolltolower="shanglaJiazaiGengduo" 
    lower-threshold="80"
  >
    <view class="list-container">
      <block wx:for="{{dashouList}}" wx:key="uid">
        <view class="dashou-card">
          <image class="avatar" src="{{item.touxiangUrl}}" mode="aspectFill" />
          <view class="info-right">
            <view class="row1">
              <text class="nick">{{item.nicheng}}</text>
              <view class="badges">
                <text class="badge {{item.zaixianzhuangtai==1?'online':'offline'}}">{{item.zaixianzhuangtai==1?'在线':'离线'}}</text>
                <text class="badge {{item.zhanghaozhuangtai==1?'normal':'banned'}}">{{item.zhanghaozhuangtai==1?'正常':'封禁'}}</text>
              </view>
            </view>
            <text class="uid">ID: {{item.uid}}</text>
            <view class="row2">
              <text class="tag">接单 {{item.jiedanzongliang || 0}}</text>
              <text class="tag">成交 {{item.chengjiaozongliang || 0}}</text>
              <text class="tag">退款 {{item.tuikuanliang || 0}}</text>
              <text class="tag">余额 ¥{{item.yue || '0.00'}}</text>
            </view>
            <view class="contact-btn" data-uid="{{item.uid}}" bindtap="contactDashou">联系</view>
          </view>
        </view>
      </block>

      <!-- 加载更多按钮（新增） -->
      <view wx:if="{{hasMore && !isLoadingMore}}" class="load-more-btn" bindtap="shanglaJiazaiGengduo">
        加载更多
      </view>

      <!-- 加载状态提示 -->
      <view class="load-state" wx:if="{{isLoadingMore}}"><text>加载中…</text></view>
      <view class="load-state" wx:if="{{!hasMore && dashouList.length > 0}}"><text>— 已全部加载 —</text></view>
      <view class="empty" wx:if="{{!isLoading && dashouList.length === 0}}">
        <image src="/images/empty.png" mode="aspectFit" />
        <text>暂无下级接单员</text>
      </view>
    </view>
  </scroll-view>

  <global-notification id="global-notification" />
</view>