<!--pages/home/home.wxml-->
<view class="fullscreen-bg">

  <t-navbar title="{{i18n.common.zy}}{{i18n.common.title}}" t-class-title="nav-title" />

  <scroll-view 
    class="page-scroll__container" 
    type="list" 
    scroll-y 
    style="height: {{pageHeight}};"
    refresher-enabled="{{true}}"
    refresher-triggered="{{refreshing}}"
    bindrefresherrefresh="onRefreshScienceList"
    bindscrolltolower="onLoadMoreScienceList"
    lower-threshold="100">
    <view class="follow-container">
      <view class="follow-box" bind:tap="showFollowPopup">
        <image src="../../assets/bg/icon_notice@3x.png" mode="heightFix" class="notice-icon" />
        <view class="pieces">{{popupList.length}}</view>
        <view class="follow-text" wx:if="{{NoteTitle}}">{{NoteTitle}}</view>
      </view>
      <view class="tool-bar-wrapper">
        <view class="tool" wx:if="{{location.description}}">
          <text>{{location.description}}</text>
        </view>
        <view class="tool" wx:if="{{solarTerms.description}}">
          <text>{{solarTerms.description}}</text>
        </view>
      </view>
    </view>

    <view class="body-img">
      <!-- 咨询中的状态-->
      <view class="chat-status" wx:if="{{isConsulting}}" bind:tap="goToConsultation">
        <view class="chat-status__dot" wx:if="{{hasNewMessage}}"></view>
        <text class="chat-status__text">{{i18n.home.consult}}中...</text>
      </view>
      <!-- 使用 image 标签确保图片清晰度 -->
      <image class="body-bg-image" src="../../assets/bg/pic_body@2x.png" mode="aspectFit" />
      <view class="header-container">
        <view class="user-info-wrapper" wx:if="{{patient}}">
          <view class="user-box">
            <text class="user-name">{{patient.name}}</text>
            <t-icon color="{{patientIconColor}}" name="{{patientIcon}}" size="20px"></t-icon>
          </view>
          <view class="user-pageBox">
            <text class="user-age" wx:if="{{patient.age}}">{{patient.age}}岁</text>
            <text class="user-description" overflow="fade" max-lines="1">{{patientDescription}}</text>
          </view>
        </view>
      </view>

      <view wx:if="{{healthReport.loading}}" class="loading-center">
        <t-loading theme="circular" size="48px" color="#2d92fd" />
      </view>
      <view class="healthyAnalyze" bindtap="goHealthAnalyze" wx:elif="{{isShowComplete}}">
        请完成{{i18n.home.analysis}}
      </view>
      <view class="steps-container" wx:elif="{{i18n.home.__showRecord__}}">
        <vertical-steps statusList="{{statusList}}" dataset="{{healthReport.data}}" bind:position="onBodyModel" />
        <view class="warn-box" wx:if="{{healthIndex.data.length>0}}">
          <image src="../../assets/bg/icon_warning@3x.png" class="warn-img" />
          <view class="right-box" bind:tap="tabValue">
            <view style="margin-bottom:10rpx" wx:for="{{healthIndex.data}}" wx:key="{{item.quotaId}}">{{item}}</view>
          </view>
        </view>
      </view>

      <view class="report-container" bindtap="toReportPage" wx:if="{{healthReport.data.reportTime}}">
        <view class="report-box">
          <view>
            <image src="../../assets/bg/icon_file@3x.png" class="report-img" />
          </view>
          <view class="text-box" wx:if="{{healthReport.data.reportTime}}">
            <view class="text-one">{{i18n.report.title}}</view>
            <view class="text-two">日期：{{healthReport.data.reportTime}}</view>
          </view>
        </view>
      </view>
    </view>

    <view class="care-container" wx:if="{{displayList.length>0 && i18n.home.__showDisplay__}}">
      <view class="care-box">
        <view class="care-header">
          <image src="../../assets/icon/icon_plan@3x.png" class="care-icon" />
          <text>调养计划</text>
        </view>
        <view class="care-list">
          <block wx:for="{{displayList}}" wx:key="id">
            <view class="care-item">
              <view class="item-main" bindtap="toggleItem" data-index="{{index}}">
                <text class="dot"></text>
                <text class="item-title">{{item.conditioningProgramName}}</text>
                <text class="item-next-time" wx:if="{{item.arrangeDate && item.sellType==='2'}}">下一次时间：{{item.arrangeDate}}{{item.applyTime?'（已预约）':''}}</text>
                <t-icon name="{{item.expanded ? 'chevron-up' : 'chevron-down'}}" size="24rpx" class="item-arrow" color="#C0C4CC" />
              </view>
              <!-- 这里放详细内容 -->
              <view class="item-detail" wx:if="{{item.expanded}}">

                <view style="width: 60%;">
                  <!-- 轮播媒体容器 -->
                  <view class="carousel-container" wx:if="{{item.carouselMediaList && item.carouselMediaList.length > 0}}">
                    <!-- 轮播组件 -->
                    <media-carousel mediaList="{{item.carouselMediaList}}" showIndicator="{{true}}" autoplay="{{true}}" interval="{{4000}}" circular="{{true}}" bind:fullscreenchange="onCarouselFullscreenChange" itemId="{{item.id}}" />
                  </view>
                  <view class="item-box">
                    <view class="flex" wx:if="{{item.arrangeDate && item.sellType==='2'}}"><text>下一次时间：</text><text>{{item.arrangeDate}}</text></view>
                    <view class="flex">
                      <text wx:if="{{item.sellType==='2'}}">已完成：<text style="color:#2ec4b6">{{item.finishCount}}次</text><text style="margin:0 5px">/</text>
                        <text>{{item.totalMeasure}}次</text></text>

                    </view>
                    <view>频次：每{{item.frequencyType}}天{{item.frequencyMeasure}}{{item.convertUnit?item.convertUnit:'次'}}</view>
                    <view>开具医生：{{item.operateBy}}</view>
                    <view wx:if="{{item.sellType==='2'}}" class="ins-box"><text>机构：</text><text class="copyable-text" catchlongpress="onCopyInstitutionName" data-name="{{item.conditioningProgramSupplierName}}">
                    {{item.conditioningProgramSupplierName?item.conditioningProgramSupplierName:'-'}}</text></view>
                  </view>
                </view>
                <view data-id="{{item.id}}" wx:if="{{item.sellType!=='2'}}" class="verify-record" bindtap="isGoPunchcard" data-signinTime="{{item.signinTime}}">{{
                      item.signinTime?'已打卡':'打卡'
                    }}</view>
                    <view class="right-btn">
                <view catchtap="onRecord" data-id="{{item.id}}" wx:if="{{item.sellType==='2'}}" class="verify-record">预约/核销记录</view>
                <view catchtap="{{item.applyTime?'':'onAppointment'}}" data-id="{{item.id}}" wx:if="{{item.sellType==='2'}}" class="{{item.applyTime?'':'verify-record'}}">{{item.applyTime?'':'预约'}}</view>
                </view>
              </view>
            </view>
          </block>
        </view>
        <view class="expand-all" wx:if="{{careList.length > 4}}" bindtap="toggleAll">
          <t-icon name="{{allExpanded ? 'chevron-up' : 'chevron-down'}}" size="32rpx" class="expand-arrow" color="#C0C4CC" />
        </view>
      </view>
    </view>

    <view class="science-list-wrapper" wx:if="{{scienceList.length}}">
      <view class="list-title" bind:tap="toSciencePage">
        <view class="missionary">{{i18n.healthTeach.title}}</view>
        <view class="title-box serch">
          <text>查询</text>
          <t-icon name="chevron-right-double"></t-icon>
        </view>
      </view>
      <view class="waterfall-container">
        <view class="waterfall-column">
          <waterfall-card wx:for="{{leftColumnList}}" wx:key="id" item="{{item}}" index="{{index}}"></waterfall-card>
        </view>
        <view class="waterfall-column">
          <waterfall-card wx:for="{{rightColumnList}}" wx:key="id" item="{{item}}" index="{{index}}"></waterfall-card>
        </view>
      </view>
      <view class="loading-more" wx:if="{{scienceListLoading}}">
        <t-loading theme="circular" size="32px" color="#2d92fd" />
        <text class="loading-text">加载中...</text>
      </view>
      <view class="loading-more" wx:elif="{{scienceListHasMore === false}}">
        <text class="loading-text">没有更多了</text>
      </view>
      <!--<science-card wx:for="{{scienceList}}" wx:key="id" item="{{item}}" index="{{index}}"></science-card>-->
    </view>
    <science-card style="display: none;">
      <!--?-->
    </science-card>
    <view style="height: {{container.safeBottomOffset}}px;flex: none;"></view>
  </scroll-view>

</view>

<!-- 将 tabbar 移到最外层 -->
<view class="tabbar-container" wx:if="{{false}}">
  <tabbar wx:if="{{!tabbarHidden}}" tabbarValue="{{tabbarValue}}" patientId="{{patient.patientId}}"></tabbar>
</view>






<view wx:if="{{sheet}}" class="draggable-sheet-shade" catch:tap="hideDraggableSheet"></view>
<draggable-sheet class="draggable-sheet-wrapper" style="height: {{container.height}}px;" initial-child-size="0" min-child-size="0" max-child-size="1" snap="{{true}}" snap-sizes="{{[0.5]}}" worklet:onsizeupdate="onDraggableSizeUpdate">
  <scroll-view class="scrollable draggable-sheet-container" type="custom" scroll-y associative-container="draggable-sheet" show-scrollbar="{{false}}" bounces="{{false}}">
    <sticky-section>
      <sticky-header>
        <view class="draggable-sheet-bar">
          <view class="indicator" />
        </view>
        <view wx:if="{{position.CT}}" style="text-align: center;">预警信息</view>
      </sticky-header>
      <block wx:if="{{position.LT}}">
        <view class="card-wrapper" wx:for="{{position.LT}}" wx:key="*this">
          <t-cell wx:if="{{item.title}}" t-class="card-header cell-border-gradient" title="{{item.title}}" />
          <view wx:if="{{item.description}}" class="card-body">&emsp;&emsp;{{item.description}}</view>
        </view>
      </block>
      <block wx:if="{{position.RB}}">
        <view class="card-wrapper">
          <t-cell t-class="card-header cell-border-gradient" title="中医证素解释" />
          <view class="card-body">
            <view class="row" wx:for="{{position.RB.factorItems}}" wx:key="*this">
              <view class="primary">{{item.factorItemName}}</view>
              <view style="margin-top: 4px;" wx:if="{{item.factorItemDescription}}">&emsp;&emsp;{{item.factorItemDescription}}</view>
            </view>
          </view>
        </view>
        <view class="card-wrapper">
          <t-cell t-class="card-header cell-border-gradient" title="中医证型解释" />
          <view class="card-body">
            <view class="row" wx:for="{{position.RB.diagnoseSyndromes}}" wx:key="*this">
              <view class="primary">{{item.diagnoseSyndromeName}}</view>
              <view style="margin-top: 4px;" wx:if="{{item.diagnoseSyndromeAnalysis}}">&emsp;&emsp;{{item.diagnoseSyndromeAnalysis}}</view>
            </view>
          </view>
        </view>
      </block>
      <block wx:if="{{position.RT}}">
        <view class="card-wrapper">
          <t-cell t-class="card-header cell-border-gradient" title="{{position.RT.constitutionGroupName}}" />
          <view class="card-body">
            <span class="row">{{position.RT.constitutionGroupDefinition}}</span>
          </view>
        </view>
        <view class="card-wrapper">
          <t-cell t-class="card-header cell-border-gradient" title="舌象解释" />
          <view class="card-body">
            <view>&emsp;&emsp;{{position.RT.tongueAnalysisResult}}</view>
            <view class="picture-wrapper">
              <image src="{{position.RT.upImg}}" mode="aspectFit" />
              <image src="{{position.RT.downImg}}" mode="aspectFit" />
            </view>
          </view>
        </view>
        <view class="card-wrapper">
          <t-cell t-class="card-header cell-border-gradient" title="面象解释" />
          <view class="card-body">
            <view>&emsp;&emsp;{{position.RT.faceAnalysisResult}}</view>
            <view wx:if="{{position.RT.faceImg}}" class="picture-wrapper">
              <image src="{{position.RT.faceImg}}" mode="aspectFit" />
            </view>
          </view>
        </view>
      </block>
      <block wx:if="{{position.CT}}">
        <view class="CT row" wx:for="{{position.CT}}" wx:key="*this">{{item}}</view>
      </block>
      <view class="bottom-wrapper">
        <form-button index="2" bind:tap="hideDraggableSheet" disableOnClick="{{false}}"></form-button>
      </view>
    </sticky-section>
  </scroll-view>

  <tabbar tabbarValue="{{tabbarValue}}" patientId="{{patient.patientId}}" wx:if="{{!tabbarHidden}}"></tabbar>

  <t-popup visible="{{isShowPopup}}" placement="center">
    <view class="popup-container">
      <view class="popup-block">
        <scroll-view class="scroll_live" scroll-y="{{true}}" show-scrollbar="{{false}}" enhanced="{{true}}" animation="{{animationData}}">
          <view class="popup-item" wx:for="{{popupList}}" wx:key="{{id}}" 
          catch:tap="goComplete" 
          data-page="{{item.page}}" 
          data-id="{{item.pendingWorkId}}" data-title="{{item.title}}">
            <view class="popup-text">{{index+1}}.{{item.title}}</view>
            <view class="popup-action">{{item.button}}</view>
          </view>
        </scroll-view>
      </view>
      <t-icon t-class="close-btn" name="close-circle" size="64rpx" color="#fff" bind:tap="onClose" />
    </view>
  </t-popup>
</draggable-sheet>