<!--养殖场列表页面-->
<view class="page-container">
  <!-- 搜索栏 -->
  <view class="search-bar">
    <view class="search-input-wrapper">
      <input 
        class="search-input"
        placeholder="搜索养殖场名称或编号"
        value="{{searchKeyword}}"
        bindinput="onSearchInput"
        bindconfirm="onSearchConfirm"
      />
      <view class="search-icon" bindtap="onSearchConfirm">
        <image src="/images/icons/search.png" mode="aspectFit"></image>
      </view>
      <view class="clear-icon" wx:if="{{searchKeyword}}" bindtap="onSearchClear">
        <image src="/images/icons/close.png" mode="aspectFit"></image>
      </view>
    </view>
    <view class="filter-btn" bindtap="onStatusFilter">
      <image src="/images/icons/filter.png" mode="aspectFit"></image>
    </view>
  </view>

  <!-- 养殖场列表 -->
  <scroll-view 
    class="farm-list-scroll"
    scroll-y
    refresher-enabled
    refresher-triggered="{{refreshing}}"
    bindrefresherrefresh="onPullDownRefresh"
    bindscrolltolower="onReachBottom"
  >
    <view class="farm-list">
      <view 
        class="farm-item"
        wx:for="{{farmList}}"
        wx:key="id"
        data-farm="{{item}}"
        bindtap="onFarmTap"
      >
        <!-- 养殖场基本信息 -->
        <view class="farm-header">
          <view class="farm-info">
            <text class="farm-name">{{item.name}}</text>
            <text class="farm-code">编号：{{item.code}}</text>
          </view>
          <view class="farm-status">
            <text class="status {{formatStatus(item.status).class}}">
              {{formatStatus(item.status).text}}
            </text>
          </view>
        </view>

        <!-- 养殖场详细信息 -->
        <view class="farm-details">
          <view class="detail-row">
            <view class="detail-item">
              <text class="detail-label">类型</text>
              <text class="detail-value">{{item.type_name}}</text>
            </view>
            <view class="detail-item">
              <text class="detail-label">面积</text>
              <text class="detail-value">{{formatArea(item.area)}}</text>
            </view>
          </view>
          <view class="detail-row">
            <view class="detail-item">
              <text class="detail-label">容量</text>
              <text class="detail-value">{{formatNumber(item.capacity)}}头</text>
            </view>
            <view class="detail-item">
              <text class="detail-label">存栏</text>
              <text class="detail-value">{{formatNumber(item.animal_count)}}头</text>
            </view>
          </view>
        </view>

        <!-- 健康率和地址 -->
        <view class="farm-stats">
          <view class="health-rate">
            <text class="health-label">健康率</text>
            <text class="health-value {{item.health_rate >= 95 ? 'text-success' : item.health_rate >= 90 ? 'text-warning' : 'text-danger'}}">
              {{item.health_rate}}%
            </text>
          </view>
          <text class="farm-address">{{item.address}}</text>
        </view>

        <!-- 操作按钮 -->
        <view class="farm-actions">
          <button 
            class="action-btn secondary"
            data-farm="{{item}}"
            bindtap="onViewStatistics"
          >
            统计
          </button>
          <button 
            class="action-btn secondary"
            data-farm="{{item}}"
            bindtap="onEditFarm"
          >
            编辑
          </button>
          <button 
            class="action-btn danger"
            data-farm="{{item}}"
            bindtap="onDeleteFarm"
          >
            删除
          </button>
        </view>
      </view>
    </view>

    <!-- 加载更多 -->
    <view class="load-more" wx:if="{{hasMore && farmList.length > 0}}">
      <view class="loading-spinner" wx:if="{{loading}}"></view>
      <text class="load-text">{{loading ? '加载中...' : '上拉加载更多'}}</text>
    </view>

    <!-- 没有更多数据 -->
    <view class="no-more" wx:if="{{!hasMore && farmList.length > 0}}">
      <text>没有更多数据了</text>
    </view>
  </scroll-view>

  <!-- 空状态 -->
  <view class="empty" wx:if="{{!loading && farmList.length === 0}}">
    <image class="empty-icon" src="/images/empty-farm.png" mode="aspectFit"></image>
    <text class="empty-text">还没有养殖场</text>
    <text class="empty-desc">添加您的第一个养殖场开始管理</text>
    <button class="btn btn-primary mt-3" bindtap="onAddFarm">添加养殖场</button>
  </view>

  <!-- 加载状态 -->
  <view class="loading" wx:if="{{loading && farmList.length === 0}}">
    <view class="loading-spinner"></view>
    <text>加载中...</text>
  </view>

  <!-- 添加按钮 -->
  <view class="add-btn" bindtap="onAddFarm">
    <image src="/images/icons/add.png" mode="aspectFit"></image>
  </view>
</view>