<!-- 固定顶部区域 -->
<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-y="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.OM}}</view>
        <view class="table-cell">{{item.CL}}</view>
        <view class="table-cell">{{item.CEC}}</view>
        <view class="table-cell">{{item.H_plus}}</view>
        <view class="table-cell">{{item.N}}</view>
        <view class="table-cell">{{item.Al3_plus}}</view>
        <view class="table-cell">{{item.Delta_pH}}</view>
      </view>
    </block>
  </view>
</scroll-view>

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

    <view class="modal-item">
    <view class="item-label">有机质含量(g/kg)：</view>
    <input class="input-field" type="number"  placeholder="比值" data-field="OM" bindinput="onInputOM" value="{{newData.OM}}"/>
  </view>
    <view class="modal-item">
    <view class="item-label">土壤粘粒(g/kg)：</view>
    <input class="input-field" type="number"  placeholder="请输入酸碱度" data-field="CL" bindinput="onInputCL" value="{{newData.CL}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">阳离子交换量(cmol/kg)：</view>
    <input class="input-field" type="number"  placeholder="请输入有机质含量" data-field="CEC" bindinput="onInputCEC" value="{{newData.CEC}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">交换性氢(cmol/kg)：</view>
    <input class="input-field" type="number"  placeholder="请输入氯离子含量" data-field="H_plus" bindinput="onInputH_plus" value="{{newData.H_plus}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">水解氮(g/kg)：</view>
    <input class="input-field" type="number"  placeholder="请输入H含量" data-field="N" bindinput="onInputN" value="{{newData.N}}"/>
  </view>

    <view class="modal-item">
    <view class="item-label">交换性铝(cmol/kg)：</view>
    <input class="input-field" type="number"  placeholder="请输入铝离子含量" data-field="Al3_plus" bindinput="onInputAl3_plus" value="{{newData.Al3_plus}}"/>
  </view>

  <view class="modal-item">
    <view class="item-label">ΔpH：</view>
    <input class="input-field" type="number"  placeholder="请输入铝离子含量" data-field="Delta_pH" bindinput="onInputDelta_pH" value="{{newData.Delta_pH}}"/>
  </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>
