<!--module/diet/pages/delivery-address/delivery-address.wxml-->
<t-navbar title="{{i18n.orderText.mineOrder}}" left-arrow bindtap="goMine" />
<t-tabs value="{{currentTab}}" bindchange="onTabChange">
  <t-tab-panel label="全部" value="all" />
  <t-tab-panel label="{{i18n.orderText.paying}}" value="pending" />
  <t-tab-panel label="{{i18n.orderText.paid}}" value="paid" />
  <t-tab-panel label="{{i18n.orderText.paySuccess}}" value="completed" />
    <!-- <t-tab-panel label="交易关闭" value=closed" /> -->
</t-tabs>

<scroll-view class="page-scroll__container" scroll-y>
  <block wx:for="{{orders}}" wx:key="id">
    <view class="order-card" bindtap="onOrderDetail" data-id="{{item.id}}" data-status="{{item.orderStatus}}">
      <view class="order-header">
        <view>
          <text wx:if="{{item.orderNo}}">订单编号：{{item.orderNo}}</text>
        </view>
        <text class="order-status {{statusClassObj[item.orderStatus]}}">{{statusObj[item.orderStatus]}}</text>
      </view>
      <view class="order-user" data-status="{{item.orderStatus}}" catchtap="changeAddress"
       data-id="{{item.id}}" wx:if="{{item.isDelivery==='Y'}}">
       <view wx:if="{{item.showAddress}}">
        <view class="contact">
        <view class="name" wx:if="item.liaison">{{item.liaison}}</view> 
         <view wx:if="{{item.phone}}">{{item.phone}}</view>
          </view>
        <view wx:if="{{item.address}}">{{item.address || ''}}</view>
        </view>
        <view wx:else class="delivery-address">
          请选择配送地址
        </view>
      </view>
      <view class="order-body">
        <image src="{{item.photo}}" class="order-img" wx:if="{{item.photo}}" />
        <image src="../../assets/servicePag.png" class="order-img" wx:else />
        <view class="order-info">
          <text class="order-title">{{item.conditioningWrapName || ''}}</text>
          <text class="order-doctor" wx:if="{{item.operateBy}}">开具医生：<text style="color:black">{{item.operateBy}}</text></text>
          <text class="order-time" wx:if="{{item.operateTime}}">开具时间：<text style="color:black">{{item.operateTime}}</text></text>
        </view>
      </view>

      <view class="line"></view>
      <!-- 服务包列表 -->
      <view class="service-packages">
        <view 
          class="service-package-item" 
          wx:for="{{item.items}}" 
          wx:key="id"
          wx:for-item="package"
          wx:for-index="packageIndex"
          wx:if="{{packageIndex < 2 || expandedItems[item.id]}}"
        >
          <image 
            src="{{package.photo}}" 
            class="service-package-img" 
            wx:if="{{package.photo}}" 
            mode="aspectFill"
          />
          <view class="service-package-placeholder" wx:else>
            <text class="placeholder-icon">📦</text>
          </view>
          <view class="service-package-info">
            <view class="service-package-header">
              <text class="service-package-name">{{package.name}}</text>
              <text class="service-package-price" wx:if="{{package.price > 0}}">¥{{package.price}}</text>
            </view>
            <view class="servicepag-des">
            <text class="service-package-detail" wx:if="{{package.description}}">{{package.description}}</text>
            <text class="service-package-quantity" wx:if="{{package.quantity > 0}}">x{{package.quantity}}</text>
            </view>
          </view>
        </view>
        <!-- 展开/收起按钮 -->
        <view 
          class="expand-toggle" 
          wx:if="{{item.items && item.items.length > 2}}"
          catchtap="toggleServicePackages"
          data-id="{{item.id}}"
        >
          <text class="expand-text">{{expandedItems[item.id] ? '收起' : '展开'}}</text>
          <text class="expand-icon {{expandedItems[item.id] ? 'expanded' : ''}}">▼</text>
        </view>
      </view>
      <view class="order-footer">
        <view class="order-price">订单金额：<text class="order-amount">￥{{item.cost}}</text></view>

        <view class="order-actions">
          <!-- 按状态显示不同按钮 -->
          <t-button wx:if="{{item.orderStatus==='0'}}" size="small" type="default" class="outline-btn cancel" bindtap="onCancel" data-id="{{item.id}}" disabled="{{throttleTimers.cancel}}">
            取消订单
          </t-button>
          <t-button wx:if="{{item.orderStatus==='0'}}" size="small" type="primary" bindtap="onPay" class="outline-btn" data-id="{{item.id}}" disabled="{{(payingId===item.id) || throttleTimers.pay}}">
            立即支付
          </t-button>
          <!-- <t-button wx:if="{{item.orderStatus==='6' || item.orderStatus==='345'}}" size="small" type="default" class="outline-btn cancel" bindtap="onSeeLogistics" data-id="{{item.id}}" disabled="{{throttleTimers.logistics}}">
            查看物流
          </t-button> -->
          <!-- <t-button wx:if="{{item.orderStatus==='6'}}" size="small" type="default" class="outline-btn" bindtap="onConfirmReceiving" data-id="{{item.id}}" disabled="{{throttleTimers.confirmReceiving}}">
            确认收货
          </t-button> -->

        </view>
      </view>
    </view>
  </block>
  <block wx:if="{{orders.length === 0}}">
    <t-empty icon="info-circle-filled" description="暂无数据" />
  </block>
  <t-dialog visible="{{showConfirm}}" content="确定要取消订单吗？" confirm-btn="{{ { content: '取消订单', variant: 'base', theme: 'primary' } }}" cancel-btn="再想想" bind:confirm="confirmCancelDialog" bind:cancel="closeDialog" />
</scroll-view>

<view style="height: {{container.safeBottomOffset}}px;flex: none;"></view>