<!-- 合同编辑页面 -->
<view class="edit-container">
  <!-- 加载状态 -->
  <view class="loading-state" wx:if="{{loading}}">
    <text class="loading-icon">⏳</text>
    <text class="loading-text">加载中...</text>
  </view>

  <!-- 错误状态 -->
  <view class="error-state" wx:if="{{error}}">
    <text class="error-icon">❌</text>
    <text class="error-text">{{error}}</text>
    <button class="retry-btn" bindtap="retryLoadContract">重试</button>
  </view>

  <!-- 编辑表单 -->
  <view class="edit-form" wx:if="{{!loading && !error && contract}}">
    <view class="form-section">
      <view class="section-title">基本信息</view>
      
      <view class="form-item">
        <text class="form-label">合同编号</text>
        <input class="form-input" value="{{contract.contractNumber}}" disabled />
      </view>
      
      <view class="form-item">
        <text class="form-label">客户姓名</text>
        <input class="form-input" value="{{contract.customerName}}" bindinput="onInputChange" data-field="customerName" placeholder="请输入客户姓名" />
      </view>
      
      <view class="form-item">
        <text class="form-label">客户电话</text>
        <input class="form-input" value="{{contract.phone}}" bindinput="onInputChange" data-field="phone" placeholder="请输入客户电话" />
      </view>
      
      <view class="form-item">
        <text class="form-label">客户身份证</text>
        <input class="form-input" value="{{contract.borrowerIdNumber}}" bindinput="onInputChange" data-field="borrowerIdNumber" placeholder="请输入客户身份证" />
      </view>
    </view>

    <view class="form-section">
      <view class="section-title">贷款信息</view>
      
      <view class="form-item">
        <text class="form-label">贷款金额</text>
        <input class="form-input" type="digit" value="{{contract.amount}}" bindinput="onInputChange" data-field="amount" placeholder="请输入贷款金额" />
      </view>
      
      <view class="form-item">
        <text class="form-label">贷款期限(月)</text>
        <input class="form-input" type="number" value="{{contract.term}}" bindinput="onInputChange" data-field="term" placeholder="请输入贷款期限" />
      </view>
      
      <view class="form-item">
        <text class="form-label">利率(%)</text>
        <input class="form-input" type="digit" value="{{contract.interestRate}}" bindinput="onInputChange" data-field="interestRate" placeholder="请输入利率" />
      </view>
      
      <view class="form-item">
        <text class="form-label">合同状态</text>
        <picker bindchange="onStatusChange" value="{{statusIndex}}" range="{{statusOptions}}" range-key="text">
          <view class="picker-display">
            {{statusOptions[statusIndex].text}}
            <text class="picker-arrow">></text>
          </view>
        </picker>
      </view>
    </view>

    <view class="form-section">
      <view class="section-title">其他信息</view>
      
      <view class="form-item">
        <text class="form-label">合同类型</text>
        <picker bindchange="onTypeChange" value="{{typeIndex}}" range="{{typeOptions}}" range-key="text">
          <view class="picker-display">
            {{typeOptions[typeIndex].text}}
            <text class="picker-arrow">></text>
          </view>
        </picker>
      </view>
      
      <view class="form-item">
        <text class="form-label">贷款用途</text>
        <input class="form-input" value="{{contract.purpose}}" bindinput="onInputChange" data-field="purpose" placeholder="请输入贷款用途" />
      </view>
      
      <view class="form-item">
        <text class="form-label">备注</text>
        <textarea class="form-textarea" value="{{contract.remark}}" bindinput="onInputChange" data-field="remark" placeholder="请输入备注信息" />
      </view>
    </view>
  </view>

  <!-- 操作按钮 -->
  <view class="form-actions" wx:if="{{!loading && !error && contract}}">
    <button class="action-btn cancel-btn" bindtap="cancelEdit">取消</button>
    <button class="action-btn save-btn" bindtap="saveContract" disabled="{{saving}}">
      {{saving ? '保存中...' : '保存'}}
    </button>
  </view>
</view>
