<!--pages/cattle/archive/archive.wxml-->
<view class="page-container">
  <!-- 搜索栏 -->
  <view class="search-bar">
    <input 
      class="search-input" 
      placeholder="🔍 请输入耳号"
      value="{{searchValue}}"
      bindinput="onSearchInput"
      bindconfirm="handleSearch"
      type="number"
    />
    <button class="search-btn" bindtap="handleSearch" wx:if="{{searchValue}}">搜索</button>
    <button class="clear-btn" bindtap="clearSearch" wx:if="{{searchValue}}">清空</button>
  </view>

  <!-- 加载状态 -->
  <view class="loading-container" wx:if="{{loading && !refreshing}}">
    <text>加载中...</text>
  </view>

  <!-- 牛只列表 -->
  <view class="cattle-list" wx:else>
    <view class="cattle-card" wx:for="{{list}}" wx:key="id" bindtap="viewDetail" data-id="{{item.id}}">
      <!-- 耳号 -->
      <view class="card-header">
        <text class="ear-number">耳号：{{item.earNumber}}</text>
        <text class="arrow">›</text>
      </view>
      
      <!-- 详细信息 -->
      <view class="card-body">
        <view class="info-row">
          <text class="label">佩戴设备：</text>
          <text class="value">{{item.earNumber}}</text>
        </view>
        <view class="info-row">
          <text class="label">出生日期：</text>
          <text class="value">{{item.birthdayText}}</text>
        </view>
        <view class="info-row">
          <text class="label">品类：</text>
          <text class="value">{{item.cate || '-'}}</text>
        </view>
        <view class="info-row">
          <text class="label">品种：</text>
          <text class="value">{{item.varieties || '-'}}</text>
        </view>
        <view class="info-row">
          <text class="label">生理阶段：</text>
          <text class="value">{{item.physiologicalStageText}}</text>
        </view>
        <view class="info-row">
          <text class="label">性别：</text>
          <text class="value">{{item.sexText}}</text>
        </view>
        <view class="info-row">
          <text class="label">栏舍：</text>
          <text class="value">{{item.penName || '-'}}</text>
        </view>
      </view>
    </view>

    <!-- 空状态 -->
    <view class="empty-container" wx:if="{{!loading && list.length === 0}}">
      <text class="empty-icon">🐄</text>
      <text class="empty-text">暂无牛只档案数据</text>
    </view>
  </view>

  <!-- 分页 -->
  <view class="pagination" wx:if="{{totalPages > 1 && list.length > 0}}">
    <button class="page-btn" bindtap="prevPage" disabled="{{page === 1}}">上一页</button>
    <view class="page-numbers">
      <text class="page-number {{page === item ? 'active' : ''}}" 
            wx:for="{{totalPages}}" 
            wx:key="index"
            wx:for-item="item"
            wx:for-index="index"
            data-page="{{index + 1}}"
            bindtap="changePage">
        {{index + 1}}
      </text>
    </view>
    <button class="page-btn" bindtap="nextPage" disabled="{{page === totalPages}}">下一页</button>
  </view>

  <!-- 数据统计 -->
  <view class="stats-bar" wx:if="{{!loading}}">
    <text class="stats-text">共 {{total}} 头牛，当前第 {{page}}/{{totalPages}} 页</text>
  </view>

  <!-- 新增档案按钮 -->
  <view class="add-btn" bindtap="addCattle">
    <text>新增档案</text>
  </view>
</view>
