<view class="container">
  <scroll-view scroll-y class="scroll" bindscrolltolower="loadMore">
    <view wx:if="{{ loading && list.length === 0 }}" class="tip">加载中...</view>
    <block wx:for="{{ list }}" wx:key="id">
      <view class="card" bindtap="openDetail" data-item="{{ item }}">
        <view class="card-head">
          <text class="time">{{ item.create_time }}</text>
          <text class="tag {{ item.status_class }}">{{ item.display_status }}</text>
        </view>
        <text class="info">金额：¥{{ item.fakuanjine }}</text>
        <text class="info">理由：{{ item.chufaliyou }}</text>
        <text class="info staff" wx:if="{{ item.staff_label }}">{{ item.staff_label }}</text>
        <text class="info link" wx:if="{{ item.guanliandingdan_id }}">订单：{{ item.guanliandingdan_id }}</text>
      </view>
    </block>
    <view wx:if="{{ list.length > 0 && !loadingMore && hasMore }}" class="load-more-btn" bindtap="loadMore">点击获取更多</view>
    <view wx:if="{{ loadingMore }}" class="tip">加载中...</view>
    <view wx:if="{{ !hasMore && list.length > 0 }}" class="tip">—— 没有更多了 ——</view>
    <view wx:if="{{ !loading && list.length === 0 }}" class="empty">暂无罚单记录</view>
  </scroll-view>

  <view wx:if="{{ showDetail }}" class="modal-mask">
    <view class="modal-panel">
      <view class="modal-head">
        <text class="modal-title">罚单详情</text>
        <view class="modal-close" bindtap="closeDetail">✕</view>
      </view>
      <scroll-view scroll-y class="modal-body">
        <view class="row"><text class="lbl">罚款金额</text><text class="val strong">¥{{ detailItem.fakuanjine }}</text></view>
        <view class="row"><text class="lbl">状态</text><text class="tag {{ detailItem.status_class }}">{{ detailItem.display_status }}</text></view>
        <view class="row"><text class="lbl">分红到账</text><text class="val">¥{{ detailItem.applicant_bonus_amount || '0.00' }}</text></view>
        <view class="row" wx:if="{{ detailItem.staff_label }}"><text class="lbl">申请客服</text><text class="val">{{ detailItem.staff_label }}</text></view>
        <view class="row"><text class="lbl">处罚理由</text><text class="val">{{ detailItem.chufaliyou }}</text></view>
        <view class="row" wx:if="{{ detailItem.guanliandingdan_id }}">
          <text class="lbl">关联订单</text>
          <text class="val link" bindtap="goOrder" data-id="{{ detailItem.guanliandingdan_id }}">{{ detailItem.guanliandingdan_id }} ›</text>
        </view>
        <view class="row" wx:if="{{ detailItem.bohuiliyou }}"><text class="lbl">驳回理由</text><text class="val">{{ detailItem.bohuiliyou }}</text></view>
        <view class="row" wx:if="{{ detailItem.shensuliyou }}"><text class="lbl">申诉理由</text><text class="val">{{ detailItem.shensuliyou }}</text></view>

        <view class="section">
          <text class="sec-title">处罚证据图（可管理）</text>
          <view class="img-grid">
            <block wx:for="{{ detailItem.zhengju_list }}" wx:key="id">
              <view class="img-box">
                <image class="img" src="{{ item.fullUrl }}" mode="aspectFill" bindtap="previewImage" data-url="{{ item.fullUrl }}"/>
                <view wx:if="{{ detailItem.zhuangtai === 1 || detailItem.zhuangtai === 3 }}" class="img-del" catchtap="deleteEvidence" data-id="{{ item.id }}">✕</view>
              </view>
            </block>
            <view wx:if="{{ (detailItem.zhuangtai === 1 || detailItem.zhuangtai === 3) && detailItem.zhengju_list.length < 9 }}" class="img-add" bindtap="chooseEvidence">+</view>
          </view>
          <view wx:if="{{ uploading }}" class="progress-text">上传中 {{ uploadProgressWidth }}</view>
        </view>

        <view wx:if="{{ detailItem.shensu_list.length }}" class="section">
          <text class="sec-title">打手申诉图片</text>
          <view class="img-grid">
            <block wx:for="{{ detailItem.shensu_list }}" wx:key="id">
              <view class="img-box" bindtap="previewImage" data-url="{{ item.fullUrl }}">
                <image class="img" src="{{ item.fullUrl }}" mode="aspectFill"/>
              </view>
            </block>
          </view>
        </view>
      </scroll-view>
      <view class="modal-foot">
        <view wx:if="{{ detailItem.zhuangtai === 1 || detailItem.zhuangtai === 3 }}" class="pbtn primary" bindtap="openModify">修改</view>
        <view wx:if="{{ detailItem.zhuangtai === 1 || detailItem.zhuangtai === 3 }}" class="pbtn warn" bindtap="openCancel">撤销</view>
        <view wx:if="{{ detailItem.zhuangtai === 4 }}" class="pbtn primary" bindtap="openResubmit">再次申请</view>
        <view class="pbtn default" bindtap="closeDetail">关闭</view>
      </view>
    </view>
  </view>

  <view wx:if="{{ showModify }}" class="modal-mask sub-modal">
    <view class="modal-panel small">
      <view class="modal-head"><text class="modal-title">修改罚单</text><view class="modal-close" bindtap="closeModify">✕</view></view>
      <view class="modal-body">
        <textarea class="textarea" placeholder="罚款原因" value="{{ modifyLiyou }}" bindinput="onModifyLiyou"/>
        <input class="input-num" type="digit" placeholder="金额" value="{{ modifyJine }}" bindinput="onModifyJine"/>
      </view>
      <view class="modal-foot">
        <view class="pbtn primary" bindtap="submitModify">确认</view>
        <view class="pbtn default" bindtap="closeModify">取消</view>
      </view>
    </view>
  </view>

  <view wx:if="{{ showCancel }}" class="modal-mask sub-modal">
    <view class="modal-panel small">
      <view class="modal-head"><text class="modal-title">撤销罚单</text><view class="modal-close" bindtap="closeCancel">✕</view></view>
      <view class="modal-body">
        <textarea class="textarea" placeholder="驳回理由" value="{{ cancelLiyou }}" bindinput="onCancelLiyou"/>
      </view>
      <view class="modal-foot">
        <view class="pbtn warn" bindtap="submitCancel">确认撤销</view>
        <view class="pbtn default" bindtap="closeCancel">取消</view>
      </view>
    </view>
  </view>

  <view wx:if="{{ showResubmit }}" class="modal-mask sub-modal">
    <view class="modal-panel small">
      <view class="modal-head"><text class="modal-title">再次申请</text><view class="modal-close" bindtap="closeResubmit">✕</view></view>
      <view class="modal-body">
        <textarea class="textarea" placeholder="罚款原因" value="{{ resubmitLiyou }}" bindinput="onResubmitLiyou"/>
        <input class="input-num" type="digit" placeholder="金额" value="{{ resubmitJine }}" bindinput="onResubmitJine"/>
      </view>
      <view class="modal-foot">
        <view class="pbtn primary" bindtap="submitResubmit">提交</view>
        <view class="pbtn default" bindtap="closeResubmit">取消</view>
      </view>
    </view>
  </view>
</view>
