<!-- pages/qiangdan/qiangdan.wxml -->
<view class="qiangdan-page">
  <!-- 商品类型选择 -->
  <view class="leixing-quyu">
    <scroll-view class="leixing-scroll" scroll-x enhanced show-scrollbar="{{false}}">
      <view class="leixing-container">
        <block wx:for="{{shangpinleixing}}" wx:key="id">
          <view
            class="leixing-item {{xuanzhongLeixingId == item.id ? 'leixing-active' : ''}}"
            data-id="{{item.id}}"
            bindtap="selectLeixing"
          >
            <view wx:if="{{xuanzhongLeixingId == item.id}}" class="guangyun-effect"></view>
            <image class="leixing-tupian" src="{{item.full_tupian_url}}" mode="aspectFill"/>
            <text class="leixing-jieshao">{{item.jieshao}}</text>
          </view>
        </block>
      </view>
    </scroll-view>
  </view>

  <!-- 🆕 标签筛选区 -->
  <view class="biaoqian-quyu" wx:if="{{bankuaiBiaoqian.length > 0}}">
    <scroll-view class="biaoqian-scroll" scroll-x enhanced show-scrollbar="{{false}}">
      <view class="biaoqian-container">
        <view class="biaoqian-item {{xuanzhongBiaoqianId == 0 ? 'biaoqian-active' : ''}}" data-id="0" bindtap="selectBiaoqian">
          <text class="quanbu-text">全部</text>
        </view>
        <block wx:for="{{bankuaiBiaoqian}}" wx:key="id">
          <view class="biaoqian-item {{xuanzhongBiaoqianId == item.id ? 'biaoqian-active' : ''}}" data-id="{{item.id}}" bindtap="selectBiaoqian">
            <chenghao-tag mingcheng="{{item.mingcheng}}" texiaoJson="{{item.texiao_json}}" />
          </view>
        </block>
      </view>
    </scroll-view>
  </view>

  <view class="fenge-xian"></view>

  <!-- 订单列表 -->
  <view class="dingdan-container">
    <scroll-view
      class="dingdan-scroll-view"
      scroll-y enhanced show-scrollbar="{{false}}"
      refresher-enabled="{{xuanzhongLeixingId != null}}"
      refresher-threshold="80"
      refresher-default-style="black"
      refresher-background="#0b0f1a"
      refresher-triggered="{{scrollViewRefreshing}}"
      bindrefresherrefresh="onPullDownRefresh"
      bindscrolltolower="onReachBottom"
    >
      <view class="refresher-container" slot="refresher">
        <text wx:if="{{scrollViewRefreshing}}" class="refreshing-text">⚡️ 正在刷新...</text>
        <text wx:else class="pull-down-text">▼ 下拉刷新订单</text>
      </view>

      <view class="dingdan-list">
        <view wx:if="{{!xuanzhongLeixingId}}" class="empty-tip">
          <image src="/images/icon_select.png" class="tip-icon"></image>
          <text class="tip-text">请先选择上方订单类型</text>
        </view>
        <view wx:elif="{{dingdanList.length === 0 && !isLoading}}" class="empty-tip">
          <image src="/images/icon_empty_order.png" class="tip-icon"></image>
          <text class="tip-text">当前类型暂无待抢订单</text>
        </view>

        <block wx:for="{{dingdanList}}" wx:key="dingdan_id">
          <!-- 平台订单卡片 -->
          <view wx:if="{{item.isPingtai}}" class="dingdan-card pingtai-card" data-item="{{item}}">
            <view class="card-top">
              <text class="creat-time">{{item.creat_time}}</text>
              <view class="top-line"></view>
              <text class="pingtai-tag">⚙️ 平台订单</text>
            </view>

            <!-- 指定接单员行（新增标签滚动） -->
            <view wx:if="{{item.isZhiding}}" class="zhiding-row">
              <text class="zhiding-icon">指定</text>
              <image wx:if="{{item.zhiding_avatar_full}}" class="zhiding-avatar" src="{{item.zhiding_avatar_full}}" mode="aspectFill"/>
              <text class="zhiding-nicheng">{{item.zhiding_nicheng || '指定接单员'}}</text>
              <text class="zhiding-uid">UID: {{item.zhiding_uid || '未知'}}</text>
              <!-- 🆕 接单员标签 -->
              <scroll-view wx:if="{{item.dashou_biaoqian.length > 0}}" class="biaoqian-inline-scroll" scroll-x>
                <chenghao-tag wx:for="{{item.dashou_biaoqian}}" wx:for-item="tag" wx:key="id" mingcheng="{{tag.mingcheng}}" texiaoJson="{{tag.texiao_json}}" />
              </scroll-view>
            </view>

            <view class="card-content">
              <image class="neirong-tupian" src="{{item.full_tupian_url}}" mode="aspectFill"/>
              <view class="jieshao-box {{item.jieshao && item.jieshao.length > 60 ? 'jieshao-ellipsis' : ''}}" data-type="jieshao" data-content="{{item.jieshao}}" bindtap="onViewDetail">
                <text class="jieshao-label">介绍：</text>
                <text class="jieshao-text">{{item.jieshao || '暂无介绍'}}</text>
                <text wx:if="{{item.jieshao && item.jieshao.length > 60}}" class="view-more">[点击查看]</text>
              </view>
            </view>

            <view wx:if="{{item.beizhu}}" class="beizhu-box {{item.beizhu.length > 40 ? 'beizhu-ellipsis' : ''}}" data-type="beizhu" data-content="{{item.beizhu}}" bindtap="onViewDetail">
              <text class="beizhu-label">备注：</text>
              <text class="beizhu-text">{{item.beizhu}}</text>
              <text wx:if="{{item.beizhu.length > 40}}" class="view-more">[点击查看]</text>
            </view>

            <!-- 🆕 订单需求标签 -->
            <view wx:if="{{item.xuqiu_biaoqian.length > 0}}" class="xuqiu-biaoqian-area">
              <text class="xuqiu-label">需求标签：</text>
              <scroll-view class="xuqiu-biaoqian-scroll" scroll-x>
                <chenghao-tag wx:for="{{item.xuqiu_biaoqian}}" wx:for-item="tag" wx:key="id" mingcheng="{{tag.mingcheng}}" texiaoJson="{{tag.texiao_json}}" />
              </scroll-view>
            </view>

            <view class="card-bottom">
              <view class="fenyong-box">
                <text class="fenyong-icon">💰</text>
                <text class="fenyong-text">分佣</text>
                <!-- 🆕 根据是否有权限显示价格或提示 -->
                <block wx:if="{{item.hasRequiredMember}}">
                  <text class="fenyong-price">{{item.dashou_fencheng || 0}}</text>
                  <text class="fenyong-unit">元</text>
                </block>
                <block wx:else>
                  <text class="fenyong-price" style="font-size: 28rpx; color: #ffaa88;">未开通会员</text>
                </block>
              </view>
              <view class="qiangdan-btn mecha-btn pingtai-btn" data-item="{{item}}" bindtap="onQiangdanTap">
                <text class="btn-text">⚡ 立即抢单</text>
                <view class="btn-shine"></view>
                <view class="btn-glow"></view>
                <view class="mecha-overlay"></view>
              </view>
            </view>
          </view>

          <!-- 商家订单卡片 -->
          <view wx:elif="{{item.isShangjia}}" class="dingdan-card shangjia-card" data-item="{{item}}">
            <view class="card-top">
              <text class="creat-time">{{item.creat_time}}</text>
              <view class="top-line"></view>
              <text class="pingtai-tag">🏪 商家发单</text>
            </view>

            <!-- 指定接单员行 -->
            <view wx:if="{{item.isZhiding}}" class="zhiding-row">
              <text class="zhiding-icon">指定</text>
              <image wx:if="{{item.zhiding_avatar_full}}" class="zhiding-avatar" src="{{item.zhiding_avatar_full}}" mode="aspectFill"/>
              <text class="zhiding-nicheng">{{item.zhiding_nicheng || '指定接单员'}}</text>
              <text class="zhiding-uid">UID: {{item.zhiding_uid || '未知'}}</text>
              <!-- 🆕 接单员标签 -->
              <scroll-view wx:if="{{item.dashou_biaoqian.length > 0}}" class="biaoqian-inline-scroll" scroll-x>
                <chenghao-tag wx:for="{{item.dashou_biaoqian}}" wx:for-item="tag" wx:key="id" mingcheng="{{tag.mingcheng}}" texiaoJson="{{tag.texiao_json}}" />
              </scroll-view>
            </view>

            <view class="shangjia-info">
              <image class="shangjia-touxiang" src="{{item.full_tupian_url}}" mode="aspectFill"/>
              <text class="shangjia-nicheng">{{item.sjnicheng || '未知商家'}}</text>
              <!-- 🆕 商家标签 -->
              <scroll-view wx:if="{{item.shangjia_biaoqian.length > 0}}" class="biaoqian-inline-scroll" scroll-x>
                <chenghao-tag wx:for="{{item.shangjia_biaoqian}}" wx:for-item="tag" wx:key="id" mingcheng="{{tag.mingcheng}}" texiaoJson="{{tag.texiao_json}}" />
              </scroll-view>
            </view>

            <view class="shangjia-jieshao {{item.jieshao && item.jieshao.length > 50 ? 'jieshao-ellipsis' : ''}}" data-type="jieshao" data-content="{{item.jieshao}}" bindtap="onViewDetail">
              <text class="jieshao-label">订单介绍：</text>
              <text class="jieshao-text">{{item.jieshao || '暂无介绍'}}</text>
              <text wx:if="{{item.jieshao && item.jieshao.length > 50}}" class="view-more">[点击查看]</text>
            </view>

            <view wx:if="{{item.beizhu}}" class="shangjia-beizhu {{item.beizhu.length > 30 ? 'beizhu-ellipsis' : ''}}" data-type="beizhu" data-content="{{item.beizhu}}" bindtap="onViewDetail">
              <text class="beizhu-label">商家备注：</text>
              <text class="beizhu-text">{{item.beizhu}}</text>
              <text wx:if="{{item.beizhu.length > 30}}" class="view-more">[点击查看]</text>
            </view>

            <!-- 🆕 订单需求标签 -->
            <view wx:if="{{item.xuqiu_biaoqian.length > 0}}" class="xuqiu-biaoqian-area">
              <text class="xuqiu-label">需求标签：</text>
              <scroll-view class="xuqiu-biaoqian-scroll" scroll-x>
                <chenghao-tag wx:for="{{item.xuqiu_biaoqian}}" wx:for-item="tag" wx:key="id" mingcheng="{{tag.mingcheng}}" texiaoJson="{{tag.texiao_json}}" />
              </scroll-view>
            </view>

            <view class="card-bottom">
              <view class="fenyong-box">
                <text class="fenyong-icon">💰</text>
                <text class="fenyong-text">分佣</text>
                <!-- 🆕 根据是否有权限显示价格或提示 -->
                <block wx:if="{{item.hasRequiredMember}}">
                  <text class="fenyong-price">{{item.dashou_fencheng || 0}}</text>
                  <text class="fenyong-unit">元</text>
                </block>
                <block wx:else>
                  <text class="fenyong-price" style="font-size: 28rpx; color: #ffaa88;">未开通会员</text>
                </block>
              </view>
              <view class="qiangdan-btn mecha-btn shangjia-btn" data-item="{{item}}" bindtap="onQiangdanTap">
                <text class="btn-text">⚡ 立即抢单</text>
                <view class="btn-shine"></view>
                <view class="btn-glow"></view>
                <view class="mecha-overlay"></view>
              </view>
            </view>
          </view>
        </block>

        <view wx:if="{{isLoadingMore && dingdanList.length > 0}}" class="loading-more"><text class="loading-text">⚙️ 加载更多订单中...</text></view>
        <view wx:if="{{!hasMore && dingdanList.length > 0}}" class="no-more"><text class="no-more-text">—— 没有更多订单了 ——</text></view>
      </view>
    </scroll-view>

    <view wx:if="{{isLoading && dingdanList.length === 0 && xuanzhongLeixingId}}" class="loading-mask">
      <view class="loading-spinner"></view>
      <text class="loading-mask-text">⚡ 订单加载中...</text>
    </view>
  </view>

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