<!-- 固定顶部区域 -->
<view class="top-container">
  <view class="add-btn-container">
  <button class="add-btn" bindtap="onImport">导入</button>
  <button class="add-btn" bindtap="onExport">导出</button>
  <button class="add-btn" bindtap="onDownloadTemplate">下载模板</button>
  <button class="add-btn" bindtap="onAdd">新增</button>
  </view>
</view>

<!-- 滚动区域 -->
<scroll-view class="table-container" scroll-x="true" scroll-with-animation="true">
  <!-- 数据加载中 -->
  <view wx:if="{{loading}}" class="loading">数据加载中，请稍候...</view>

  <!-- 无数据提示 -->
  <view wx:if="{{!loading && filteredRows.length === 0}}" class="no-data">暂无数据</view>

  <!-- 表格 -->
  <view class="table-body">
    <view class="table-header">
      <view class="table-cell" wx:for="{{tableHeaders}}" wx:key="index">{{item}}</view>
    </view>
    <view class="table-header">
      <view class="table-cell" wx:for="{{unit}}" wx:key="index">{{item}}</view>
    </view>

    <block wx:for="{{filteredRows}}" wx:key="index">
      <view class="table-row" bindtap="onRowClick" data-index="{{index}}" data-row="{{item}}">
        <view class='table-cell' wx:for="{{list}}" wx:key="item">
          <view class='item'>{{item}}</view>
        </view>
        <view class="table-cell">{{index + 1}}</view> <!-- 序号 -->
        <view class="table-cell">{{item.Q_over_b}}</view>
        <view class="table-cell">{{item.pH}}</view>
        <view class="table-cell">{{item.OM}}</view>
        <view class="table-cell">{{item.CL}}</view>
        <view class="table-cell">{{item.H}}</view>
        <view class="table-cell">{{item.Al}}</view>
      </view>
    </block>
  </view>
</scroll-view>

<!-- 新增数据弹窗 -->
<view class="modal" wx:if="{{showAddModal}}">
  <view class="modal-content">

    <view class="modal-item">
    <view class="item-label">土壤提升单位pH的生石灰施用量%：</view>
    <input class="input-field" placeholder="比值" data-field="Q_over_b" bindinput="onInputQ_over_b" value="{{newData.Q_over_b}}"/>
  </view>
    <view class="modal-item">
    <view class="item-label">土壤初始含量：</view>
    <input class="input-field" placeholder="请输入酸碱度" data-field="pH" bindinput="onInputpH" value="{{newData.pH}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">土壤有机含量：</view>
    <input class="input-field" placeholder="请输入有机质含量" data-field="OM" bindinput="onInputOM" value="{{newData.OM}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">土壤粘粒含量：</view>
    <input class="input-field" placeholder="请输入氯离子含量" data-field="CL" bindinput="onInputCL" value="{{newData.CL}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">交换性氢含量：</view>
    <input class="input-field" placeholder="请输入H含量" data-field="H" bindinput="onInputH" value="{{newData.H}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">交换性铝含量：</view>
    <input class="input-field" placeholder="请输入铝离子含量" data-field="Al" bindinput="onInputAl" value="{{newData.Al}}"/>
  </view>

    <view class="button-container">
      <button class="submit-btn" bindtap="onSubmit">确认</button>
      <button class="cancel-btn" bindtap="onCancel">取消</button>
    </view>
  </view>
</view>

<!-- 底部编辑删除弹窗 -->
<view class="modal" wx:if="{{showModal}}">
  <view class="modal-content">
    <view class="modal-item" bindtap="onEdit">编辑</view>
    <view class="modal-item delete" bindtap="onDelete">删除</view>
    <view class="modal-item cancel" bindtap="onCancel">取消</view>
  </view>
</view>
