<!-- 商家端个人中心 - 逍遥梦布局，逻辑/接口不变 -->
<block wx:if="{{staffBooting}}">
  <view class="sj-page user-page">
    <view class="sj-page-header">
      <view class="status-bar" style="height:{{statusBar}}px"></view>
      <view class="nav-bar flexm" style="height:{{navBar - statusBar}}px"><text class="sj-nav-title">我的</text></view>
    </view>
    <view class="unreg-area sj-mx20">
      <view class="sj-panel unreg-card">
        <text class="unreg-title">客服身份加载中</text>
        <text class="unreg-desc">请稍候，正在同步您的派单员权限…</text>
      </view>
    </view>
    <tab-bar/>
  </view>
</block>

<block wx:elif="{{!isShangjia && !isStaffMode}}">
  <view class="sj-page user-page">
    <view class="sj-page-header">
      <view class="status-bar" style="height:{{statusBar}}px"></view>
      <view class="nav-bar flexm" style="height:{{navBar - statusBar}}px"><text class="sj-nav-title">我的</text></view>
    </view>
    <view class="unreg-area sj-mx20">
      <view class="sj-panel unreg-card">
        <text class="unreg-title">商家入驻</text>
        <text class="unreg-desc">商家老板请填写商家邀请码；若您是客服/派单员，请走下方入口</text>
        <input class="unreg-input" placeholder="商家邀请码（老板专用）" maxlength="100" value="{{inviteCode}}" bindinput="onInviteCodeInput"/>
        <view class="sj-btn-bg unreg-btn flexm" bindtap="onRegister">商家注册</view>
        <view class="unreg-link staff-link" bindtap="goToStaffJoin">我是客服 / 派单员，绑定客服秘钥</view>
        <view class="unreg-link" bindtap="switchToNormal">返回点单端</view>
        <view class="unreg-link" bindtap="clearCache">清除缓存，重新登录</view>
      </view>
    </view>
    <tab-bar/>
  </view>
</block>

<block wx:else>
  <view class="sj-page user-page">
    <view class="sj-page-header">
      <view class="status-bar" style="height:{{statusBar}}px"></view>
      <view class="nav-bar flexm sj-nav-bar" style="height:{{navBar - statusBar}}px">
        <text class="sj-nav-title">我的</text>
      </view>
    </view>

    <view class="refresh-float" wx:if="{{false}}">
      <image class="refresh-float-ico" src="{{imgUrls.iconRefresh}}" mode="aspectFit"/>
    </view>

    <scroll-view class="content" scroll-y enhanced show-scrollbar="{{false}}">
      <view class="user-info flexb">
        <view class="flex">
          <image class="avatar" src="{{avatarUrl || defaultAvatarUrl}}" mode="aspectFill" bindtap="previewAvatar"/>
          <view>
            <view class="nickname-row flex">
              <text class="nickname">{{nicheng || '商家'}}</text>
              <view class="sj-identity-tag" wx:if="{{isStaffMode}}">{{staffRoleName || '商家客服'}}</view>
              <view class="sj-identity-tag" wx:else>商家</view>
            </view>
            <view wx:if="{{!isStaffMode}}" class="nickname-edit-btn flexm" bindtap="editNicheng">修改昵称</view>
            <view class="identity-tags-row flex" wx:if="{{identityTagList && identityTagList.length > 0}}">
              <view class="badge-tag-wrap" wx:for="{{identityTagList}}" wx:key="id">
                <chenghao-tag mingcheng="{{item.mingcheng}}" texiaoJson="{{item.texiao_json}}"/>
              </view>
            </view>
            <view class="sn-row flex" bindtap="copyUid">
              <text class="sn">ID: {{uid || '--'}}</text>
              <image class="copy-ico" src="{{imgUrls.iconCopy}}" mode="aspectFit"/>
            </view>
          </view>
        </view>
        <view class="user-header-actions">
          <image class="header-action-ico" src="{{imgUrls.iconRefresh}}" mode="aspectFit" bindtap="refreshShangjiaInfo"/>
        </view>
      </view>

      <view class="badge-zone" wx:if="{{chenghaoList && chenghaoList.length > 0}}">
        <scroll-view scroll-x class="badge-scroll">
          <view class="badge-tag-wrap" wx:for="{{chenghaoList}}" wx:key="index">
            <chenghao-tag mingcheng="{{item.mingcheng}}" texiaoJson="{{item.texiao_json}}"/>
          </view>
        </scroll-view>
      </view>

      <view class="sj-wallet-card flexb">
        <view>
          <view class="sj-w-label">{{isStaffMode ? '可用派单额度(元)' : '商家余额(元)'}}</view>
          <view class="sj-w-num">¥{{sjyue}}</view>
          <view class="sj-w-sub" wx:if="{{!isStaffMode}}">发单总量 {{fabu}} · 退款 {{tuikuan}}</view>
          <view class="sj-w-sub" wx:else>角色：{{staffRoleName}}</view>
        </view>
        <view class="wallet-btns flex" wx:if="{{showRechargeWithdraw}}">
          <view class="sj-btn-outline" catchtap="goToRecharge">充值</view>
          <view class="sj-btn-outline" catchtap="goToWithdraw">去提现</view>
        </view>
      </view>

      <view class="freeze-row flexa">
        <view class="freeze-col flexmc">
          <text class="freeze-num">{{jinriliushui}}</text>
          <text class="freeze-lbl">今日流水</text>
        </view>
        <view class="freeze-col flexmc">
          <text class="freeze-num">{{jinyueliushui}}</text>
          <text class="freeze-lbl">今月流水</text>
        </view>
        <view class="freeze-col flexmc">
          <text class="freeze-num">{{jinridingdan}}</text>
          <text class="freeze-lbl">今日派单</text>
        </view>
      </view>

      <view class="sj-panel sj-mx20 order-nav-box">
        <view class="sj-section-hd">我的订单</view>
        <view class="sj-order-nav">
          <view class="sj-order-nav-item" bindtap="goToPendingOrders">
            <text class="sj-order-nav-num">{{pendingCount}}</text>
            <text class="sj-order-nav-lbl">待结算</text>
          </view>
          <view class="sj-order-nav-item" bindtap="goToMyOrders">
            <text class="sj-order-nav-num">{{jinrituikuan}}</text>
            <text class="sj-order-nav-lbl">今日退款</text>
          </view>
          <view class="sj-order-nav-item" bindtap="goToMessages">
            <text class="sj-order-nav-num">{{punishPending}}</text>
            <text class="sj-order-nav-lbl">处罚待处理</text>
          </view>
          <view class="sj-order-nav-item" bindtap="goToMyOrders">
            <text class="sj-order-nav-num">›</text>
            <text class="sj-order-nav-lbl">全部订单</text>
          </view>
        </view>
      </view>

      <view class="sj-panel sj-mx20">
        <view class="sj-section-hd">交易与发单</view>
        <view class="sj-func-grid">
          <view class="sj-func-item" bindtap="goToRegularPaiDan" wx:if="{{canDispatch}}">
            <image class="sj-func-icon" src="{{imgUrls.iconFast}}" mode="aspectFit"/>
            <text class="sj-func-txt">常规派单</text>
          </view>
          <view class="sj-func-item" bindtap="goToPaiDan" wx:if="{{canDispatch}}">
            <image class="sj-func-icon" src="{{imgUrls.iconRelease}}" mode="aspectFit"/>
            <text class="sj-func-txt">自定义派单</text>
          </view>
          <view class="sj-func-item" bindtap="goToLinkPaiDan" wx:if="{{canDispatch}}">
            <image class="sj-func-icon" src="{{imgUrls.iconOrders}}" mode="aspectFit"/>
            <text class="sj-func-txt">链接派单</text>
          </view>
          <view class="sj-func-item" bindtap="goToDataStats" wx:if="{{canViewFinance || !isStaffMode}}">
            <image class="sj-func-icon" src="{{imgUrls.iconRank}}" mode="aspectFit"/>
            <text class="sj-func-txt">经营数据</text>
          </view>
          <view class="sj-func-item" bindtap="goToKefuKey" wx:if="{{canStaffManage}}">
            <image class="sj-func-icon" src="{{imgUrls.iconService}}" mode="aspectFit"/>
            <text class="sj-func-txt">客服邀请码</text>
          </view>
          <view class="sj-func-item" bindtap="goToKefuList" wx:if="{{canStaffManage}}">
            <image class="sj-func-icon" src="{{imgUrls.iconKefuList}}" mode="aspectFit"/>
            <text class="sj-func-txt">客服列表</text>
          </view>
          <view class="sj-func-item" bindtap="goToAuditLog" wx:if="{{canAudit}}">
            <image class="sj-func-icon" src="{{imgUrls.iconOrders}}" mode="aspectFit"/>
            <text class="sj-func-txt">操作日志</text>
          </view>
          <view class="sj-func-item" bindtap="goToStaffRank" wx:if="{{canAudit}}">
            <image class="sj-func-icon" src="{{imgUrls.iconRank}}" mode="aspectFit"/>
            <text class="sj-func-txt">客服排行</text>
          </view>
          <view class="sj-func-item" bindtap="goToMessages" wx:if="{{!isStaffMode}}">
            <image class="sj-func-icon" src="{{imgUrls.iconPunish}}" mode="aspectFit"/>
            <text class="sj-func-txt">处罚记录</text>
          </view>
          <view class="sj-func-item" bindtap="goToRanking" wx:if="{{!isStaffMode}}">
            <image class="sj-func-icon" src="{{imgUrls.iconRank}}" mode="aspectFit"/>
            <text class="sj-func-txt">商家排行</text>
          </view>
          <view class="sj-func-item" bindtap="goToKefu">
            <image class="sj-func-icon" src="{{imgUrls.iconService}}" mode="aspectFit"/>
            <text class="sj-func-txt">在线客服</text>
          </view>
          <view class="sj-func-item" bindtap="goToHome">
            <image class="sj-func-icon" src="{{imgUrls.iconOrders}}" mode="aspectFit"/>
            <text class="sj-func-txt">商家首页</text>
          </view>
        </view>
      </view>

      <view class="sj-panel sj-mx20 sys-panel">
        <view class="sys-item flexb" bindtap="switchToNormal">
          <text class="sys-text">返回点单端</text>
          <text class="sys-arrow">›</text>
        </view>
        <view class="sys-item flexb" bindtap="clearCache">
          <text class="sys-text">清除缓存</text>
          <text class="sys-sub">重新登录</text>
        </view>
      </view>

      <view class="sj-scroll-bottom"></view>
    </scroll-view>
    <tab-bar/>
  </view>
</block>

<view class="loading-mask" wx:if="{{isLoading}}">
  <view class="loading-spinner"></view>
</view>

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