<!-- 牛只批次设置页面 -->
<view class="page-container">
  <!-- 顶部搜索区域 -->
  <view class="search-bar">
    <input class="search-input" placeholder="请输入批次名称或编号（精确匹配）" value="{{search}}" bindinput="onSearchInput" confirm-type="search" bindconfirm="onSearchConfirm" />
    <button class="search-btn" bindtap="onSearch">查询</button>
  </view>

  <!-- 统计与分页信息 -->
  <view class="summary-bar">
    <text>总数：{{total}}</text>
    <text>第 {{page}} / {{totalPages}} 页</text>
  </view>

  <!-- 批次列表 -->
  <scroll-view scroll-y class="list-scroll">
    <block wx:if="{{loading}}">
      <view class="loading">加载中...</view>
    </block>

    <block wx:if="{{!loading && records.length === 0}}">
      <view class="empty">暂无数据</view>
    </block>

    <block wx:for="{{records}}" wx:key="id">
      <view class="record-card">
        <!-- 头部主信息 -->
        <view class="record-header">
          <view class="title-line">
            <text class="name">{{item.name || item.batch_name || item.batchName || '-'}}</text>
            <text class="code">编号：{{item.code || item.batch_number || item.batchNumber || '-'}}</text>
          </view>
          <view class="meta-line">
            <text class="status" wx:if="{{item.statusStr}}">状态：{{item.statusStr}}</text>
            <text class="time" wx:if="{{item.createdAtStr}}">创建时间：{{item.createdAtStr}}</text>
          </view>
        </view>

        <!-- 详情字段（显示全部返回字段，中文映射） -->
        <view class="record-body">
          <block wx:for="{{item.displayPairs}}" wx:key="key" wx:for-item="pair">
            <view class="pair-row">
              <text class="pair-key">{{pair.keyZh}}</text>
              <text class="pair-val">{{pair.val}}</text>
            </view>
          </block>
        </view>
      </view>
    </block>
  </scroll-view>

  <!-- 分页 -->
  <view class="pagination">
    <button class="page-btn" bindtap="prevPage" disabled="{{page <= 1}}">上一页</button>
    <scroll-view scroll-x class="page-numbers">
      <view class="page-items">
        <block wx:for="{{pages}}" wx:key="index">
          <view class="page-item {{current ? 'active' : ''}}" data-page="{{num}}" bindtap="goToPage">
            <text>{{num}}</text>
          </view>
        </block>
      </view>
    </scroll-view>
    <button class="page-btn" bindtap="nextPage" disabled="{{page >= totalPages}}">下一页</button>
  </view>
</view>