<!--pages/workbench/workbench.wxml-->
<!-- 默认头像使用网络地址以减小包体积 -->
<wxs module="utils">
  var DEFAULT_AVATAR = 'https://ai-c.maimanji.com/images/default-avatar.png';
  module.exports = {
    DEFAULT_AVATAR: DEFAULT_AVATAR,
    getAvatar: function(avatar) {
      return avatar || DEFAULT_AVATAR;
    }
  };
</wxs>
<view class="container">
  <!-- 顶部状态栏 -->
  <view class="status-bar">
    <view class="status-info">
      <image class="avatar" src="{{utils.getAvatar(userInfo.avatar)}}" mode="aspectFill"></image>
      <view class="status-text">
        <text class="name">{{userInfo.nickname || '陪聊师'}}</text>
        <view class="status-tag {{currentStatus}}">
          <text>{{statusText}}</text>
        </view>
      </view>
    </view>
    <view class="status-switch" bindtap="showStatusPicker">
      <text>切换状态</text>
      <image class="arrow" src="/images/arrow-right.png"></image>
    </view>
  </view>

  <!-- 等级信息卡片 -->
  <view class="level-card">
    <view class="level-header">
      <view class="level-badge level-{{levelCode}}">
        <text class="level-text">{{levelName}}</text>
      </view>
      <text class="level-title">当前等级</text>
    </view>
    <view class="level-prices">
      <view class="price-item">
        <text class="price-label">文字服务</text>
        <text class="price-value">¥{{textPrice}}/分钟</text>
      </view>
      <view class="price-divider"></view>
      <view class="price-item">
        <text class="price-label">语音服务</text>
        <text class="price-value">¥{{voicePrice}}/分钟</text>
      </view>
    </view>
  </view>

  <!-- 数据统计卡片 -->
  <view class="stats-card">
    <view class="stats-row">
      <view class="stat-item">
        <text class="stat-value">{{stats.todayOrders || 0}}</text>
        <text class="stat-label">今日订单</text>
      </view>
      <view class="stat-item">
        <text class="stat-value">¥{{stats.todayIncome || '0.00'}}</text>
        <text class="stat-label">今日收入</text>
      </view>
    </view>
    <view class="stats-row">
      <view class="stat-item">
        <text class="stat-value">{{stats.totalOrders || 0}}</text>
        <text class="stat-label">总订单数</text>
      </view>
      <view class="stat-item">
        <text class="stat-value">¥{{stats.totalIncome || '0.00'}}</text>
        <text class="stat-label">总收入</text>
      </view>
    </view>
  </view>

  <!-- 快捷操作 -->
  <view class="quick-actions">
    <view class="action-item" bindtap="goToOrders">
      <image src="/images/icon-orders.png"></image>
      <text>我的订单</text>
    </view>
    <view class="action-item" bindtap="goToCustomers">
      <image src="/images/icon-customers.png"></image>
      <text>客户管理</text>
    </view>
    <view class="action-item" bindtap="goToWithdraw">
      <image src="/images/icon-withdraw.png"></image>
      <text>提现</text>
    </view>
    <view class="action-item" bindtap="goToCommission">
      <image src="/images/icon-commission.png"></image>
      <text>佣金明细</text>
    </view>
  </view>

  <!-- 接单大厅 -->
  <view class="order-hall">
    <view class="section-header">
      <text class="section-title">接单大厅</text>
      <text class="section-more" bindtap="refreshHall">刷新</text>
    </view>

    <view class="hall-list" wx:if="{{hallOrders.length > 0}}">
      <view class="hall-item" wx:for="{{hallOrders}}" wx:key="id">
        <view class="hall-user">
          <image class="user-avatar" src="{{utils.getAvatar(item.user.avatar)}}" mode="aspectFill"></image>
          <view class="user-info">
            <text class="user-name">{{item.user.nickname || '用户'}}</text>
            <text class="order-time">{{item.createTimeText}}</text>
          </view>
        </view>
        <view class="hall-content">
          <text class="service-type">{{item.serviceTypeText}}</text>
          <text class="service-duration">{{item.duration}}分钟</text>
          <text class="service-price">¥{{item.amount}}</text>
        </view>
        <view class="hall-message" wx:if="{{item.message}}">
          <text>{{item.message}}</text>
        </view>
        <view class="hall-actions">
          <button class="btn-reject" bindtap="rejectOrder" data-id="{{item.id}}">拒绝</button>
          <button class="btn-accept" bindtap="acceptOrder" data-id="{{item.id}}">接单</button>
        </view>
      </view>
    </view>

    <view class="empty-hall" wx:else>
      <image src="/images/empty-orders.png"></image>
      <text>暂无待接订单</text>
    </view>
  </view>

  <!-- 进行中的订单 -->
  <view class="active-orders" wx:if="{{activeOrders.length > 0}}">
    <view class="section-header">
      <text class="section-title">进行中的订单</text>
    </view>

    <view class="active-list">
      <view class="active-item" wx:for="{{activeOrders}}" wx:key="id" bindtap="goToChat" data-order="{{item}}">
        <view class="active-user">
          <image class="user-avatar" src="{{utils.getAvatar(item.user.avatar)}}" mode="aspectFill"></image>
          <view class="user-info">
            <text class="user-name">{{item.user.nickname || '用户'}}</text>
            <text class="remaining-time">剩余 {{item.remainingTime}}</text>
          </view>
        </view>
        <view class="active-actions">
          <button class="btn-end" catchtap="endService" data-id="{{item.id}}">结束服务</button>
        </view>
      </view>
    </view>
  </view>
</view>

<!-- 状态选择弹窗 -->
<view class="status-picker-mask" wx:if="{{showStatusModal}}" bindtap="hideStatusPicker"></view>
<view class="status-picker" wx:if="{{showStatusModal}}">
  <view class="picker-header">
    <text>选择状态</text>
  </view>
  <view class="picker-options">
    <view class="picker-option {{currentStatus === 'online' ? 'active' : ''}}" bindtap="changeStatus" data-status="online">
      <view class="status-dot online"></view>
      <text>在线接单</text>
    </view>
    <view class="picker-option {{currentStatus === 'busy' ? 'active' : ''}}" bindtap="changeStatus" data-status="busy">
      <view class="status-dot busy"></view>
      <text>忙碌中</text>
    </view>
    <view class="picker-option {{currentStatus === 'offline' ? 'active' : ''}}" bindtap="changeStatus" data-status="offline">
      <view class="status-dot offline"></view>
      <text>离线</text>
    </view>
  </view>
</view>
