<!--pages/farmer/farmer.wxml-->
<view class="farmer-container">
  <!-- 标题栏 -->
  <view class="header">
    <view class="header-left">
      <view class="back-btn" bindtap="onBack">
        <text class="back-icon">←</text>
      </view>
      <text class="title">{{mode === 'add' ? '新增养殖户' : mode === 'edit' ? '编辑养殖户' : '养殖户详情'}}</text>
    </view>
    <view class="header-right" wx:if="{{mode === 'view'}}">
      <view class="action-btn" bindtap="onEdit">
        <text class="edit-icon">✏️</text>
      </view>
    </view>
  </view>

  <!-- 养殖户详情卡片 -->
  <view class="farmer-detail-card" wx:if="{{mode === 'view'}}">
    <view class="card-header">
      <view class="farmer-avatar">
        <text class="avatar-text">{{farmerInfo.name.charAt(0)}}</text>
      </view>
      <view class="farmer-basic">
        <view class="farmer-name">{{farmerInfo.name}}</view>
        <view class="status-tag {{farmerInfo.status}}">
          <text>{{farmerInfo.status === 'active' ? '正常' : farmerInfo.status === 'pending' ? '待审核' : '停用'}}</text>
        </view>
      </view>
    </view>

    <view class="card-content">
      <view class="info-section">
        <view class="section-title">基本信息</view>
        <view class="info-grid">
          <view class="info-item">
            <text class="info-label">农场名称</text>
            <text class="info-value">{{farmerInfo.farmName}}</text>
          </view>
          <view class="info-item">
            <text class="info-label">联系电话</text>
            <text class="info-value">{{farmerInfo.phone}}</text>
          </view>
          <view class="info-item">
            <text class="info-label">农场地址</text>
            <text class="info-value">{{farmerInfo.address}}</text>
          </view>
          <view class="info-item">
            <text class="info-label">注册时间</text>
            <text class="info-value">{{farmerInfo.registerTime}}</text>
          </view>
        </view>
      </view>

      <view class="info-section">
        <view class="section-title">养殖信息</view>
        <view class="info-grid">
          <view class="info-item">
            <text class="info-label">牲畜数量</text>
            <text class="info-value highlight">{{farmerInfo.animalCount}}头</text>
          </view>
          <view class="info-item">
            <text class="info-label">养殖类型</text>
            <text class="info-value">{{farmerInfo.animalType || '牛羊混养'}}</text>
          </view>
          <view class="info-item">
            <text class="info-label">农场面积</text>
            <text class="info-value">{{farmerInfo.farmArea || '500亩'}}</text>
          </view>
          <view class="info-item">
            <text class="info-label">最近检查</text>
            <text class="info-value">{{farmerInfo.lastCheckTime || '2024-01-15'}}</text>
          </view>
        </view>
      </view>
    </view>
  </view>

  <!-- 表单编辑模式 -->
  <view class="farmer-form" wx:if="{{mode === 'add' || mode === 'edit'}}">
    <view class="form-section">
      <view class="section-title">基本信息</view>
      <view class="form-group">
        <text class="form-label">养殖户姓名 <text class="required">*</text></text>
        <input 
          class="form-input" 
          placeholder="请输入养殖户姓名"
          value="{{formData.name}}"
          bindinput="onInputChange"
          data-field="name"
        />
      </view>
      <view class="form-group">
        <text class="form-label">农场名称 <text class="required">*</text></text>
        <input 
          class="form-input" 
          placeholder="请输入农场名称"
          value="{{formData.farmName}}"
          bindinput="onInputChange"
          data-field="farmName"
        />
      </view>
      <view class="form-group">
        <text class="form-label">联系电话 <text class="required">*</text></text>
        <input 
          class="form-input" 
          placeholder="请输入联系电话"
          type="number"
          value="{{formData.phone}}"
          bindinput="onInputChange"
          data-field="phone"
        />
      </view>
      <view class="form-group">
        <text class="form-label">农场地址 <text class="required">*</text></text>
        <textarea 
          class="form-textarea" 
          placeholder="请输入农场详细地址"
          value="{{formData.address}}"
          bindinput="onInputChange"
          data-field="address"
        />
      </view>
    </view>

    <view class="form-section">
      <view class="section-title">养殖信息</view>
      <view class="form-group">
        <text class="form-label">牲畜数量 <text class="required">*</text></text>
        <input 
          class="form-input" 
          placeholder="请输入牲畜数量"
          type="number"
          value="{{formData.animalCount}}"
          bindinput="onInputChange"
          data-field="animalCount"
        />
      </view>
      <view class="form-group">
        <text class="form-label">养殖类型</text>
        <picker 
          class="form-picker"
          bindchange="onPickerChange"
          data-field="animalType"
          value="{{animalTypeIndex}}"
          range="{{animalTypes}}"
        >
          <view class="picker-content">
            <text class="picker-text">{{formData.animalType || '请选择养殖类型'}}</text>
            <text class="picker-arrow">></text>
          </view>
        </picker>
      </view>
      <view class="form-group">
        <text class="form-label">农场面积</text>
        <input 
          class="form-input" 
          placeholder="请输入农场面积（亩）"
          type="digit"
          value="{{formData.farmArea}}"
          bindinput="onInputChange"
          data-field="farmArea"
        />
      </view>
    </view>
  </view>

  <!-- 操作按钮 -->
  <view class="action-buttons">
    <view class="btn-group" wx:if="{{mode === 'view'}}">
      <view class="btn btn-secondary" bindtap="onEdit">编辑信息</view>
      <view class="btn btn-danger" bindtap="onDelete">删除养殖户</view>
    </view>
    <view class="btn-group" wx:if="{{mode === 'add' || mode === 'edit'}}">
      <view class="btn btn-secondary" bindtap="onCancel">取消</view>
      <view class="btn btn-primary" bindtap="onSave">{{mode === 'add' ? '保存' : '更新'}}</view>
    </view>
  </view>
</view>