<!--客户详情-->
<template>
  <view class="assemble">
    <view class="main_box">
      <view style="height: 20rpx;background: #29D3B4;"></view>

      <view class="count_section">
        <view class="main">
          <view class="course_box">
            <view class="course_box_top">
              <view class="course_box_top_top">
                <image class="pic" :src="$util.img('/uniapp_src/static/images/index/myk.png')"></image>
                <view class="name">{{ safeGet(clientInfo, 'customerResource.name', '未知客户') }}</view>
              </view>
              <view class="course_box_top_below">
                <view class="course_box_top_below-left">
                </view>
                <view class="course_box_top_below-right">
                  <!-- 操作按钮 -->
                  <view class="action-buttons">
                    <view class="btn-item" @click="handleMakeCall">
                      <image class="btn-icon"
                             :src="$util.img('/uniapp_src/static/images/index/phone.png')"></image>
                    </view>
                    <view class="btn-item" @click="handleSendMessage"
                          v-if="safeGet(clientInfo, 'customerResource.member_id')">
                      <image class="btn-icon"
                             :src="$util.img('/uniapp_src/static/images/index/message.png')"></image>
                    </view>
                  </view>
                </view>
              </view>
            </view>
            <view class="course_box_centre"></view>
            <view class="course_box_below">
              <view :class="{'selected-text': switch_tags_type === 1, 'text': switch_tags_type !== 1}"
                    @click="switch_tags(1)">基本资料
              </view>
              <view :class="{'selected-text': switch_tags_type === 2, 'text': switch_tags_type !== 2}"
                    @click="switch_tags(2)">课程信息
              </view>
              <view :class="{'selected-text': switch_tags_type === 3, 'text': switch_tags_type !== 3}"
                    @click="switch_tags(3)">通话记录
              </view>
              <view :class="{'selected-text': switch_tags_type === 4, 'text': switch_tags_type !== 4}"
                    @click="switch_tags(4)">体测记录
              </view>
              <view :class="{'selected-text': switch_tags_type === 5, 'text': switch_tags_type !== 5}"
                    @click="switch_tags(5)">学习计划
              </view>
            </view>
          </view>
        </view>
      </view>
      <view class="bg_box bg_top"></view>
      <view class="bg_box bg_bottom"></view>
    </view>

    <!--      基本资料-->
    <view class="basic-information" v-if="switch_tags_type == 1">
      <!-- 整合的客户和学生信息区域 -->
      <view class="integrated-info-section">
        <view class="basic-message">
          <view>客户和学生信息</view>
          <view class="add-student-btn" @click="openAddStudentDialog">
            <view class="add-icon">+</view>
            <view class="add-text">添加学生</view>
          </view>
        </view>
        
        <view class="integrated-cards-container">
          <!-- 整合的客户和学生信息卡片 -->
          <swiper 
            v-if="studentList.length > 0"
            class="student-swiper" 
            :indicator-dots="studentList.length > 1"
            :autoplay="false"
            :circular="studentList.length > 1"
            indicator-color="rgba(255, 255, 255, 0.5)"
            indicator-active-color="#29d3b4"
            style="height: 650rpx;"
            @change="onStudentSwiperChange">
            <swiper-item v-for="(student, index) in studentList" :key="student.id" class="student-swiper-item">
              <view class="integrated-student-card">
                <!-- 客户基本信息区域 -->
                <view class="basic-info-section">
                  <view class="section-header">
                    <view class="customer-avatar">
                      <text>{{ safeGet(clientInfo, 'customerResource.name', '客').charAt(0) }}</text>
                    </view>
                    <view class="customer-info">
                      <view class="customer-name">{{ safeGet(clientInfo, 'customerResource.name', '未知客户') }}</view>
                      <view class="customer-meta">
                        <text class="customer-phone">{{ safeGet(clientInfo, 'customerResource.phone_number', '') }}</text>
                      </view>
                    </view>
                    <view class="contact-actions">
                      <view class="contact-btn phone-btn" @click="makeCall">
                        <text class="contact-icon">📞</text>
                      </view>
                      <view class="contact-btn message-btn" @click="sendMessage">
                        <text class="contact-icon">💬</text>
                      </view>
                    </view>
                  </view>
                  
                  <view class="basic-info-grid">
                    <view class="basic-info-item">
                      <text class="info-label">来源渠道</text>
                      <text class="info-value">{{ safeGet(clientInfo, 'customerResource.source_channel_name', '未知渠道') }}</text>
                    </view>
                    <view class="basic-info-item">
                      <text class="info-label">来源</text>
                      <text class="info-value">{{ safeGet(clientInfo, 'customerResource.source_name', '未知来源') }}</text>
                    </view>
                    <view class="basic-info-item">
                      <text class="info-label">顾问</text>
                      <text class="info-value">{{ safeGet(clientInfo, 'customerResource.consultant_name', '未知顾问') }}</text>
                    </view>
                    <view class="basic-info-item">
                      <text class="info-label">性别</text>
                      <text class="info-value">{{ safeGet(clientInfo, 'customerResource.gender_name', '未知性别') }}</text>
                    </view>
                  </view>
                </view>
                
                <view class="divider-line"></view>
                
                <!-- 学生信息区域 -->
                <view class="student-info-section">
                  <view class="student-header">
                    <view class="student-avatar">
                      <text>{{ student.name ? student.name.charAt(0) : '学' }}</text>
                    </view>
                    <view class="student-basic-info">
                      <view class="student-name">{{ student.name || '未知学生' }}</view>
                      <view class="student-meta">
                        <text class="student-age">{{ formatAge(student.age) }}</text>
                        <text class="student-gender">{{ formatGender(student.gender) }}</text>
                      </view>
                    </view>
                    <view class="student-edit-btn" @click="openEditStudentDialog(student)">
                      <text class="edit-text">编辑</text>
                    </view>
                  </view>
                  
                  <view class="student-details-grid">
                    <view class="detail-item">
                      <text class="detail-label">出生日期：</text>
                      <text class="detail-value">{{ student.birthday || '未设置' }}</text>
                    </view>
                    <view class="detail-item">
                      <text class="detail-label">联系电话：</text>
                      <text class="detail-value">{{ student.contact_phone || '未设置' }}</text>
                    </view>
                    <view class="detail-item">
                      <text class="detail-label">紧急联系人：</text>
                      <text class="detail-value">{{ student.emergency_contact || '未设置' }}</text>
                    </view>
                    <view class="detail-item">
                      <text class="detail-label">体验课次数：</text>
                      <text class="detail-value">{{ student.trial_class_count || 0 }}次</text>
                    </view>
                  </view>
                </view>
                
                <view class="actions-divider"></view>
                
                <!-- 学生操作区域 -->
                <view class="student-actions-panel">
                  <view class="actions-toggle" @click="toggleStudentActions(student)">
                    <text class="toggle-icon" :class="{ 'expanded': student.actionsExpanded }">▲</text>
                  </view>
                  
                  <!-- 学生相关操作按钮 -->
                  <view class="actions-content" v-if="student.actionsExpanded">
                    <view class="actions-grid">
                      <view 
                        v-for="action in sortedStudentActions" 
                        :key="action.key"
                        class="action-item"
                        @click="handleStudentAction(action.key, student)">
                        <view class="action-icon">{{ action.icon }}</view>
                        <text class="action-text">{{ action.text }}</text>
                      </view>
                    </view>
                  </view>
                </view>
              </view>
            </swiper-item>
          </swiper>
          
          <!-- 空状态 -->
          <view v-if="studentList.length === 0" class="empty-students">
            <image src="/static/images/empty.png" mode="aspectFit" class="empty-img"></image>
            <text class="empty-text">暂无学生信息</text>
            <view class="empty-add-btn" @click="openAddStudentDialog">
              <text>添加第一个学生</text>
            </view>
          </view>
        </view>
      </view>
      <view style="height: 200rpx;"></view>
    </view>

    <!--      课程信息-->
    <view class="course-info" v-if="switch_tags_type == 2">
      <view v-if="courseInfo && courseInfo.length > 0">
        <view v-for="(course, index) in courseInfo" :key="index" class="course-item"
              @click="viewCourseDetail(course)">
          <view class="course-header">
            <view class="course-title">{{ course.course_name || '未知课程' }}</view>
            <view class="course-status" :class="'status-' + (course.status || 'default')">
              {{ course.status === 'active' ? '进行中' : course.status === 'expired' ? '已过期' : course.status === 'completed' ? '已完成' : '未知状态'
              }}
            </view>
          </view>

          <view class="course-progress">
            <view class="progress-bar">
              <view class="progress-fill"
                    :style="{width: ((course.total_count > 0 ? Math.round((course.used_count / course.total_count) * 100) : 0)) + '%'}">
              </view>
            </view>
            <view class="progress-text">{{ course.used_count || 0 }}/{{ course.total_count || 0 }}节
            </view>
          </view>

          <view class="course-details">
            <view class="detail-row">
              <view class="detail-label">剩余课时：</view>
              <view class="detail-value">{{ (course.total_count || 0) - (course.used_count || 0) }}节
              </view>
            </view>
            <view class="detail-row">
              <view class="detail-label">有效期至：</view>
              <view class="detail-value">
                {{ $util.formatToDateTime(course.expiry_date, 'Y-m-d') || '无限期' }}
              </view>
            </view>
            <view class="detail-row">
              <view class="detail-label">请假次数：</view>
              <view class="detail-value">{{ course.leave_count || 0 }}次</view>
            </view>
            <view class="detail-row">
              <view class="detail-label">主教练：</view>
              <view class="detail-value">{{ course.main_coach_name || '未分配' }}</view>
            </view>
            <view class="detail-row">
              <view class="detail-label">教务：</view>
              <view class="detail-value">{{ course.education_name || '未分配' }}</view>
            </view>
            <view class="detail-row">
              <view class="detail-label">助教：</view>
              <view class="detail-value">{{ course.assistant_names || '无' }}</view>
            </view>
          </view>

          <view class="course-actions">
            <view class="action-btn" @click.stop="openCourseEditDialog(course)">点击修改教练配置</view>
          </view>
        </view>
      </view>
      <view v-else class="empty-course">
        <image src="/static/images/empty.png" mode="aspectFit" class="empty-img"></image>
        <text class="empty-text">暂无课程信息</text>
      </view>
      <view style="height: 200rpx;"></view>
    </view>

    <!--      通话记录-->
    <view class="call-log" v-if="switch_tags_type == 3">
      <view class="call-record-wrapper" v-for="(v,k) in listCallUp" :key="k">
        <view class="call-record-item">
          <view class="call-record-header">
            <view class="call-name">{{ v.name }}</view>
            <view class="call-time">{{ v.create_time }}</view>
          </view>
          <view class="call-record-content">
            <view class="call-detail">
              <text class="call-label">呼叫时间：</text>
              <text>{{ v.created_at }}</text>
            </view>
            <button type="primary" size="mini" class="remark-btn" @click="openAddRemark(v)">
              {{ v.remarks ? '修改备注' : '添加备注' }}
            </button>
          </view>
          <view class="call-remark">
            <text class="call-label">呼叫备注：</text>
            <text class="call-remark-content">{{ v.remarks || '无' }}</text>
          </view>
        </view>
      </view>
      <view style="height: 200rpx;"></view>
    </view>
    <!-- 体测记录 -->
    <view class="fitness-test-records" v-if="switch_tags_type == 4">
      <!-- 新增按钮 -->
      <view class="add-record-btn-container">
        <view class="add-record-btn" @click="openAddFitnessRecord">
          <view class="add-icon">+</view>
          <view class="add-text">新增体测记录</view>
        </view>
      </view>
      
      <!-- 体测记录列表 -->
      <view class="fitness-record-list">
        <view v-if="fitnessRecords.length === 0" class="empty-records">
          <image src="/static/images/empty.png" mode="aspectFit" class="empty-img"></image>
          <text class="empty-text">暂无体测记录</text>
        </view>
        
        <view v-for="(record, index) in fitnessRecords" :key="index" 
              class="fitness-record-item" @click="openEditFitnessRecord(record)">
          <view class="record-header">
            <view class="record-date">{{ record.test_date }}</view>
            <view class="record-actions">
              <view class="edit-btn" @click.stop="openEditFitnessRecord(record)">编辑</view>
            </view>
          </view>
          
          <view class="record-content">
            <view class="record-data">
              <view class="data-item">
                <view class="data-label">身高</view>
                <view class="data-value">{{ record.height }}cm</view>
              </view>
              <view class="data-item">
                <view class="data-label">体重</view>
                <view class="data-value">{{ record.weight }}kg</view>
              </view>
            </view>
            
            <!-- PDF附件列表 -->
            <view class="pdf-attachments" v-if="record.pdf_files && record.pdf_files.length > 0">
              <view class="attachment-title">体测报告</view>
              <view class="pdf-list">
                <view v-for="(pdf, pdfIndex) in record.pdf_files" :key="pdfIndex" 
                      class="pdf-item" @click.stop="previewPDF(pdf)">
                  <view class="pdf-icon">📄</view>
                  <view class="pdf-name">{{ pdf.name }}</view>
                  <view class="pdf-size">{{ formatFileSize(pdf.size) }}</view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <!--  学习计划  -->
    <view class="study-plan" v-if="switch_tags_type == 5">

    </view>
    <!-- 底部按钮组已移除，操作按钮已整合到学生卡片中 -->

    <!-- 添加备注弹窗 -->
    <uni-popup ref="remarkPopup" type="dialog">
      <view class="custom-popup-dialog">
        <view class="dialog-header">
          <text class="dialog-title">{{ currentRecord && currentRecord.remarks ? '修改备注' : '添加备注' }}</text>
        </view>
        <view class="dialog-content">
          <view class="remark-textarea-container">
							<textarea class="remark-textarea" v-model="remark_content" placeholder="请输入备注内容"
                        maxlength="200"></textarea>
            <text class="remark-count">{{ remark_content.length }}/200</text>
          </view>
        </view>
        <view class="dialog-footer">
          <view class="dialog-btn cancel-btn" @click="closeRemark">取消</view>
          <view class="dialog-btn confirm-btn" @click="confirmRemark">确定</view>
        </view>
      </view>
    </uni-popup>

    <!-- 体测记录编辑弹窗 -->
    <uni-popup ref="fitnessRecordPopup" type="center">
      <view class="popup-container">
        <view class="popup-header">
          <view class="popup-title">{{ isEditingFitnessRecord ? '编辑体测记录' : '新增体测记录' }}</view>
          <view class="popup-close" @click="closeFitnessRecordEdit">✕</view>
        </view>
        <view class="fitness-record-form">
          <view class="form-section">
            <view class="form-item">
              <view class="form-label">测试日期</view>
              <view class="form-input">
                <input type="date" v-model="currentFitnessRecord.test_date" placeholder="请选择测试日期" />
              </view>
            </view>
            
            <view class="form-item">
              <view class="form-label">身高(cm)</view>
              <view class="form-input">
                <input type="number" v-model="currentFitnessRecord.height" placeholder="请输入身高" />
              </view>
            </view>
            
            <view class="form-item">
              <view class="form-label">体重(kg)</view>
              <view class="form-input">
                <input type="number" v-model="currentFitnessRecord.weight" placeholder="请输入体重" />
              </view>
            </view>
            
            <view class="form-item">
              <view class="form-label">体测报告</view>
              <view class="file-upload-area">
                <view class="upload-btn" @click="selectPDFFiles">
                  <view class="upload-icon">📁</view>
                  <view class="upload-text">选择PDF文件</view>
                </view>
                
                <!-- 已选择的PDF文件列表 -->
                <view v-if="currentFitnessRecord.pdf_files && currentFitnessRecord.pdf_files.length > 0" 
                      class="selected-files">
                  <view v-for="(pdf, index) in currentFitnessRecord.pdf_files" :key="index" 
                        class="selected-file-item">
                    <view class="file-info">
                      <view class="file-icon">📄</view>
                      <view class="file-name">{{ pdf.name }}</view>
                      <view class="file-size">{{ formatFileSize(pdf.size) }}</view>
                    </view>
                    <view class="file-remove" @click="removePDFFile(index)">✕</view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="popup-footer">
          <view class="popup-btn cancel-btn" @click="closeFitnessRecordEdit">取消</view>
          <view class="popup-btn confirm-btn" @click="confirmFitnessRecordEdit">确认</view>
        </view>
      </view>
    </uni-popup>

    <!-- 教练配置编辑弹窗 -->
    <uni-popup ref="courseEditPopup" type="center">
      <view class="popup-container">
        <view class="popup-header">
          <view class="popup-title">修改教练配置</view>
          <view class="popup-close" @click="closeCourseEdit">✕</view>
        </view>
        <view class="course-edit-container">
          <view class="edit-section">
            <view class="section-title">主教练（单选）</view>
            <view v-if="coachList.length === 0" class="empty-tip">暂无主教练数据</view>
            <view class="coach-list">
              <view v-for="coach in coachList" :key="coach.person_id" class="coach-item"
                    :class="{selected: selectedMainCoach === coach.person_id}"
                    @click="selectMainCoach(coach.person_id)">
                <view class="coach-name">{{ coach.name }}</view>
                <view class="coach-check" v-if="selectedMainCoach === coach.person_id">✓</view>
              </view>
            </view>
          </view>

          <view class="edit-section">
            <view class="section-title">教务（单选）</view>
            <view v-if="educationList.length === 0" class="empty-tip">暂无教务数据</view>
            <view class="coach-list">
              <view v-for="education in educationList" :key="education.person_id" class="coach-item"
                    :class="{selected: selectedEducation === education.person_id}"
                    @click="selectEducation(education.person_id)">
                <view class="coach-name">{{ education.name }}</view>
                <view class="coach-check" v-if="selectedEducation === education.person_id">✓</view>
              </view>
            </view>
          </view>

          <view class="edit-section">
            <view class="section-title">助教（多选）</view>
            <view v-if="assistantList.length === 0" class="empty-tip">暂无助教数据</view>
            <view class="coach-list">
              <view v-for="assistant in assistantList" :key="assistant.person_id" class="coach-item"
                    :class="{selected: selectedAssistants.includes(assistant.person_id)}"
                    @click="toggleAssistant(assistant.person_id)">
                <view class="coach-name">{{ assistant.name }}</view>
                <view class="coach-check" v-if="selectedAssistants.includes(assistant.person_id)">✓
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="popup-footer">
          <view class="popup-btn cancel-btn" @click="closeCourseEdit">取消</view>
          <view class="popup-btn confirm-btn" @click="confirmCourseEdit">确认</view>
        </view>
      </view>
    </uni-popup>

    <!-- 学生信息编辑弹窗 -->
    <uni-popup ref="studentEditPopup" type="center">
      <view class="popup-container student-edit-popup">
        <view class="popup-header">
          <view class="popup-title">{{ isEditingStudent ? '编辑学生信息' : '添加学生信息' }}</view>
          <view class="popup-close" @click="closeStudentEdit">✕</view>
        </view>
        <scroll-view class="student-form-container" scroll-y="true">
          <view class="form-section">
            <!-- 基本信息 -->
            <view class="form-group">
              <view class="form-group-title">基本信息</view>
              
              <view class="form-item">
                <view class="form-label required">姓名</view>
                <view class="form-input">
                  <input type="text" v-model="currentStudent.name" placeholder="请输入学生姓名" maxlength="20" />
                </view>
              </view>
              
              <view class="form-item">
                <view class="form-label required">性别</view>
                <view class="form-input">
                  <picker :range="genderOptions" range-key="label" @change="onGenderChange">
                    <view class="picker-display">
                      {{ formatGender(currentStudent.gender) || '请选择性别' }}
                      <text class="picker-arrow">›</text>
                    </view>
                  </picker>
                </view>
              </view>
              
              <view class="form-item">
                <view class="form-label required">出生日期</view>
                <view class="form-input">
                  <picker mode="date" :value="currentStudent.birthday" @change="onBirthdayChange">
                    <view class="picker-display">
                      {{ currentStudent.birthday || '请选择出生日期' }}
                      <text class="picker-arrow">›</text>
                    </view>
                  </picker>
                </view>
              </view>
              
              <view class="form-item">
                <view class="form-label">联系电话</view>
                <view class="form-input">
                  <input type="number" v-model="currentStudent.contact_phone" placeholder="请输入联系电话" maxlength="20" />
                </view>
              </view>
              
              <view class="form-item">
                <view class="form-label">紧急联系人</view>
                <view class="form-input">
                  <input type="text" v-model="currentStudent.emergency_contact" placeholder="请输入紧急联系人" maxlength="255" />
                </view>
              </view>
            </view>
            
            <!-- 学员信息 -->
            <view class="form-group">
              <view class="form-group-title">学员信息</view>
              
              <view class="form-item">
                <view class="form-label">会员标签</view>
                <view class="form-input">
                  <input type="text" v-model="currentStudent.member_label" placeholder="请输入会员标签" maxlength="255" />
                </view>
              </view>
              
              <view class="form-item">
                <view class="form-label">体验课次数</view>
                <view class="form-input">
                  <input type="number" v-model="currentStudent.trial_class_count" placeholder="体验课次数" />
                </view>
              </view>
              
              <view class="form-item">
                <view class="form-label">学员状态</view>
                <view class="form-input">
                  <picker :range="[{label: '无效', value: 0}, {label: '有效', value: 1}]" range-key="label" @change="onStatusChange">
                    <view class="picker-display">
                      {{ currentStudent.status === 1 ? '有效' : '无效' }}
                      <text class="picker-arrow">›</text>
                    </view>
                  </picker>
                </view>
              </view>
            </view>
            
            <!-- 其他信息 -->
            <view class="form-group">
              <view class="form-group-title">其他信息</view>
              
              <view class="form-item">
                <view class="form-label">备注</view>
                <view class="form-textarea">
                  <textarea v-model="currentStudent.note" placeholder="请输入备注信息" maxlength="200"></textarea>
                </view>
              </view>
            </view>
          </view>
        </scroll-view>
        <view class="popup-footer">
          <view class="popup-btn cancel-btn" @click="closeStudentEdit">取消</view>
          <view class="popup-btn confirm-btn" @click="confirmStudentEdit">保存</view>
        </view>
      </view>
    </uni-popup>
  </view>
  </view>
</template>

<script>
import apiRoute from '@/api/apiRoute.js'
import marketApi from '@/api/market.js'

export default {
  components: {
    // 导入组件
    uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
  },
  data() {
    return {
      switch_tags_type: 1,
      select_type: 1,

      resource_sharing_id: '', //共享资源表id
      clientInfo: {
        id: '', //共享资源id
        resource_id: '', //客户资源id
        customerResource: {}, //客户资源信息
        sixSpeed: {}, //六要素信息
      }, //共享资源详情

      //跟进记录列表
      followList: [],
      //通话记录列表
      listCallUp: [],

      //当前登录的员工信息
      userInfo: {},

      // 备注相关
      remark_content: '',
      // 当前选中的通话记录
      currentRecord: null,

      // 课程信息相关
      courseInfo: [], // 课程信息列表
      currentCourse: null, // 当前选中的课程

      // 教练配置相关
      coachList: [], // 主教练列表
      educationList: [], // 教务列表
      assistantList: [], // 助教列表

      // 选中的配置
      selectedMainCoach: null, // 选中的主教练ID
      selectedEducation: null, // 选中的教务ID
      selectedAssistants: [], // 选中的助教ID数组

      // 体测记录相关
      fitnessRecords: [], // 体测记录列表
      currentFitnessRecord: {
        id: null,
        test_date: '',
        height: '',
        weight: '',
        pdf_files: []
      }, // 当前编辑的体测记录
      isEditingFitnessRecord: false, // 是否为编辑模式
      
      // 学生信息相关 (基于school_student表结构)
      studentList: [], // 学生列表
      currentStudent: {
        id: null,
        name: '',
        gender: 0, // 性别: 0未知, 1男, 2女
        age: 0.00, // 年龄，支持小数表示，例如3.11表示3岁11个月
        birthday: null,
        user_id: 0, // 资源ID
        campus_id: null,
        class_id: null,
        note: '', // 备注信息
        status: 1, // 学员状态: 0无效, 1有效
        emergency_contact: '', // 紧急联系人
        contact_phone: '', // 联系人电话
        member_label: '', // 会员标签
        consultant_id: null,
        coach_id: null,
        trial_class_count: 2, // 体验课次数|默认2（新增学员赠送）
        actionsExpanded: false // 操作面板展开状态
      }, // 当前编辑的学生信息
      isEditingStudent: false, // 是否为编辑模式
      currentStudentIndex: 0, // 当前显示的学生索引
      
      // 操作按钮相关
      actionButtons: [
        { key: 'edit_detail', text: '编辑详情', icon: '✏️' },
        { key: 'course_arrangement', text: '课程安排', icon: '📅' },
        { key: 'edit_record', text: '修改记录', icon: '📝' },
        { key: 'order_list', text: '订单列表', icon: '📋' },
        { key: 'service_list', text: '服务列表', icon: '🔧' }
      ], // 默认操作按钮
      
      // 选项数据
      genderOptions: [
        { label: '未知', value: 0 },
        { label: '男', value: 1 },
        { label: '女', value: 2 }
      ]
    }
  },
  computed: {
    // 判断是否有课程信息
    hasCourseInfo() {
      return this.courseInfo && Array.isArray(this.courseInfo) && this.courseInfo.length > 0
    },
    
    // 获取排序后的操作按钮
    sortedActions() {
      // 从本地存储获取排序配置
      const savedOrder = uni.getStorageSync('action_buttons_order')
      if (savedOrder && Array.isArray(savedOrder)) {
        // 根据保存的顺序重新排列
        const sortedButtons = []
        savedOrder.forEach(key => {
          const button = this.actionButtons.find(btn => btn.key === key)
          if (button) sortedButtons.push(button)
        })
        // 添加新增的按钮（如果有）
        this.actionButtons.forEach(button => {
          if (!savedOrder.includes(button.key)) {
            sortedButtons.push(button)
          }
        })
        return sortedButtons
      }
      return this.actionButtons
    },
    
    // 获取学生专用的排序后操作按钮
    sortedStudentActions() {
      const studentActions = [
        { key: 'course_info', text: '课程信息', icon: '📚' },
        { key: 'fitness_record', text: '体测记录', icon: '📊' },
        { key: 'study_plan', text: '学习计划', icon: '📋' },
        { key: 'course_arrangement', text: '课程安排', icon: '📅' },
        { key: 'order_list', text: '订单列表', icon: '📃' },
        { key: 'service_list', text: '服务列表', icon: '🔧' }
      ]
      
      // 从本地存储获取学生操作按钮排序配置
      const savedOrder = uni.getStorageSync('student_action_buttons_order')
      if (savedOrder && Array.isArray(savedOrder)) {
        const sortedButtons = []
        savedOrder.forEach(key => {
          const button = studentActions.find(btn => btn.key === key)
          if (button) sortedButtons.push(button)
        })
        // 添加新增的按钮（如果有）
        studentActions.forEach(button => {
          if (!savedOrder.includes(button.key)) {
            sortedButtons.push(button)
          }
        })
        return sortedButtons
      }
      return studentActions
    }
  },
  onLoad(options) {
    console.log('onLoad - 接收到参数:', options)

    // 检查options是否存在且包含resource_sharing_id
    if (!options || !options.resource_sharing_id) {
      console.error('onLoad - 缺少必要参数resource_sharing_id')
      uni.showToast({
        title: '缺少必要参数',
        icon: 'none',
      })

      // 延迟返回上一页
      setTimeout(() => {
        uni.navigateBack()
      }, 1500)
      return
    }

    this.resource_sharing_id = options.resource_sharing_id //共享资源表id
    console.log('onLoad - 设置 resource_sharing_id:', this.resource_sharing_id)
  },
  onShow() {
    console.log('onShow - 开始初始化')
    this.init()
  },
  methods: {
    async init() {
      console.log('init - 开始初始化流程')

      // 恢复为串行请求处理，确保数据依赖关系正确
      try {
        // 先获取客户详情，因为其他操作可能依赖于客户详情
        console.log('init - 开始获取客户详情')
        await this.getInfo()
        console.log('init - 客户详情获取完成')

        // 获取员工信息、通话记录、教练列表、课程信息、体测记录和学生列表可以并行
        console.log('init - 开始获取员工信息、通话记录、教练列表、课程信息、体测记录和学生列表')
        await Promise.all([
          this.getUserInfo(),
          this.getListCallUp(),
          this.getPersonnelList(),
          this.getCourseInfo(), // 添加课程信息获取
          this.getFitnessRecords(), // 添加体测记录获取
          this.getStudentList(), // 添加学生列表获取
        ])
        console.log('init - 员工信息、通话记录、教练列表、课程信息、体测记录和学生列表获取完成')
      } catch (error) {
        console.error('init - 数据加载出错:', error)
      }
    },

    //获取当前登录的员工信息
    async getUserInfo() {
      console.log('getUserInfo - 开始获取员工信息')
      try {
        let res = await apiRoute.getPersonnelInfo({})
        if (res.code != 1) {
          uni.showToast({
            title: res.msg,
            icon: 'none',
          })
          return false
        }

        this.userInfo = res.data
        console.log('getUserInfo - 员工信息获取成功')
        return true
      } catch (error) {
        console.error('getUserInfo - 获取员工信息失败:', error)
        return false
      }
    },

    //获取客户详情
    async getInfo() {
      console.log('getInfo - 开始获取客户详情, resource_sharing_id:', this.resource_sharing_id)
      try {
        // 检查resource_sharing_id是否存在
        if (!this.resource_sharing_id) {
          console.error('getInfo - resource_sharing_id为空，无法获取客户详情')
          uni.showToast({
            title: '缺少必要参数',
            icon: 'none',
          })
          return false
        }

        let data = {
          resource_sharing_id: this.resource_sharing_id, //共享资源表id
        }
        console.log('getInfo - 发起请求:', data)
        let res = await apiRoute.xs_resourceSharingInfo(data)
        console.log('getInfo - 请求响应:', res)
        if (res.code != 1) {
          console.error('getInfo - 请求失败:', res.msg)
          uni.showToast({
            title: res.msg,
            icon: 'none',
          })
          return false
        }
        this.clientInfo = res.data
        console.log('getInfo - 客户详情数据:', this.clientInfo)
        console.log('getInfo - 客户详情获取完成')
        return true
      } catch (error) {
        console.error('getInfo - 获取客户详情失败:', error)
        return false
      }
    },

    //获取跟进记录
    async getFollowList() {
      let data = {
        sales_id: this.resource_sharing_id, //
      }
      let res = await marketApi.followList(data)
      if (res.code != 1) {
        uni.showToast({
          title: res.msg,
          icon: 'none',
        })
        return
      }
      this.followList = res.data
    },

    //获取通话记录
    async getListCallUp() {
      console.log('getListCallUp - 开始获取通话记录')
      try {
        // 检查clientInfo.resource_id是否存在
        if (!this.clientInfo || !this.clientInfo.resource_id) {
          console.error('getListCallUp - resource_id为空，无法获取通话记录')
          return false
        }

        let data = {
          resource_id: this.clientInfo.resource_id, // 使用正确的参数名和客户资源ID
        }
        console.log('getListCallUp - 请求参数:', data)
        let res = await apiRoute.listCallUp(data)
        console.log('getListCallUp - 响应:', res)
        if (res.code != 1) {
          uni.showToast({
            title: res.msg || '获取通话记录失败',
            icon: 'none',
          })
          return false
        }
        this.listCallUp = res.data || []
        console.log('getListCallUp - 通话记录获取成功, 数量:', this.listCallUp.length)
        return true
      } catch (error) {
        console.error('getListCallUp - 获取通话记录失败:', error)
        return false
      }
    },

    //跳转页面-编辑客户详情
    openViewEditClues() {
      // 检查resource_sharing_id是否存在
      if (!this.resource_sharing_id) {
        console.error('openViewEditClues - resource_sharing_id为空，无法跳转')
        uni.showToast({
          title: '缺少必要参数',
          icon: 'none',
        })
        return
      }

      let resource_sharing_id = this.resource_sharing_id //共享资源表id
      this.$navigateTo({
        url: `/pages/market/clue/edit_clues?resource_sharing_id=${resource_sharing_id}`,
      })
    },

    //跳转页面-客户信息修改记录
    openViewEditCluesLog() {
      // 检查clientInfo.resource_id是否存在
      const resource_id = this.safeGet(this.clientInfo, 'resource_id')
      if (!resource_id) {
        console.error('openViewEditCluesLog - resource_id为空，无法跳转')
        uni.showToast({
          title: '缺少必要参数',
          icon: 'none',
        })
        return
      }

      this.$navigateTo({
        url: `/pages/market/clue/edit_clues_log?resource_id=${resource_id}`,
      })
    },

    //跳转页面-订单列表（支持学生参数）
    openViewOrder(student = null) {
      // 检查必要参数是否存在
      const resource_id = this.safeGet(this.clientInfo, 'resource_id')
      if (!resource_id) {
        console.error('openViewOrder - resource_id为空，无法跳转')
        uni.showToast({
          title: '缺少必要参数',
          icon: 'none',
        })
        return
      }

      let resource_name = this.safeGet(this.clientInfo, 'customerResource.name', '') //客户资源id姓名
      let staff_id = this.safeGet(this.userInfo, 'id', '') //员工id
      let staff_id_name = this.safeGet(this.userInfo, 'name', '') //员工姓名

      // 如果有学生信息，添加学生参数
      let url = `/pages/market/clue/order_list?resource_id=${resource_id}&resource_name=${resource_name}&staff_id=${staff_id}&staff_id_name=${staff_id_name}`
      if (student) {
        url += `&student_id=${student.id}&student_name=${encodeURIComponent(student.name)}`
      }

      this.$navigateTo({
        url: url,
      })
    },

    //跳转页面-课程安排（支持学生参数）
    openViewEditClassLog(student = null) {
      let resource_id = this.clientInfo.resource_id //客户资源id
      let resource_name = this.clientInfo.customerResource.name || '' //客户资源id姓名

      let staff_id = this.userInfo.id //员工id
      let staff_id_name = this.userInfo.name || '' //员工姓名

      // 如果有学生信息，添加学生参数
      let url = `/pages/market/clue/class_arrangement?resource_id=${resource_id}&resource_name=${resource_name}&staff_id=${staff_id}&staff_id_name=${staff_id_name}`
      if (student) {
        url += `&student_id=${student.id}&student_name=${encodeURIComponent(student.name)}`
      }

      this.$navigateTo({
        url: url,
      })
    },

    //跳转页面-编辑客户详情（支持学生参数）
    openViewEditClues(student = null) {
      // 检查resource_sharing_id是否存在
      if (!this.resource_sharing_id) {
        console.error('openViewEditClues - resource_sharing_id为空，无法跳转')
        uni.showToast({
          title: '缺少必要参数',
          icon: 'none',
        })
        return
      }

      let resource_sharing_id = this.resource_sharing_id //共享资源表id
      let url = `/pages/market/clue/edit_clues?resource_sharing_id=${resource_sharing_id}`
      if (student) {
        url += `&student_id=${student.id}&student_name=${encodeURIComponent(student.name)}`
      }

      this.$navigateTo({
        url: url,
      })
    },

    //跳转页面-客户信息修改记录（支持学生参数）
    openViewEditCluesLog(student = null) {
      // 检查clientInfo.resource_id是否存在
      const resource_id = this.safeGet(this.clientInfo, 'resource_id')
      if (!resource_id) {
        console.error('openViewEditCluesLog - resource_id为空，无法跳转')
        uni.showToast({
          title: '缺少必要参数',
          icon: 'none',
        })
        return
      }

      let url = `/pages/market/clue/edit_clues_log?resource_id=${resource_id}`
      if (student) {
        url += `&student_id=${student.id}&student_name=${encodeURIComponent(student.name)}`
      }

      this.$navigateTo({
        url: url,
      })
    },

    //跳转页面-转接跟进任务
    openViewNewTask() {
      this.$navigateTo({
        url: `/pages/market/clue/new_task`,
      })
    },

    //拨打电话
    async callTel(tel) {
      let param = {
        staff_id: this.userInfo.id, //员工id
        resource_id: this.clientInfo.resource_id, //资源ID
        resource_type: '', //资源类型（如设备、文件、系统等）
        communication_type: 'phone', //沟通类型: phone-电话, email-邮件, meeting-会议, other-其他
        communication_result: 'success', //沟通结果: success-成功, failure-失败, pending-待定
        remarks: null, //备注
        tag: null, //标签
      }

      let res = await apiRoute.xs_communicationRecordsAdd(param) //添加通过记录
      if (res.code != 1) {
        uni.showToast({
          title: res.msg,
          icon: 'none',
        })
        return
      }

      uni.makePhoneCall({
        phoneNumber: tel,
      })
    },

    // 打开添加备注弹窗
    openAddRemark(record) {
      this.remark_content = record.remarks || '' // 如果有现有备注，显示出来
      this.currentRecord = record
      this.$refs.remarkPopup.open()
    },

    // 确认添加备注
    async confirmRemark() {
      if (!this.remark_content.trim()) {
        uni.showToast({
          title: '请输入备注内容',
          icon: 'none',
        })
        return
      }

      // 检查是否选中了通话记录
      if (!this.currentRecord || !this.currentRecord.id) {
        uni.showToast({
          title: '未选中通话记录',
          icon: 'none',
        })
        return
      }

      try {
        uni.showLoading({
          title: '提交中...',
          mask: true,
        })

        // 使用更新备注的接口而不是添加新记录
        const params = {
          id: this.currentRecord.id, // 通话记录ID
          remarks: this.remark_content, // 备注内容
        }

        console.log('更新通话记录备注:', params)

        // 调用更新备注的接口
        const res = await apiRoute.xs_communicationRecordsEdit(params)

        if (res.code !== 1) {
          uni.showToast({
            title: res.msg || '更新备注失败',
            icon: 'none',
          })
          return
        }

        uni.showToast({
          title: '备注更新成功',
          icon: 'success',
        })

        // 刷新通话记录列表
        await this.getListCallUp()

      } catch (error) {
        console.error('更新备注失败:', error)
        uni.showToast({
          title: '更新备注失败，请重试',
          icon: 'none',
        })
      } finally {
        uni.hideLoading()
        this.closeRemark()
      }
    },

    // 关闭备注弹窗
    closeRemark() {
      this.$refs.remarkPopup.close()
    },

    // 拨打电话按钮点击
    handleMakeCall() {
      if (!this.clientInfo.customerResource.phone_number) {
        uni.showToast({
          title: '电话号码为空',
          icon: 'none',
        })
        return
      }
      this.callTel(this.clientInfo.customerResource.phone_number)
    },

    // 发送消息按钮点击
    handleSendMessage() {
      if (!this.clientInfo.customerResource.member_id) {
        uni.showToast({
          title: '该客户未注册账号，无法发送消息',
          icon: 'none',
        })
        return
      }

      let from_id = uni.getStorageSync('userInfo').id //发送者的id
      let to_id = this.clientInfo.customerResource.member_id //接收者ID
      this.$navigateTo({
        url: `/pages/common/im_chat_info?from_id=${from_id}&to_id=${to_id}`,
      })
    },

    //切换标签
    async switch_tags(type) {
      // 如果点击课程信息标签但没有课程数据，则不允许切换
      if (type === 2 && !this.hasCourseInfo) {
        uni.showToast({
          title: '暂无课程信息',
          icon: 'none',
        })
        return
      }

      this.switch_tags_type = type

      // 当切换到课程信息时，刷新课程数据
      if (type === 2) {
        await this.getCourseInfo()
      }

      // 当切换到通话记录时，刷新通话记录数据
      if (type === 3) {
        await this.getListCallUp()
        console.log('刷新通话记录数据，当前记录数：', this.listCallUp.length)
      }

      // 当切换到体测记录时，刷新体测记录数据
      if (type === 4) {
        await this.getFitnessRecords()
        console.log('刷新体测记录数据，当前记录数：', this.fitnessRecords.length)
      }
    },
    getSelect(type) {
      this.select_type = type
    },

    // 获取课程信息
    async getCourseInfo() {
      try {
        if (!this.clientInfo.resource_id) {
          console.error('getCourseInfo - resource_id为空，无法获取课程信息')
          this.courseInfo = []
          return false
        }

        // 使用学生课程信息接口
        const params = {
          resource_id: this.clientInfo.resource_id,
          member_id: this.clientInfo.customerResource.member_id || '',
        }

        console.log('getCourseInfo - 请求参数:', params)

        try {
          const res = await apiRoute.getStudentCourseInfo(params)
          console.log('getCourseInfo - API响应:', res)

          if (res.code === 1) {
            // 格式化课程数据
            this.courseInfo = this.formatCourseData(res.data || [])
            console.log('getCourseInfo - 课程信息获取成功:', this.courseInfo)
            return true
          } else {
            console.warn('API返回错误:', res.msg)
            this.courseInfo = []
            return false
          }
        } catch (apiError) {
          console.warn('获取课程信息API调用失败:', apiError)
          this.courseInfo = []
          return false
        }
      } catch (error) {
        console.error('getCourseInfo - 获取课程信息异常:', error)
        this.courseInfo = []
        return false
      }
    },

    // 格式化课程数据
    formatCourseData(rawData) {
      if (!Array.isArray(rawData)) {
        return []
      }

      return rawData.map(item => ({
        id: item.id || Math.random(),
        course_name: item.course_name || '未知课程',
        total_count: item.total_count || 0,
        used_count: item.used_count || 0,
        leave_count: item.leave_count || 0,
        expiry_date: item.expiry_date || '',
        status: item.status || 'active',
        main_coach_id: item.main_coach_id || null,
        main_coach_name: item.main_coach_name || '未分配',
        education_id: item.education_id || null,
        education_name: item.education_name || '未分配',
        assistant_ids: item.assistant_ids || '',
        assistant_names: item.assistant_names || '无',
      }))
    },


    // 获取人员列表（教练、教务、助教）
    async getPersonnelList() {
      try {
        console.log('getPersonnelList - 开始获取教练数据')

        uni.showLoading({
          title: '获取教练数据...',
        })

        const res = await apiRoute.common_getCoachList()
        console.log('getPersonnelList - API响应:', res)

        uni.hideLoading()

        if (res.code === 1 && res.data) {
          // 直接使用后端返回的分类数据
          this.coachList = res.data.coach_list || []
          this.educationList = res.data.education_list || []
          this.assistantList = res.data.assistant_list || []

          console.log('getPersonnelList - 教练数据获取成功')
          console.log('教练列表:', this.coachList)
          console.log('教务列表:', this.educationList)
          console.log('助教列表:', this.assistantList)
          return true
        } else {
          console.warn('API返回错误:', res)

          // 显示API错误信息
          uni.showToast({
            title: res.msg || '获取教练数据失败',
            icon: 'none',
          })

          // 如果API调用失败，使用模拟数据
          this.coachList = this.getMockCoachList()
          this.educationList = this.getMockEducationList()
          this.assistantList = this.getMockAssistantList()

          console.log('getPersonnelList - 使用模拟教练数据')
          console.log('模拟教练列表:', this.coachList)
          console.log('模拟教务列表:', this.educationList)
          console.log('模拟助教列表:', this.assistantList)
          return true
        }
      } catch (error) {
        console.error('getPersonnelList - 获取教练列表异常:', error)
        uni.hideLoading()

        // 显示错误信息
        uni.showToast({
          title: '网络错误，使用模拟数据',
          icon: 'none',
        })

        // 降级到模拟数据
        this.coachList = this.getMockCoachList()
        this.educationList = this.getMockEducationList()
        this.assistantList = this.getMockAssistantList()

        console.log('getPersonnelList - 使用模拟教练数据（异常情况）')
        console.log('模拟教练列表:', this.coachList)
        console.log('模拟教务列表:', this.educationList)
        console.log('模拟助教列表:', this.assistantList)
        return false
      }
    },

    // 获取模拟教练数据
    getMockCoachList() {
      return [{
        id: 1,
        person_id: 1,
        name: '张教练',
        head_img: '',
        phone: '',
      },
        {
          id: 5,
          person_id: 5,
          name: '陈教练',
          head_img: '',
          phone: '',
        },
        {
          id: 7,
          person_id: 7,
          name: '刘教练',
          head_img: '',
          phone: '',
        },
      ]
    },

    // 获取模拟教务数据
    getMockEducationList() {
      return [{
        id: 2,
        person_id: 2,
        name: '李教务',
        head_img: '',
        phone: '',
      },
        {
          id: 8,
          person_id: 8,
          name: '周教务',
          head_img: '',
          phone: '',
        },
      ]
    },

    // 获取模拟助教数据
    getMockAssistantList() {
      return [{
        id: 3,
        person_id: 3,
        name: '王助教',
        head_img: '',
        phone: '',
      },
        {
          id: 4,
          person_id: 4,
          name: '赵助教',
          head_img: '',
          phone: '',
        },
        {
          id: 6,
          person_id: 6,
          name: '孙助教',
          head_img: '',
          phone: '',
        },
        {
          id: 9,
          person_id: 9,
          name: '钱助教',
          head_img: '',
          phone: '',
        },
      ]
    },

    // 打开课程编辑弹窗
    async openCourseEditDialog(course) {
      this.currentCourse = course

      // 确保教练数据已加载
      console.log('打开教练配置弹窗，检查教练数据:', {
        coachList: this.coachList,
        educationList: this.educationList,
        assistantList: this.assistantList,
      })

      // 如果教练数据为空，重新获取
      if (!this.coachList.length && !this.educationList.length && !this.assistantList.length) {
        console.log('教练数据为空，重新获取...')
        await this.getPersonnelList()
      }

      // 设置当前选中的配置，使用person_id进行回显
      this.selectedMainCoach = course.main_coach_id
      this.selectedEducation = course.education_id
      this.selectedAssistants = course.assistant_ids ? course.assistant_ids.split(',').map(Number) : []

      console.log('打开教练配置弹窗:', {
        course: course,
        selectedMainCoach: this.selectedMainCoach,
        selectedEducation: this.selectedEducation,
        selectedAssistants: this.selectedAssistants,
        coachListLength: this.coachList.length,
        educationListLength: this.educationList.length,
        assistantListLength: this.assistantList.length,
      })

      this.$refs.courseEditPopup.open()
    },

    // 选择主教练
    selectMainCoach(personId) {
      this.selectedMainCoach = personId
      console.log('选择主教练:', personId)
    },

    // 选择教务
    selectEducation(personId) {
      this.selectedEducation = personId
      console.log('选择教务:', personId)
    },

    // 切换助教选择
    toggleAssistant(personId) {
      const index = this.selectedAssistants.indexOf(personId)
      if (index > -1) {
        this.selectedAssistants.splice(index, 1)
      } else {
        this.selectedAssistants.push(personId)
      }
      console.log('切换助教选择:', personId, '当前选中:', this.selectedAssistants)
    },

    // 确认修改教练配置
    async confirmCourseEdit() {
      try {
        uni.showLoading({
          title: '保存中...',
          mask: true,
        })

        const params = {
          student_course_id: this.currentCourse.id,
          main_coach_id: this.selectedMainCoach, // 使用person_id
          education_id: this.selectedEducation, // 使用person_id
          assistant_ids: this.selectedAssistants.join(','), // 使用person_id数组
        }

        console.log('准备保存教练配置:', params)

        try {
          // 调用真实的API接口
          const res = await apiRoute.updateStudentCoursePersonnel(params)
          if (res.code === 1) {
            uni.showToast({
              title: '修改成功',
              icon: 'success',
            })

            // 刷新课程信息
            await this.getCourseInfo()

          } else {
            uni.showToast({
              title: res.msg || '修改失败',
              icon: 'none',
            })
            return
          }
        } catch (apiError) {
          console.warn('API调用失败，使用本地更新:', apiError)

          // API调用失败时的降级处理：更新本地数据
          const courseIndex = this.courseInfo.findIndex(c => c.id === this.currentCourse.id)
          if (courseIndex > -1) {
            // 更新主教练
            const mainCoach = this.coachList.find(c => c.person_id === this.selectedMainCoach)
            if (mainCoach) {
              this.courseInfo[courseIndex].main_coach_id = this.selectedMainCoach
              this.courseInfo[courseIndex].main_coach_name = mainCoach.name
            }

            // 更新教务
            const education = this.educationList.find(e => e.person_id === this.selectedEducation)
            if (education) {
              this.courseInfo[courseIndex].education_id = this.selectedEducation
              this.courseInfo[courseIndex].education_name = education.name
            }

            // 更新助教
            const assistantNames = this.selectedAssistants.map(personId => {
              const assistant = this.assistantList.find(a => a.person_id === personId)
              return assistant ? assistant.name : ''
            }).filter(name => name).join(', ')

            this.courseInfo[courseIndex].assistant_ids = this.selectedAssistants.join(',')
            this.courseInfo[courseIndex].assistant_names = assistantNames || '无'
          }

          uni.showToast({
            title: '修改成功（本地）',
            icon: 'success',
          })
        }

      } catch (error) {
        console.error('confirmCourseEdit - 修改教练配置失败:', error)
        uni.showToast({
          title: '修改失败，请重试',
          icon: 'none',
        })
      } finally {
        uni.hideLoading()
        this.$refs.courseEditPopup.close()
      }
    },

    // 关闭课程编辑弹窗
    closeCourseEdit() {
      this.$refs.courseEditPopup.close()
    },

    // 查看课程详情
    viewCourseDetail(course) {
      // 检查课程信息ID是否存在
      if (!course || !course.id) {
        console.error('课程信息ID缺失，无法跳转到详情页面')
        uni.showToast({
          title: '课程信息不完整',
          icon: 'none',
        })
        return
      }

      console.log('跳转到课程详情页面，课程ID:', course.id)

      // 跳转到课程详情页面，带上课程ID和学生资源ID
      this.$navigateTo({
        url: `/pages/market/course/course_detail?id=${course.id}&resource_id=${this.clientInfo.resource_id}&student_name=${encodeURIComponent(this.safeGet(this.clientInfo, 'customerResource.name', '未知学生'))}`,
      })
    },


    // 安全访问对象属性的方法，优化性能
    safeGet(obj, path, defaultValue = '') {
      if (!obj) return defaultValue

      // 使用缓存来提高性能
      if (!this._pathCache) this._pathCache = {}

      // 使用路径作为缓存键
      const cacheKey = path

      // 如果这个路径没有缓存过分割结果，则计算并缓存
      if (!this._pathCache[cacheKey]) {
        this._pathCache[cacheKey] = path.split('.')
      }

      const keys = this._pathCache[cacheKey]
      let result = obj

      // 使用for循环而不是for...of，更高效
      for (let i = 0; i < keys.length; i++) {
        const key = keys[i]
        if (result === null || result === undefined || !result.hasOwnProperty(key)) {
          return defaultValue
        }
        result = result[key]
      }

      return result || defaultValue
    },

    // 体测记录相关方法
    // 获取体测记录列表
    async getFitnessRecords() {
      try {
        if (!this.clientInfo.resource_id) {
          console.error('getFitnessRecords - resource_id为空，无法获取体测记录')
          this.fitnessRecords = []
          return false
        }

        const params = {
          resource_id: this.clientInfo.resource_id,
        }

        console.log('getFitnessRecords - 请求参数:', params)

        // 暂时使用模拟数据，实际开发中应该调用真实API
        this.fitnessRecords = this.getMockFitnessRecords()
        console.log('getFitnessRecords - 体测记录获取成功:', this.fitnessRecords)
        return true

        // 真实API调用代码（注释掉）
        // const res = await apiRoute.getFitnessRecords(params)
        // if (res.code === 1) {
        //   this.fitnessRecords = res.data || []
        //   console.log('getFitnessRecords - 体测记录获取成功:', this.fitnessRecords)
        //   return true
        // } else {
        //   console.warn('API返回错误:', res.msg)
        //   this.fitnessRecords = []
        //   return false
        // }
      } catch (error) {
        console.error('getFitnessRecords - 获取体测记录异常:', error)
        this.fitnessRecords = []
        return false
      }
    },

    // 获取模拟体测记录数据
    getMockFitnessRecords() {
      return [
        {
          id: 1,
          test_date: '2024-01-15',
          height: '165',
          weight: '55',
          pdf_files: [
            {
              id: 1,
              name: '体测报告_2024-01-15.pdf',
              size: 1024000,
              url: '/static/mock/fitness_report_1.pdf'
            }
          ]
        },
        {
          id: 2,
          test_date: '2024-03-10',
          height: '166',
          weight: '53',
          pdf_files: [
            {
              id: 2,
              name: '体测报告_2024-03-10.pdf',
              size: 1200000,
              url: '/static/mock/fitness_report_2.pdf'
            },
            {
              id: 3,
              name: '营养建议_2024-03-10.pdf',
              size: 800000,
              url: '/static/mock/nutrition_advice_1.pdf'
            }
          ]
        }
      ]
    },

    // 打开新增体测记录弹窗
    openAddFitnessRecord() {
      this.isEditingFitnessRecord = false
      this.currentFitnessRecord = {
        id: null,
        test_date: this.getCurrentDate(),
        height: '',
        weight: '',
        pdf_files: []
      }
      this.$refs.fitnessRecordPopup.open()
    },

    // 打开编辑体测记录弹窗
    openEditFitnessRecord(record) {
      this.isEditingFitnessRecord = true
      this.currentFitnessRecord = {
        id: record.id,
        test_date: record.test_date,
        height: record.height,
        weight: record.weight,
        pdf_files: [...(record.pdf_files || [])]
      }
      this.$refs.fitnessRecordPopup.open()
    },

    // 关闭体测记录编辑弹窗
    closeFitnessRecordEdit() {
      this.$refs.fitnessRecordPopup.close()
      this.currentFitnessRecord = {
        id: null,
        test_date: '',
        height: '',
        weight: '',
        pdf_files: []
      }
    },

    // 确认体测记录编辑
    async confirmFitnessRecordEdit() {
      try {
        // 表单验证
        if (!this.currentFitnessRecord.test_date) {
          uni.showToast({
            title: '请选择测试日期',
            icon: 'none'
          })
          return
        }

        if (!this.currentFitnessRecord.height) {
          uni.showToast({
            title: '请输入身高',
            icon: 'none'
          })
          return
        }

        if (!this.currentFitnessRecord.weight) {
          uni.showToast({
            title: '请输入体重',
            icon: 'none'
          })
          return
        }

        uni.showLoading({
          title: '保存中...',
          mask: true
        })

        const params = {
          resource_id: this.clientInfo.resource_id,
          test_date: this.currentFitnessRecord.test_date,
          height: this.currentFitnessRecord.height,
          weight: this.currentFitnessRecord.weight,
          pdf_files: this.currentFitnessRecord.pdf_files
        }

        if (this.isEditingFitnessRecord) {
          params.id = this.currentFitnessRecord.id
        }

        console.log('保存体测记录参数:', params)

        // 暂时使用本地更新，实际开发中应该调用真实API
        if (this.isEditingFitnessRecord) {
          const index = this.fitnessRecords.findIndex(r => r.id === this.currentFitnessRecord.id)
          if (index > -1) {
            this.fitnessRecords[index] = { ...this.currentFitnessRecord }
          }
        } else {
          const newRecord = {
            ...this.currentFitnessRecord,
            id: Date.now() // 生成临时ID
          }
          this.fitnessRecords.unshift(newRecord)
        }

        uni.showToast({
          title: '保存成功',
          icon: 'success'
        })

        // 真实API调用代码（注释掉）
        // const res = await apiRoute.saveFitnessRecord(params)
        // if (res.code === 1) {
        //   uni.showToast({
        //     title: '保存成功',
        //     icon: 'success'
        //   })
        //   await this.getFitnessRecords()
        // } else {
        //   uni.showToast({
        //     title: res.msg || '保存失败',
        //     icon: 'none'
        //   })
        //   return
        // }

      } catch (error) {
        console.error('保存体测记录失败:', error)
        uni.showToast({
          title: '保存失败，请重试',
          icon: 'none'
        })
      } finally {
        uni.hideLoading()
        this.closeFitnessRecordEdit()
      }
    },

    // 选择PDF文件
    selectPDFFiles() {
      uni.chooseFile({
        count: 5,
        type: 'file',
        extension: ['pdf'],
        success: (res) => {
          console.log('选择的文件:', res.tempFiles)
          
          res.tempFiles.forEach(file => {
            if (file.type === 'application/pdf') {
              const pdfFile = {
                id: Date.now() + Math.random(),
                name: file.name,
                size: file.size,
                url: file.path
              }
              this.currentFitnessRecord.pdf_files.push(pdfFile)
            }
          })
        },
        fail: (err) => {
          console.error('选择文件失败:', err)
          uni.showToast({
            title: '选择文件失败',
            icon: 'none'
          })
        }
      })
    },

    // 移除PDF文件
    removePDFFile(index) {
      this.currentFitnessRecord.pdf_files.splice(index, 1)
    },

    // 预览PDF文件
    previewPDF(pdf) {
      console.log('预览PDF:', pdf)
      
      // 使用uni.openDocument预览PDF
      uni.openDocument({
        filePath: pdf.url,
        fileType: 'pdf',
        showMenu: true,
        success: (res) => {
          console.log('PDF预览成功:', res)
        },
        fail: (err) => {
          console.error('PDF预览失败:', err)
          uni.showToast({
            title: '预览失败',
            icon: 'none'
          })
        }
      })
    },

    // 格式化文件大小
    formatFileSize(bytes) {
      if (bytes === 0) return '0 B'
      const k = 1024
      const sizes = ['B', 'KB', 'MB', 'GB']
      const i = Math.floor(Math.log(bytes) / Math.log(k))
      return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
    },

    // 获取当前日期
    getCurrentDate() {
      const now = new Date()
      const year = now.getFullYear()
      const month = String(now.getMonth() + 1).padStart(2, '0')
      const day = String(now.getDate()).padStart(2, '0')
      return `${year}-${month}-${day}`
    },

    // 学生信息相关方法
    // 获取学生列表
    async getStudentList() {
      try {
        if (!this.clientInfo.resource_id) {
          console.error('getStudentList - resource_id为空，无法获取学生列表')
          // 如果没有resource_id，使用Mock数据用于调试
          console.log('getStudentList - 使用Mock数据替代')
          this.studentList = this.getMockStudentList()
          console.log('getStudentList - Mock学生列表:', this.studentList)
          return true
        }

        const params = {
          parent_resource_id: this.clientInfo.resource_id,
        }

        console.log('getStudentList - 请求参数:', params)
        console.log('getStudentList - 当前clientInfo:', this.clientInfo)

        // 调用真实API
        const res = await apiRoute.xs_getStudentList(params)
        console.log('getStudentList - API原始响应:', res)
        
        if (res.code === 1) {
          this.studentList = res.data || []
          console.log('getStudentList - 学生列表获取成功，数据数量:', this.studentList.length)
          console.log('getStudentList - 学生列表详细数据:', this.studentList)
          
          // 强制触发视图更新
          this.$forceUpdate()
          
          return true
        } else {
          console.warn('getStudentList - API返回业务错误，使用Mock数据:', res.msg)
          // API返回错误时，使用Mock数据
          this.studentList = this.getMockStudentList()
          console.log('getStudentList - 使用Mock学生列表:', this.studentList)
          return true
        }
      } catch (error) {
        console.error('getStudentList - 获取学生列表异常，使用Mock数据:', error)
        // 发生异常时，使用Mock数据
        this.studentList = this.getMockStudentList()
        console.log('getStudentList - 异常情况下使用Mock学生列表:', this.studentList)
        return true
      }
    },

    // 获取模拟学生列表数据
    getMockStudentList() {
      return [
        {
          id: 1,
          name: '张小明',
          gender: 1, // 1男
          age: 9.05, // 9岁5个月
          birthday: '2015-05-10',
          user_id: this.clientInfo?.resource_id || 0,
          campus_id: null,
          class_id: null,
          note: '活泼好动，喜欢运动',
          status: 1,
          emergency_contact: '张妈妈',
          contact_phone: '13800138001',
          member_label: '新学员',
          consultant_id: null,
          coach_id: null,
          trial_class_count: 2,
          actionsExpanded: false
        },
        {
          id: 2,
          name: '张小丽',
          gender: 2, // 2女
          age: 6.03, // 6岁3个月
          birthday: '2018-08-15',
          user_id: this.clientInfo?.resource_id || 0,
          campus_id: null,
          class_id: null,
          note: '比较内向，但很认真',
          status: 1,
          emergency_contact: '张妈妈',
          contact_phone: '13800138002',
          member_label: '优秀学员',
          consultant_id: null,
          coach_id: null,
          trial_class_count: 1,
          actionsExpanded: false
        }
      ]
    },

    // swiper切换事件
    onStudentSwiperChange(e) {
      this.currentStudentIndex = e.detail.current
    },

    // 格式化年龄显示
    formatAge(age) {
      if (!age) return '未知年龄'
      const years = Math.floor(age)
      const months = Math.round((age - years) * 12)
      if (months === 0) {
        return `${years}岁`
      }
      return `${years}岁${months}个月`
    },

    // 格式化性别显示
    formatGender(gender) {
      switch (gender) {
        case 1: return '男'
        case 2: return '女'
        default: return '未知'
      }
    },

    // 切换操作面板展开状态
    toggleActionPanel(index) {
      this.studentList[index].actionsExpanded = !this.studentList[index].actionsExpanded
    },

    // 处理操作按钮点击
    handleAction(action, student) {
      switch (action.key) {
        case 'edit_detail':
          this.openViewEditClues(student)
          break
        case 'course_arrangement':
          this.openViewEditClassLog(student)
          break
        case 'edit_record':
          this.openViewEditCluesLog(student)
          break
        case 'order_list':
          this.openViewOrder(student)
          break
        case 'service_list':
          this.openViewOrder(student) // 暂时复用订单列表
          break
        default:
          console.log('未知操作:', action.key)
      }
    },

    // 开始操作按钮排序
    startActionSort(actionIndex) {
      uni.showModal({
        title: '操作提示',
        content: '长按可以调整操作按钮的顺序，是否进入排序模式？',
        success: (res) => {
          if (res.confirm) {
            this.enterSortMode()
          }
        }
      })
    },

    // 进入排序模式
    enterSortMode() {
      // 这里可以实现更复杂的排序界面
      // 暂时提供简单的反转功能作为示例
      this.actionButtons.reverse()
      this.saveActionOrder()
      uni.showToast({
        title: '按钮顺序已调整',
        icon: 'success'
      })
    },

    // 保存操作按钮顺序
    saveActionOrder() {
      const order = this.actionButtons.map(btn => btn.key)
      uni.setStorageSync('action_buttons_order', order)
    },

    // 打开添加学生弹窗
    openAddStudentDialog() {
      this.isEditingStudent = false
      this.currentStudent = {
        id: null,
        name: '',
        gender: 0,
        age: 0.00,
        birthday: null,
        user_id: this.clientInfo?.resource_id || 0,
        campus_id: null,
        class_id: null,
        note: '',
        status: 1,
        emergency_contact: '',
        contact_phone: '',
        member_label: '',
        consultant_id: null,
        coach_id: null,
        trial_class_count: 2, // 新增学员默认赠送2节体验课
        actionsExpanded: false
      }
      this.$refs.studentEditPopup.open()
    },

    // 打开编辑学生弹窗
    openEditStudentDialog(student) {
      this.isEditingStudent = true
      this.currentStudent = {
        id: student.id,
        name: student.name,
        gender: student.gender,
        age: student.age,
        birthday: student.birthday,
        user_id: student.user_id,
        campus_id: student.campus_id,
        class_id: student.class_id,
        note: student.note,
        status: student.status,
        emergency_contact: student.emergency_contact,
        contact_phone: student.contact_phone,
        member_label: student.member_label,
        consultant_id: student.consultant_id,
        coach_id: student.coach_id,
        trial_class_count: student.trial_class_count,
        actionsExpanded: student.actionsExpanded
      }
      this.$refs.studentEditPopup.open()
    },

    // 关闭学生编辑弹窗
    closeStudentEdit() {
      this.$refs.studentEditPopup.close()
      this.currentStudent = {
        id: null,
        name: '',
        gender: 0,
        age: 0.00,
        birthday: null,
        user_id: this.clientInfo?.resource_id || 0,
        campus_id: null,
        class_id: null,
        note: '',
        status: 1,
        emergency_contact: '',
        contact_phone: '',
        member_label: '',
        consultant_id: null,
        coach_id: null,
        trial_class_count: 2,
        actionsExpanded: false
      }
    },

    // 性别选择器变化事件
    onGenderChange(e) {
      const selectedGender = this.genderOptions[e.detail.value]
      this.currentStudent.gender = selectedGender.value
    },

    // 出生日期选择器变化事件
    onBirthdayChange(e) {
      this.currentStudent.birthday = e.detail.value
      // 计算年龄（精确到月）
      if (this.currentStudent.birthday) {
        const today = new Date()
        const birthday = new Date(this.currentStudent.birthday)
        
        let years = today.getFullYear() - birthday.getFullYear()
        let months = today.getMonth() - birthday.getMonth()
        
        if (today.getDate() < birthday.getDate()) {
          months--
        }
        
        if (months < 0) {
          years--
          months += 12
        }
        
        // 转换为小数表示：例如3岁11个月 = 3.11
        const ageDecimal = years + (months / 100)
        this.currentStudent.age = ageDecimal > 0 ? parseFloat(ageDecimal.toFixed(2)) : 0
      }
    },

    // 学员状态选择器变化事件
    onStatusChange(e) {
      const statusOptions = [{label: '无效', value: 0}, {label: '有效', value: 1}]
      this.currentStudent.status = statusOptions[e.detail.value].value
    },

    // 确认学生信息编辑
    async confirmStudentEdit() {
      try {
        // 表单验证
        if (!this.currentStudent.name.trim()) {
          uni.showToast({
            title: '请输入学生姓名',
            icon: 'none'
          })
          return
        }

        if (this.currentStudent.gender === 0) {
          uni.showToast({
            title: '请选择性别',
            icon: 'none'
          })
          return
        }

        if (!this.currentStudent.birthday) {
          uni.showToast({
            title: '请选择出生日期',
            icon: 'none'
          })
          return
        }

        uni.showLoading({
          title: '保存中...',
          mask: true
        })

        // 根据school_student表结构构建参数
        const params = {
          name: this.currentStudent.name,
          gender: this.currentStudent.gender,
          age: this.currentStudent.age,
          birthday: this.currentStudent.birthday,
          user_id: this.clientInfo.resource_id, // 关联到当前客户资源ID
          campus_id: this.currentStudent.campus_id,
          class_id: this.currentStudent.class_id,
          note: this.currentStudent.note,
          status: this.currentStudent.status,
          emergency_contact: this.currentStudent.emergency_contact,
          contact_phone: this.currentStudent.contact_phone,
          member_label: this.currentStudent.member_label,
          consultant_id: this.currentStudent.consultant_id,
          coach_id: this.currentStudent.coach_id,
          trial_class_count: this.currentStudent.trial_class_count
        }

        if (this.isEditingStudent) {
          params.id = this.currentStudent.id
        }

        console.log('保存学生信息参数:', params)

        // 调用真实API
        const res = await apiRoute.xs_addStudent(params)
        if (res.code === 1) {
          uni.showToast({
            title: '保存成功',
            icon: 'success'
          })
          await this.getStudentList()
        } else {
          uni.showToast({
            title: res.msg || '保存失败',
            icon: 'none'
          })
          return
        }

      } catch (error) {
        console.error('保存学生信息失败:', error)
        uni.showToast({
          title: '保存失败，请重试',
          icon: 'none'
        })
      } finally {
        uni.hideLoading()
        this.closeStudentEdit()
      }
    },

    // 学生操作相关方法
    // 处理学生操作按钮点击
    handleStudentAction(action, student) {
      console.log('处理学生操作:', action, student)
      
      switch (action) {
        case 'course_info':
          this.handleCourseInfo(student)
          break
        case 'fitness_record':
          this.handleFitnessRecord(student)
          break
        case 'study_plan':
          this.handleStudyPlan(student)
          break
        case 'course_arrangement':
          this.handleCourseArrangement(student)
          break
        case 'order_list':
          this.handleOrderList(student)
          break
        case 'service_list':
          this.handleServiceList(student)
          break
        default:
          console.warn('未知的学生操作:', action)
      }
    },

    // 课程信息
    handleCourseInfo(student) {
      uni.showToast({
        title: `查看${student.name}的课程信息`,
        icon: 'none'
      })
      // TODO: 跳转到课程信息页面
    },

    // 体测记录  
    handleFitnessRecord(student) {
      uni.showToast({
        title: `查看${student.name}的体测记录`,
        icon: 'none'
      })
      // TODO: 跳转到体测记录页面
    },

    // 学习计划
    handleStudyPlan(student) {
      uni.showToast({
        title: `查看${student.name}的学习计划`,
        icon: 'none'
      })
      // TODO: 跳转到学习计划页面
    },

    // 课程安排
    handleCourseArrangement(student) {
      uni.showToast({
        title: `查看${student.name}的课程安排`,
        icon: 'none'
      })
      // TODO: 跳转到课程安排页面
    },

    // 订单列表
    handleOrderList(student) {
      uni.showToast({
        title: `查看${student.name}的订单列表`,
        icon: 'none'
      })
      // TODO: 跳转到订单列表页面
    },

    // 服务列表
    handleServiceList(student) {
      uni.showToast({
        title: `查看${student.name}的服务列表`,
        icon: 'none'
      })
      // TODO: 跳转到服务列表页面
    },

    // 切换学生操作面板展开状态
    toggleStudentActions(student) {
      student.actionsExpanded = !student.actionsExpanded
      // 保存展开状态到本地存储
      const expandedStates = this.studentList.reduce((acc, s) => {
        acc[s.id] = s.actionsExpanded
        return acc
      }, {})
      uni.setStorageSync('student_actions_expanded_states', expandedStates)
    },

    // 保存学生操作按钮排序
    saveStudentActionOrder(newOrder) {
      uni.setStorageSync('student_action_buttons_order', newOrder)
      console.log('学生操作按钮排序已保存:', newOrder)
    },

    // 联系方式处理方法
    makeCall() {
      const phoneNumber = this.safeGet(this.clientInfo, 'customerResource.phone_number', '')
      if (phoneNumber) {
        uni.makePhoneCall({
          phoneNumber: phoneNumber,
          success: () => {
            console.log('拨打电话成功')
          },
          fail: (err) => {
            console.error('拨打电话失败:', err)
            uni.showToast({
              title: '拨打电话失败',
              icon: 'none'
            })
          }
        })
      } else {
        uni.showToast({
          title: '客户电话号码为空',
          icon: 'none'
        })
      }
    },

    sendMessage() {
      uni.showToast({
        title: '发送消息功能待实现',
        icon: 'none'
      })
      // TODO: 实现发送消息功能
    },
  },
}
</script>

<style lang="less" scoped>
.assemble {
  width: 100%;
  height: 100vh;
  overflow: auto;
  background-color: #292929;
}

.main_box {
  background: #292929;
  min-height: 20vh;
}

// 操作按钮样式
.action-buttons {
  display: flex;
  align-items: center;

  .btn-item {
    width: 60rpx;
    height: 60rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 20rpx;

    .btn-icon {
      width: 40rpx;
      height: 40rpx;
    }
  }
}

//统计信息
.count_section {
  width: 100%;
  position: relative;

  .main {
    width: 100%;
    position: absolute;
    z-index: 2;
    padding: 0rpx 24rpx;
    display: flex;
    justify-content: center;

    .course_box {
      padding: 26rpx 22rpx 0 22rpx;
      width: 95%;
      height: 250rpx;
      border-radius: 20rpx;
      background-color: #fff;
    }
  }

  .bg_top {
    height: 180rpx;
    background-color: #29D3B4;
  }

  .bg_bottom {
    height: 80rpx;
    background-color: #292929;
  }
}

.course_box_top {
  width: 100%;
  height: 60%;
}

.course_box_centre {
  margin: auto;
  width: 95%;
  height: 4rpx;
  background: #F5F5F8;
}

.course_box_below {
  width: 100%;
  height: 40%;
  display: flex;
  justify-content: space-around;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 0 10rpx;
}

.course_box_top_top {
  display: flex;
  align-items: center;
  gap: 20rpx;

  .pic {
    width: 44rpx;
    height: 44rpx;
    border-radius: 50%;
  }

  .name {
    color: #333333;
    font-size: 28rpx;
  }
}

.course_box_top_below {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.course_box_top_below-left {
  display: flex;
  align-items: center;
  padding-top: 16rpx;
  font-size: 24rpx;
}

.drop-image-x {
  width: 20rpx;
  height: 20rpx;
}

.title-x {
  font-size: 28rpx;
  color: #333333;
  padding-left: 10rpx;
}

.course_box_top_below-right {
  padding-top: 16rpx;
  font-size: 24rpx;
  display: flex;
  align-items: center;
}

.drop-image-star {
  width: 40rpx;
  height: 40rpx;
}

.selected-text {
  color: #1CD188;
  display: flex;
  align-items: center;
  white-space: nowrap;
  font-size: 28rpx;
  padding: 0 6rpx;
}

.text {
  color: #333333;
  display: flex;
  align-items: center;
  white-space: nowrap;
  font-size: 28rpx;
  padding: 0 6rpx;
}

.basic-message {
  color: #fff;
  padding: 16rpx 60rpx;
  display: flex;
  justify-content: space-between;
}

.basic-message-div {
  width: 92%;
  margin: auto;
  background: #555555;
  border-radius: 16rpx;
  padding: 16rpx 0;
}

.basic-message-div-txt {
  display: flex;
  justify-content: space-between;
  color: #FFFFFF;
  padding: 14rpx 30rpx;
}

.bottom-label {
  width: 100%;
  height: 150rpx;
  background: #fff;
  position: fixed;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 30rpx;
}

// 自定义弹窗样式
.custom-popup-dialog {
  width: 650rpx;
  border-radius: 16rpx;
  background-color: #fff;
  overflow: hidden;
}

.dialog-header {
  padding: 30rpx;
  text-align: center;
  border-bottom: 1px solid #eee;
}

.dialog-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}

.dialog-content {
  padding: 30rpx;
}

.dialog-footer {
  display: flex;
  border-top: 1px solid #eee;
}

.dialog-btn {
  flex: 1;
  padding: 25rpx 0;
  text-align: center;
  font-size: 30rpx;
}

.cancel-btn {
  color: #666;
  border-right: 1px solid #eee;
}

.confirm-btn {
  color: #29D3B4;
  font-weight: bold;
}

// 备注文本框样式
.remark-textarea-container {
  width: 100%;
  position: relative;
  padding: 10rpx 0;
}

.remark-textarea {
  width: 100%;
  height: 240rpx;
  border: 1px solid #ddd;
  border-radius: 8rpx;
  padding: 20rpx;
  font-size: 28rpx;
  background-color: #f8f8f8;
  box-sizing: border-box;
}

.remark-count {
  position: absolute;
  bottom: 20rpx;
  right: 20rpx;
  font-size: 24rpx;
  color: #999;
}

// 备注按钮样式
.remark-btn {
  background-color: #29D3B4 !important;
  color: white !important;
  margin: 0 !important;
  padding: 0 20rpx !important;
  height: 60rpx !important;
  line-height: 60rpx !important;
  font-size: 24rpx !important;
  border-radius: 30rpx !important;
}

.follow-records-list {
  width: 92%;
  background: #434544;
  border-radius: 16rpx;
  margin: auto;
  padding: 16rpx;
  color: #fff;
  position: relative;
}

.same-community {
  width: 120rpx;
  background: #3d4a55;
  color: #1e62a9;
  position: absolute;
  top: 0;
  right: 0;
  padding: 8rpx 16rpx;
  text-align: center;
  border-radius: 40rpx 70rpx 70rpx 12rpx;
}

.coeducation {
  width: 120rpx;
  background: #3d4a55;
  color: #2e9380;
  position: absolute;
  top: 0;
  right: 0;
  padding: 8rpx 16rpx;
  text-align: center;
  border-radius: 40rpx 70rpx 70rpx 12rpx;
}

.same-community {
  width: 120rpx;
  background: #40504c;
  color: #1e62a9;
  position: absolute;
  top: 0;
  right: 0;
  padding: 8rpx 16rpx;
  text-align: center;
  border-radius: 40rpx 70rpx 70rpx 12rpx;
}

.search {
  width: 92%;
  margin: auto;
  display: flex;
  margin-top: 20rpx;
}

.selected {
  background: #294e48;
  border-radius: 16rpx;
  padding: 12rpx 8rpx;
  text-align: center;
  color: #29d3b4;
  margin-left: 5rpx;
}

.not-selected {
  margin-left: 5rpx;
  background: #ffffff;
  border: 4rpx #959595 solid;
  border-radius: 16rpx;
  padding: 12rpx 8rpx;
  text-align: center;
}

.call-record-item {
  width: 100%;
  background: #434544;
  border-radius: 16rpx;
  margin: auto;
  padding: 16rpx;
  color: #fff;
  position: relative;
}

.call-record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.call-name {
  font-size: 28rpx;
  font-weight: bold;
}

.call-time {
  font-size: 24rpx;
  color: #999;
}

.call-record-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.call-detail {
  display: flex;
  align-items: center;
}

.call-label {
  font-size: 24rpx;
  color: #999;
  margin-right: 10rpx;
}

.call-remark {
  margin-top: 10rpx;
}

.call-remark-content {
  font-size: 24rpx;
  color: #fff;
}

// 通话记录样式
.call-log {
  width: 100%;
  padding: 0 20rpx;
  box-sizing: border-box;
}

.call-record-wrapper {
  margin-bottom: 20rpx;
}

.call-record-item {
  width: 100%;
  background: #3D3D3D;
  border-radius: 16rpx;
  padding: 20rpx;
  color: #fff;
  box-sizing: border-box;
}

.call-record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15rpx;
  border-bottom: 1px solid #4A4A4A;
  padding-bottom: 10rpx;
}

.call-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #fff;
}

.call-time {
  font-size: 24rpx;
  color: #999;
}

.call-record-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10rpx;
}

.call-detail {
  display: flex;
  align-items: center;
}

.call-label {
  font-size: 24rpx;
  color: #999;
  margin-right: 10rpx;
}

.call-remark {
  margin-top: 10rpx;
  padding-top: 10rpx;
  border-top: 1px solid #4A4A4A;
}

.call-remark-content {
  font-size: 24rpx;
  color: #fff;
  word-break: break-all;
  display: inline-block;
  width: 90%;
  vertical-align: top;
}

// 课程信息样式
.course-info {
  padding: 20rpx;
}

.course-item {
  background: #3D3D3D;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
  color: #fff;
}

.course-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
  padding-bottom: 15rpx;
  border-bottom: 1px solid #4A4A4A;
}

.course-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #fff;
}

.course-status {
  padding: 8rpx 16rpx;
  border-radius: 12rpx;
  font-size: 24rpx;
  color: #fff;
}

.status-active {
  background: #29d3b4;
}

.status-expired {
  background: #ff6b6b;
}

.status-completed {
  background: #999;
}

.status-default {
  background: #666;
}

.course-progress {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}

.progress-bar {
  flex: 1;
  height: 12rpx;
  background: #555;
  border-radius: 6rpx;
  overflow: hidden;
  margin-right: 20rpx;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(to right, #29d3b4, #1ea08e);
  border-radius: 6rpx;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 26rpx;
  color: #29d3b4;
  min-width: 120rpx;
  text-align: right;
}

.course-details {
  margin-bottom: 20rpx;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15rpx;
  font-size: 28rpx;
}

.detail-label {
  color: #999;
}

.detail-value {
  color: #fff;
}

.course-actions {
  text-align: center;
  padding-top: 15rpx;
  border-top: 1px solid #4A4A4A;
}

.action-btn {
  color: #29d3b4;
  font-size: 28rpx;
}

.empty-course {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 0;
}

.empty-img {
  width: 200rpx;
  height: 200rpx;
  opacity: 0.5;
  margin-bottom: 30rpx;
}

.empty-text {
  color: #999;
  font-size: 28rpx;
}

// 教练配置编辑弹窗样式
.popup-container {
  width: 90vw;
  max-width: 600rpx;
  background: #fff;
  border-radius: 20rpx;
  box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30rpx 40rpx;
  background: #29d3b4;
  color: #fff;
}

.popup-title {
  font-size: 36rpx;
  font-weight: bold;
}

.popup-close {
  font-size: 40rpx;
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.popup-footer {
  display: flex;
  border-top: 1px solid #eee;
}

.popup-btn {
  flex: 1;
  padding: 30rpx;
  text-align: center;
  font-size: 32rpx;
  font-weight: bold;
}

.cancel-btn {
  color: #666;
  border-right: 1px solid #eee;
}

.confirm-btn {
  color: #29d3b4;
}

.popup-btn:active {
  background: #f5f5f5;
}

.course-edit-container {
  width: 100%;
  max-height: 60vh;
  overflow-y: auto;
  padding: 30rpx 20rpx;
  box-sizing: border-box;
}

.edit-section {
  margin-bottom: 40rpx;
  width: 100%;
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 20rpx;
  padding-bottom: 15rpx;
  border-bottom: 2px solid #29d3b4;
}

.coach-list {
  width: 100%;
  max-height: 300rpx;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 12rpx;
  background: #fff;
}

.coach-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 25rpx 30rpx;
  border-bottom: 1px solid #f0f0f0;
  background: #fff;
  transition: all 0.3s ease;
  min-height: 80rpx;
  box-sizing: border-box;
}

.coach-item:last-child {
  border-bottom: none;
}

.coach-item.selected {
  background: #f0f9ff;
  border-left: 4rpx solid #29d3b4;
}

.coach-item:active {
  background: #f5f5f5;
}

.coach-name {
  font-size: 30rpx;
  color: #333;
  flex: 1;
}

.coach-check {
  color: #29d3b4;
  font-size: 36rpx;
  font-weight: bold;
  width: 40rpx;
  text-align: center;
}

.empty-tip {
  color: #999;
  font-size: 28rpx;
  text-align: center;
  padding: 40rpx 0;
}

// 体测记录样式
.fitness-test-records {
  padding: 20rpx;
}

.add-record-btn-container {
  margin-bottom: 30rpx;
  display: flex;
  justify-content: center;
}

.add-record-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #29d3b4;
  color: #fff;
  border-radius: 30rpx;
  padding: 20rpx 40rpx;
  box-shadow: 0 4rpx 12rpx rgba(41, 211, 180, 0.3);
  
  .add-icon {
    font-size: 32rpx;
    margin-right: 10rpx;
    font-weight: bold;
  }
  
  .add-text {
    font-size: 28rpx;
  }
}

.add-record-btn:active {
  background: #1ea08e;
  transform: scale(0.98);
}

.fitness-record-list {
  width: 100%;
}

.empty-records {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 0;
  
  .empty-img {
    width: 200rpx;
    height: 200rpx;
    opacity: 0.5;
    margin-bottom: 30rpx;
  }
  
  .empty-text {
    color: #999;
    font-size: 28rpx;
  }
}

.fitness-record-item {
  background: #3D3D3D;
  border-radius: 16rpx;
  padding: 25rpx;
  margin-bottom: 20rpx;
  color: #fff;
  transition: background 0.3s ease;
}

.fitness-record-item:active {
  background: #454545;
}

.record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
  padding-bottom: 15rpx;
  border-bottom: 1px solid #4A4A4A;
}

.record-date {
  font-size: 30rpx;
  font-weight: bold;
  color: #29d3b4;
}

.record-actions {
  display: flex;
  align-items: center;
}

.edit-btn {
  background: rgba(41, 211, 180, 0.2);
  color: #29d3b4;
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  font-size: 24rpx;
  border: 1px solid #29d3b4;
}

.edit-btn:active {
  background: rgba(41, 211, 180, 0.3);
}

.record-content {
  width: 100%;
}

.record-data {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20rpx;
}

.data-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15rpx;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12rpx;
  min-width: 120rpx;
}

.data-label {
  font-size: 24rpx;
  color: #999;
  margin-bottom: 8rpx;
}

.data-value {
  font-size: 32rpx;
  font-weight: bold;
  color: #fff;
}

.pdf-attachments {
  margin-top: 20rpx;
  padding-top: 20rpx;
  border-top: 1px solid #4A4A4A;
}

.attachment-title {
  font-size: 26rpx;
  color: #999;
  margin-bottom: 15rpx;
}

.pdf-list {
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

.pdf-item {
  display: flex;
  align-items: center;
  padding: 15rpx;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12rpx;
  transition: background 0.3s ease;
}

.pdf-item:active {
  background: rgba(255, 255, 255, 0.1);
}

.pdf-icon {
  font-size: 28rpx;
  margin-right: 12rpx;
}

.pdf-name {
  flex: 1;
  font-size: 26rpx;
  color: #fff;
  margin-right: 10rpx;
}

.pdf-size {
  font-size: 22rpx;
  color: #999;
}

// 体测记录表单样式
.fitness-record-form {
  width: 100%;
  max-height: 60vh;
  overflow-y: auto;
  padding: 20rpx;
  box-sizing: border-box;
}

.form-section {
  width: 100%;
}

.form-item {
  margin-bottom: 30rpx;
}

.form-label {
  font-size: 30rpx;
  color: #333;
  margin-bottom: 15rpx;
  font-weight: bold;
}

.form-input {
  border: 2px solid #eee;
  border-radius: 12rpx;
  padding: 0 20rpx;
  background: #fff;
  transition: border-color 0.3s ease;
}

.form-input:focus-within {
  border-color: #29d3b4;
}

.form-input input {
  width: 100%;
  height: 80rpx;
  font-size: 28rpx;
  color: #333;
  border: none;
  outline: none;
  background: transparent;
}

.file-upload-area {
  width: 100%;
}

.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border: 2px dashed #ddd;
  border-radius: 12rpx;
  padding: 40rpx;
  margin-bottom: 20rpx;
  color: #666;
  transition: all 0.3s ease;
}

.upload-btn:active {
  background: #e9ecef;
  border-color: #29d3b4;
}

.upload-icon {
  font-size: 40rpx;
  margin-right: 15rpx;
}

.upload-text {
  font-size: 28rpx;
}

.selected-files {
  width: 100%;
}

.selected-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15rpx 20rpx;
  background: #f8f9fa;
  border-radius: 12rpx;
  margin-bottom: 10rpx;
  border: 1px solid #eee;
}

.file-info {
  display: flex;
  align-items: center;
  flex: 1;
}

.file-icon {
  font-size: 28rpx;
  margin-right: 12rpx;
  color: #666;
}

.file-name {
  flex: 1;
  font-size: 26rpx;
  color: #333;
  margin-right: 10rpx;
}

.file-size {
  font-size: 22rpx;
  color: #999;
}

.file-remove {
  width: 40rpx;
  height: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ff4757;
  color: #fff;
  border-radius: 50%;
  font-size: 24rpx;
  font-weight: bold;
  margin-left: 15rpx;
}

.file-remove:active {
  background: #ff3838;
}

// 学生信息相关样式
.student-info-section {
  margin-top: 20rpx;
}

.add-student-btn {
  display: flex;
  align-items: center;
  background: #29d3b4;
  color: #fff;
  border-radius: 20rpx;
  padding: 8rpx 16rpx;
  font-size: 24rpx;
  
  .add-icon {
    margin-right: 6rpx;
    font-weight: bold;
  }
}

.add-student-btn:active {
  background: #1ea08e;
  transform: scale(0.95);
}

.student-cards-container {
  width: 92%;
  margin: 20rpx auto;
}

.student-swiper {
  height: 400rpx;
  
  &::v-deep .uni-swiper-dots {
    bottom: 20rpx;
  }
  
  &::v-deep .uni-swiper-dot {
    width: 12rpx;
    height: 12rpx;
    background: rgba(255, 255, 255, 0.5);
  }
  
  &::v-deep .uni-swiper-dot-active {
    background: #29d3b4;
  }
}

.student-swiper-item {
  padding: 0 10rpx;
}

.student-card {
  background: #3D3D3D;
  border-radius: 20rpx;
  padding: 30rpx;
  min-height: 340rpx;
  display: flex;
  flex-direction: column;
  color: #fff;
}

.student-card-header {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
  padding-bottom: 15rpx;
  border-bottom: 1px solid #4A4A4A;
}

.student-avatar {
  width: 80rpx;
  height: 80rpx;
  margin-right: 20rpx;
  
  .avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
  }
  
  .avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #29d3b4;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32rpx;
    font-weight: bold;
    color: #fff;
  }
}

.student-basic-info {
  flex: 1;
  
  .student-name {
    font-size: 32rpx;
    font-weight: bold;
    color: #fff;
    margin-bottom: 8rpx;
  }
  
  .student-meta {
    display: flex;
    align-items: center;
    font-size: 24rpx;
    color: #999;
    
    .student-age {
      margin-right: 20rpx;
    }
  }
}

.student-actions {
  display: flex;
  align-items: center;
  
  .edit-btn {
    background: rgba(41, 211, 180, 0.2);
    color: #29d3b4;
    padding: 8rpx 16rpx;
    border-radius: 20rpx;
    font-size: 24rpx;
    border: 1px solid #29d3b4;
    
    .btn-text {
      font-size: 24rpx;
    }
  }
  
  .edit-btn:active {
    background: rgba(41, 211, 180, 0.3);
  }
}

.student-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.student-details {
  margin-bottom: 20rpx;
  
  .detail-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12rpx;
    font-size: 26rpx;
    
    .detail-label {
      color: #999;
      min-width: 120rpx;
    }
    
    .detail-value {
      color: #fff;
      flex: 1;
      text-align: right;
    }
  }
}

.student-stats {
  display: flex;
  justify-content: space-around;
  margin-top: auto;
  padding-top: 15rpx;
  border-top: 1px solid #4A4A4A;
  
  .stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    
    .stat-value {
      font-size: 28rpx;
      font-weight: bold;
      color: #29d3b4;
      margin-bottom: 5rpx;
    }
    
    .stat-label {
      font-size: 22rpx;
      color: #999;
    }
  }
}

.empty-students {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 340rpx;
  
  .empty-img {
    width: 160rpx;
    height: 160rpx;
    opacity: 0.5;
    margin-bottom: 20rpx;
  }
  
  .empty-text {
    color: #999;
    font-size: 28rpx;
    margin-bottom: 30rpx;
  }
  
  .empty-add-btn {
    background: #29d3b4;
    color: #fff;
    padding: 15rpx 30rpx;
    border-radius: 25rpx;
    font-size: 26rpx;
  }
  
  .empty-add-btn:active {
    background: #1ea08e;
    transform: scale(0.95);
  }
}

// 操作面板样式
.student-actions-panel {
  margin-top: 20rpx;
  border-top: 1px solid #4A4A4A;
  padding-top: 15rpx;
}

.actions-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10rpx 0;
  cursor: pointer;
  
  .toggle-text {
    font-size: 28rpx;
    color: #29d3b4;
    font-weight: bold;
  }
  
  .toggle-icon {
    font-size: 24rpx;
    color: #29d3b4;
    transition: transform 0.3s ease;
    
    &.expanded {
      transform: rotate(180deg);
    }
  }
}

.actions-toggle:active {
  background: rgba(41, 211, 180, 0.1);
  border-radius: 8rpx;
}

.actions-content {
  margin-top: 15rpx;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 200rpx;
  }
}

.actions-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 15rpx;
}

.action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(41, 211, 180, 0.3);
  border-radius: 12rpx;
  padding: 20rpx 15rpx;
  min-width: 120rpx;
  flex: 1;
  transition: all 0.3s ease;
  
  .action-icon {
    font-size: 28rpx;
    margin-bottom: 8rpx;
  }
  
  .action-text {
    font-size: 22rpx;
    color: #fff;
    text-align: center;
  }
}

.action-item:active {
  background: rgba(41, 211, 180, 0.2);
  border-color: #29d3b4;
  transform: scale(0.95);
  
  .action-text {
    color: #29d3b4;
  }
}

// 学生信息编辑弹窗样式
.student-edit-popup {
  width: 95vw;
  max-width: 700rpx;
  height: 85vh;
  max-height: 1400rpx;
  display: flex;
  flex-direction: column;
}

.student-form-container {
  flex: 1;
  padding: 20rpx;
  box-sizing: border-box;
  overflow-y: auto;
  min-height: 0;
}

.form-group {
  margin-bottom: 40rpx;
  
  .form-group-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 25rpx;
    padding-bottom: 10rpx;
    border-bottom: 2px solid #29d3b4;
    position: relative;
    
    &::after {
      content: '';
      position: absolute;
      bottom: -2rpx;
      left: 0;
      width: 60rpx;
      height: 2rpx;
      background: #29d3b4;
    }
  }
}

.form-item {
  margin-bottom: 25rpx;
  
  .form-label {
    font-size: 28rpx;
    color: #333;
    margin-bottom: 12rpx;
    font-weight: 500;
    
    &.required {
      position: relative;
      
      &::before {
        content: '*';
        color: #ff4757;
        margin-right: 4rpx;
        font-weight: bold;
      }
    }
  }
  
  .form-input {
    border: 2px solid #eee;
    border-radius: 12rpx;
    padding: 0 20rpx;
    background: #fff;
    transition: border-color 0.3s ease;
    
    &:focus-within {
      border-color: #29d3b4;
    }
    
    input {
      width: 100%;
      height: 80rpx;
      font-size: 28rpx;
      color: #333;
      border: none;
      outline: none;
      background: transparent;
      
      &::placeholder {
        color: #999;
      }
    }
    
    .picker-display {
      height: 80rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 28rpx;
      color: #333;
      
      .picker-arrow {
        color: #999;
        font-size: 32rpx;
        font-weight: bold;
        transform: rotate(90deg);
      }
    }
  }
  
  .form-textarea {
    border: 2px solid #eee;
    border-radius: 12rpx;
    padding: 20rpx;
    background: #fff;
    transition: border-color 0.3s ease;
    
    &:focus-within {
      border-color: #29d3b4;
    }
    
    textarea {
      width: 100%;
      height: 120rpx;
      font-size: 28rpx;
      color: #333;
      border: none;
      outline: none;
      background: transparent;
      resize: none;
      
      &::placeholder {
        color: #999;
      }
    }
  }
}

// 学生操作面板样式
.student-actions-panel {
  margin-top: 15rpx;
  padding: 20rpx;
  background: #f8f9fa;
  border-radius: 12rpx;
  border: 2px solid #e9ecef;
  transition: all 0.3s ease;
  
  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15rpx;
    
    .panel-title {
      font-size: 26rpx;
      color: #495057;
      font-weight: 600;
    }
    
    .collapse-icon {
      width: 30rpx;
      height: 30rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      background: #29d3b4;
      color: #fff;
      font-size: 20rpx;
      font-weight: bold;
      transition: transform 0.3s ease;
      
      &.expanded {
        transform: rotate(180deg);
      }
    }
  }
  
  .actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12rpx;
    margin-top: 15rpx;
    
    .action-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 15rpx 8rpx;
      background: #fff;
      border-radius: 8rpx;
      border: 1px solid #dee2e6;
      transition: all 0.3s ease;
      position: relative;
      
      &:active {
        transform: scale(0.95);
        background: #e3f2fd;
      }
      
      .action-icon {
        font-size: 32rpx;
        margin-bottom: 5rpx;
        display: block;
        line-height: 1;
      }
      
      .action-text {
        font-size: 22rpx;
        color: #495057;
        text-align: center;
        line-height: 1.2;
        font-weight: 500;
      }
      
      &:hover {
        background: #f8f9fa;
        border-color: #29d3b4;
        
        .action-text {
          color: #29d3b4;
        }
      }
    }
  }
  
  &.collapsed {
    .actions-grid {
      display: none;
    }
  }
}

// 整合后的基本信息卡片样式
.basic-info-card {
  background: #fff;
  border-radius: 15rpx;
  margin: 20rpx;
  padding: 25rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  
  .basic-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 25rpx;
    padding-bottom: 15rpx;
    border-bottom: 2px solid #f1f3f4;
    
    .info-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
      
      .title-accent {
        color: #29d3b4;
        margin-left: 10rpx;
      }
    }
    
    .info-status {
      padding: 6rpx 15rpx;
      border-radius: 20rpx;
      font-size: 24rpx;
      color: #fff;
      background: #28a745;
    }
  }
  
  .basic-info-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20rpx;
    
    .info-item {
      display: flex;
      flex-direction: column;
      
      .info-label {
        font-size: 24rpx;
        color: #6c757d;
        margin-bottom: 5rpx;
      }
      
      .info-value {
        font-size: 28rpx;
        color: #333;
        font-weight: 500;
        
        &.empty {
          color: #adb5bd;
          font-style: italic;
        }
      }
    }
  }
}

// 整合后的学生卡片容器样式
.integrated-cards-container {
  margin: 20rpx;
  min-height: 670rpx;
  display: block;
  
  .student-swiper {
    height: 650rpx !important;
    min-height: 650rpx;
    
    // 强制设置swiper内部组件的高度
    ::v-deep .uni-swiper-wrapper {
      height: 650rpx !important;
    }
    
    ::v-deep .uni-swiper-slides {
      height: 650rpx !important;
    }
    
    ::v-deep .uni-swiper-slide {
      height: 650rpx !important;
    }
  }
  
  .student-swiper-item {
    height: 620rpx !important;
    min-height: 620rpx;
    display: flex;
    flex-direction: column;
  }
}

// 整合的学生卡片样式
.integrated-student-card {
  background: #fff;
  border-radius: 15rpx;
  overflow: hidden;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  min-height: 600rpx;
  height: auto;
  display: flex;
  flex-direction: column;
  
  // 客户基本信息区域
  .basic-info-section {
    padding: 25rpx;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    
    .section-header {
      display: flex;
      align-items: center;
      margin-bottom: 25rpx;
      
      .customer-avatar {
        width: 60rpx;
        height: 60rpx;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.2);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 28rpx;
        font-weight: bold;
        margin-right: 20rpx;
      }
      
      .customer-info {
        flex: 1;
        
        .customer-name {
          font-size: 32rpx;
          font-weight: bold;
          margin-bottom: 8rpx;
        }
        
        .customer-meta {
          font-size: 24rpx;
          opacity: 0.9;
        }
      }
      
      .contact-actions {
        display: flex;
        gap: 15rpx;
        
        .contact-btn {
          width: 60rpx;
          height: 60rpx;
          border-radius: 50%;
          background: rgba(255, 255, 255, 0.2);
          display: flex;
          align-items: center;
          justify-content: center;
          transition: all 0.3s ease;
          
          &:active {
            transform: scale(0.9);
            background: rgba(255, 255, 255, 0.3);
          }
          
          .contact-icon {
            font-size: 24rpx;
          }
        }
      }
    }
    
    .basic-info-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 20rpx;
      
      .basic-info-item {
        .info-label {
          font-size: 24rpx;
          opacity: 0.8;
          margin-bottom: 5rpx;
        }
        
        .info-value {
          font-size: 26rpx;
          font-weight: 500;
        }
      }
    }
  }
  
  .divider-line {
    height: 2rpx;
    background: #f0f0f0;
    margin: 0 25rpx;
  }
  
  // 学生信息区域
  .student-info-section {
    padding: 25rpx;
    flex: 1;
    min-height: 300rpx;
    
    .student-header {
      display: flex;
      align-items: center;
      margin-bottom: 25rpx;
      
      .student-avatar {
        width: 80rpx;
        height: 80rpx;
        border-radius: 50%;
        background: linear-gradient(135deg, #29d3b4 0%, #26c6da 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 32rpx;
        font-weight: bold;
        margin-right: 20rpx;
      }
      
      .student-basic-info {
        flex: 1;
        
        .student-name {
          font-size: 30rpx;
          font-weight: bold;
          color: #333;
          margin-bottom: 8rpx;
        }
        
        .student-meta {
          font-size: 24rpx;
          color: #666;
          
          .student-age, .student-gender {
            margin-right: 20rpx;
          }
        }
      }
      
      .student-edit-btn {
        padding: 8rpx 20rpx;
        border-radius: 20rpx;
        border: 2px solid #29d3b4;
        color: #29d3b4;
        font-size: 24rpx;
        transition: all 0.3s ease;
        
        &:active {
          background: #29d3b4;
          color: #fff;
        }
      }
    }
    
    .student-details-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 15rpx;
      
      .detail-item {
        .detail-label {
          font-size: 24rpx;
          color: #666;
          margin-bottom: 5rpx;
        }
        
        .detail-value {
          font-size: 26rpx;
          color: #333;
          font-weight: 500;
        }
      }
    }
  }
  
  .actions-divider {
    height: 1rpx;
    background: #f0f0f0;
    margin: 0 25rpx;
  }
  
  // 学生操作面板
  .student-actions-panel {
    padding: 20rpx 25rpx;
    
    .actions-toggle {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 10rpx 0;
      
      .toggle-icon {
        font-size: 20rpx;
        color: #666;
        transition: transform 0.3s ease;
        
        &.expanded {
          transform: rotate(180deg);
        }
      }
    }
    
    .actions-content {
      margin-top: 15rpx;
      
      .actions-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 15rpx;
        
        .action-item {
          padding: 20rpx 10rpx;
          border-radius: 12rpx;
          background: #f8f9fa;
          border: 2px solid #e9ecef;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          transition: all 0.3s ease;
          
          &:active {
            transform: scale(0.95);
            background: #e9ecef;
            border-color: #29d3b4;
          }
          
          .action-icon {
            font-size: 28rpx;
            margin-bottom: 8rpx;
          }
          
          .action-text {
            font-size: 22rpx;
            color: #495057;
            text-align: center;
            font-weight: 500;
          }
        }
      }
    }
  }
}
</style>