<!-- mode2 自动打款 - UI 与 mode1 手动提现完全一致，逻辑为自动审核收款 -->
<view class="app">
  <image class="global-bg" src="{{imgUrls.pageBg}}" mode="aspectFill" />

  <!-- 资产区域（与 mode1 相同） -->
  <view class="assets-section">
    <view class="main-card" style="background-image: url('{{imgUrls.cardBg}}'); background-size: cover;">
      <view class="balance-wrap">
        <text class="balance-label">可提总余额</text>
        <text class="balance-value">¥{{totalAmount}}</text>
      </view>
      <view class="inner-divider"></view>
      <text class="assets-hint">← 左右滑动查看更多资产 →</text>
      <scroll-view class="assets-scroll" scroll-x="true" show-scrollbar="{{false}}" enhanced>
        <view class="assets-track">
          <block wx:for="{{assetList}}" wx:key="type">
            <view
              class="asset-tile"
              bindtap="onSelectAsset"
              data-index="{{index}}"
              style="background-image: url('{{imgUrls.assetTileBg}}'); background-size: cover; background-position: center;"
            >
              <text class="asset-name">{{item.label}}</text>
              <text class="asset-balance">¥{{item.amount}}</text>
              <text class="asset-fee">费率 {{item.rate}}%</text>
            </view>
          </block>
          <view wx:if="{{assetList.length === 0 && !isLoadingAssets}}" class="assets-empty">暂无可用资金</view>
        </view>
      </scroll-view>
    </view>
    <view class="divider-line"></view>
  </view>

  <!-- 提现记录区（mode1 布局 + 自动打款筛选/收款） -->
  <view class="history-section">
    <view class="history-header">
      <text class="history-title">提现记录</text>
    </view>

    <view wx:if="{{hasPendingCollect}}" class="pending-tip">
      您有审核通过的提现待收款，请点击「收款」按钮，在微信中主动确认后才能到账。
    </view>

    <scroll-view class="filter-scroll" scroll-x show-scrollbar="{{false}}">
      <view class="filter-track">
        <view
          wx:for="{{statusTabs}}"
          wx:key="value"
          class="filter-chip {{currentStatusFilter == item.value ? 'active' : ''}}"
          bindtap="onStatusFilterTap"
          data-value="{{item.value}}"
        >{{item.label}}</view>
      </view>
    </scroll-view>

    <scroll-view class="history-scroll" scroll-y enable-back-to-top bindscrolltolower="onReachBottom">
      <view wx:for="{{recordList}}" wx:key="index" class="history-item">
        <view class="history-info">
          <text class="history-amount">¥{{item.jine}}</text>
          <text class="history-time">{{item.create}}</text>
        </view>
        <view class="history-detail">
          <text class="history-method">微信零钱</text>
          <text class="history-type">{{item.leixingLabel}}</text>
        </view>
        <view class="history-status">
          <!-- 待收款：整块可点击 → 弹出确认收款弹窗 → 用户确认后才请求后端 -->
          <view
            wx:if="{{item.canCollect}}"
            class="status-badge status-pending collect-tappable"
            bindtap="onCollectTap"
            data-index="{{index}}"
          >
            <text>{{item.statusText}}</text>
            <text class="collect-sub">点击收款</text>
          </view>
          <view wx:elif="{{item.canShowDetail}}" class="status-badge status-fail">
            {{item.statusText}}
            <text class="fail-link" bindtap="onViewDetail" data-index="{{index}}">详情</text>
          </view>
          <view wx:else class="status-badge {{item.statusBadgeClass}}">{{item.statusText}}</view>
        </view>
      </view>
      <view wx:if="{{loading}}" class="load-tip">加载中...</view>
      <view wx:if="{{nomore && recordList.length > 0}}" class="more-tip">—— 没有更多了 ——</view>
      <view wx:if="{{!nomore && recordList.length > 0}}" class="load-more-btn" bindtap="onReachBottom">加载更多记录</view>
      <view wx:if="{{recordList.length === 0 && !loading}}" class="load-tip">暂无提现记录</view>
    </scroll-view>
  </view>

  <view class="safe-bottom"></view>
</view>

<!-- 申请提现弹窗（mode1 样式，无收款方式） -->
<view wx:if="{{showTixian}}" class="modal-mask" bindtap="onCloseTixian">
  <view class="modal-dialog" catchtap="stopPropagation">
    <view class="modal-header">申请提现</view>
    <view class="modal-body">
      <view class="auto-tip">提交后需等待审核，审核通过后请在本页点击「收款」确认到账</view>
      <view class="info-row"><text>项目</text><text>{{selectedAsset.label}}</text></view>
      <view class="info-row"><text>可提</text><text>¥{{selectedAsset.amount}}</text></view>
      <view class="info-row"><text>费率</text><text>{{currentRate}}%</text></view>
      <view class="amount-row">
        <text>金额</text>
        <input type="digit" placeholder="0.00" value="{{tixianjine}}" bindinput="onJineInput" />
      </view>
      <view class="quick-row">
        <view wx:for="{{[100,200,500,1000]}}" wx:key="item" class="quick-chip" data-value="{{item}}" bindtap="onQuickAmountTap">¥{{item}}</view>
      </view>
      <view class="fee-row">
        <text>手续费 ¥{{shouxufei}}</text>
        <text>到账 ¥{{shijidaozhang}}</text>
      </view>
    </view>
    <view class="modal-footer">
      <view class="modal-btn cancel" bindtap="onCloseTixian">取消</view>
      <view class="modal-btn confirm" bindtap="onConfirmTixian">{{submitting ? '处理中' : '提交申请'}}</view>
    </view>
  </view>
</view>

<!-- 收款确认弹窗 -->
<view wx:if="{{showCollectConfirm}}" class="modal-mask" bindtap="onCloseCollectConfirm">
  <view class="modal-dialog" catchtap="stopPropagation">
    <view class="modal-header">确认收款</view>
    <view class="modal-body">
      <view class="auto-tip">审核已通过，{{collectConfirmRecord.leixingLabel}} ¥{{collectConfirmRecord.jine}}</view>
      <view>请点击「去收款」，然后在微信弹窗中主动确认，资金才会打入您的微信零钱。</view>
      <view class="warn-tip" wx:if="{{collectConfirmRecord.shenhe_danhao}}">审核单号：{{collectConfirmRecord.shenhe_danhao}}</view>
      <view class="warn-tip">注意：审核通过≠已到账，必须您本人点击确认才能完成收款！</view>
    </view>
    <view class="modal-footer">
      <view class="modal-btn cancel" bindtap="onCloseCollectConfirm">稍后再说</view>
      <view class="modal-btn confirm" bindtap="onConfirmCollect">{{submitting ? '处理中...' : '去收款'}}</view>
    </view>
  </view>
</view>

<!-- 失败/驳回详情弹窗 -->
<view wx:if="{{showDetailModal}}" class="modal-mask" bindtap="onCloseDetailModal">
  <view class="modal-dialog" catchtap="stopPropagation">
    <view class="modal-header">{{detailTitle}}</view>
    <view class="modal-body">{{detailContent}}</view>
    <view class="modal-footer">
      <view class="modal-btn confirm" bindtap="onCloseDetailModal">知道了</view>
    </view>
  </view>
</view>

<global-notification id="global-notification" />
<popup-notice id="popupNotice" />
