<view class="sub-page pagebg">
  <image class="page-bg-img" src="https://bintao.xmxym88.com/xcx/static/images/bg.png" mode="widthFix"/>
  <view class="page-body">
    <view class="status-bar" style="height:{{statusBar}}px"></view>
    <view class="nav-bar flexb">
      <text class="back" bindtap="goBack">‹</text>
      <text class="nav-title">邀请码</text>
      <text class="back placeholder"></text>
    </view>

    <scroll-view scroll-y class="list-scroll" show-scrollbar="{{false}}">
      <view wx:if="{{gudingCode}}" class="fixed-code-card flexb">
        <view class="fixed-code-main">
          <text class="fixed-code-lbl">固定邀请码：</text>
          <text class="fixed-code-val">{{gudingCode}}</text>
        </view>
        <view class="copy-btn" bindtap="copyFixed">复制</view>
      </view>

      <view wx:if="{{kefuTips}}" class="tips-bar">{{kefuTips}}</view>

      <view class="toolbar flexb">
        <view class="sub-tabs flexa">
          <view wx:for="{{sublist}}" wx:key="name" class="sub-tab {{subCurrent==index?'on':''}}" data-idx="{{index}}" bindtap="switchSub">{{item.name}}</view>
        </view>
        <view class="add-btn" bindtap="addKey">添加</view>
      </view>

      <view class="help-row flexb" bindtap="goToRoleManage">
        <text class="help-link">角色与权限管理（资金池/划额度在此配置角色）</text>
        <text class="help-arrow">›</text>
      </view>

      <view class="help-row flexb" bindtap="goAudit">
        <text class="help-link">操作日志与客服排行</text>
        <text class="help-arrow">›</text>
      </view>

      <view class="help-row flexb" bindtap="showTips">
        <text class="help-link">秘钥使用方法</text>
        <text class="help-arrow">›</text>
      </view>

      <view wx:for="{{list}}" wx:key="id" class="key-item">
        <view class="key-row flexb">
          <view class="tag-type">{{item.typeName}}</view>
          <view class="key-code" bindtap="copyCode" data-code="{{item.code}}">{{item.code}}</view>
          <view class="status-txt {{item.status==0?'unused':'used'}}">{{item.status==0?'未使用':'已使用'}}</view>
        </view>
        <view class="key-meta">生成日期：{{item.adddate}}</view>
        <view wx:if="{{item.status==1}}" class="key-meta">使用日期：{{item.usedate}}</view>
        <view wx:if="{{item.user.nickname}}" class="key-user flex">
          <image class="user-av" src="{{item.user.avatar}}" mode="aspectFill"/>
          <text>使用人：{{item.user.nickname}}</text>
        </view>
        <view class="key-actions flexb">
          <text class="act-copy" bindtap="copyCode" data-code="{{item.code}}">复制秘钥</text>
          <text class="act-del" bindtap="delKey" data-id="{{item.id}}">删除</text>
        </view>
      </view>

      <view wx:if="{{!list.length}}" class="empty-tip">暂无卡密</view>
    </scroll-view>
  </view>

  <view wx:if="{{showQrcodeTips}}" class="mask" bindtap="closeTips">
    <view class="popup" catchtap="noop">
      <view class="popup-title">秘钥使用方法</view>
      <scroll-view scroll-y class="popup-scroll">
        <view class="popup-txt">把秘钥发给客服，用户扫下方二维码输入秘钥即可绑定。</view>
        <view class="qr-wrap">
          <image class="qr-img" src="https://xy-1314784552.cos.ap-guangzhou.myqcloud.com/uploads/images/ewm.png" mode="widthFix" bindtap="previewQr"/>
        </view>
      </scroll-view>
      <view class="popup-close" bindtap="closeTips">关闭</view>
    </view>
  </view>
</view>
