智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1784 lines
56 KiB

<!--客户详情 - 重构版本-->
<template>
<view class="assemble">
<view class="main_box">
<view style="height: 20rpx;background: #29D3B4;"></view>
<!-- 客户信息卡片 - 直接显示不包装在白色卡片中 -->
<ClientInfoCard
:client-info="clientInfo"
:actions="sortedActions"
@call="handleMakeCall"
@action="handleClientAction"
/>
<!-- 标签切换器 -->
<view class="tab-switcher-container">
<TabSwitcher
:tabs="tabs"
:active-tab-id="switch_tags_type"
@tab-change="handleTabChange"
/>
</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" v-if="studentList.length > 0">
<swiper
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: 450rpx;"
@change="onStudentSwiperChange">
<swiper-item v-for="(student, index) in studentList" :key="student.id" class="student-swiper-item">
<StudentInfoCard
:student="student"
:actions="studentActions"
:show-details="true"
@toggle-actions="toggleStudentActions"
@action="handleStudentAction"
/>
</swiper-item>
</swiper>
</view>
<!-- 空状态 -->
<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 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="student-context-header" v-if="currentStudent">
<text class="context-title">当前学生: {{ currentStudent.name }}</text>
</view>
<view v-if="listCallUp.length === 0" class="empty-records">
<image src="/static/images/empty.png" mode="aspectFit" class="empty-img"></image>
<text class="empty-text">暂无通话记录</text>
</view>
<CallRecordCard
v-for="record in listCallUp"
:key="record.id"
:record="record"
@remark="openAddRemark"
/>
<view style="height: 200rpx;"></view>
</view>
<!--体测记录 - 与当前学生关联-->
<view class="fitness-test-records" v-if="switch_tags_type == 4">
<view class="student-context-header" v-if="currentStudent">
<text class="context-title">当前学生: {{ currentStudent.name }}</text>
</view>
<!-- 新增按钮 -->
<view class="add-record-btn-container" v-if="currentStudent">
<view class="add-record-btn" @click="openAddFitnessRecord">
<view class="add-icon">+</view>
<view class="add-text">为{{ currentStudent.name }}新增体测记录</view>
</view>
</view>
<view v-if="currentStudentFitnessRecords.length === 0" class="empty-records">
<image src="/static/images/empty.png" mode="aspectFit" class="empty-img"></image>
<text class="empty-text">该学生暂无体测记录</text>
</view>
<!-- 使用FitnessRecordCard组件 -->
<FitnessRecordCard
v-for="record in currentStudentFitnessRecords"
:key="record.id"
:record="record"
@edit="openEditFitnessRecord"
/>
</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>
<!-- 体测记录编辑弹窗 -->
<FitnessRecordPopup
ref="fitnessRecordPopup"
:resource-id="clientInfo.resource_id"
@confirm="handleFitnessRecordConfirm"
@close="handleFitnessRecordClose"
/>
<!-- 教练配置编辑弹窗 -->
<CourseEditPopup
ref="courseEditPopup"
:coachList="coachList"
:educationList="educationList"
:assistantList="assistantList"
:currentCourse="currentCourse"
@confirm="handleCourseEditConfirm"
@close="handleCourseEditClose"
/>
<!-- 学生信息编辑弹窗 -->
<StudentEditPopup
ref="studentEditPopup"
:resource-id="clientInfo.resource_id"
@confirm="handleStudentEditConfirm"
@close="handleStudentEditClose"
/>
</view>
</template>
<script>
import apiRoute from '@/api/apiRoute.js'
import marketApi from '@/api/market.js'
// 导入新创建的组件
import ClientInfoCard from '@/components/client-info-card/client-info-card.vue'
import StudentInfoCard from '@/components/student-info-card/student-info-card.vue'
import TabSwitcher from '@/components/tab-switcher/tab-switcher.vue'
import FitnessRecordCard from '@/components/fitness-record-card/fitness-record-card.vue'
import CallRecordCard from '@/components/call-record-card/call-record-card.vue'
import CourseEditPopup from '@/components/course-edit-popup/course-edit-popup.vue'
import StudentEditPopup from '@/components/student-edit-popup/student-edit-popup.vue'
import FitnessRecordPopup from '@/components/fitness-record-popup/fitness-record-popup.vue'
export default {
components: {
ClientInfoCard,
StudentInfoCard,
TabSwitcher,
FitnessRecordCard,
CallRecordCard,
CourseEditPopup,
StudentEditPopup,
FitnessRecordPopup
},
data() {
return {
switch_tags_type: 1,
select_type: 1,
// 标签配置
tabs: [
{ id: 1, name: '基本资料' },
{ id: 2, name: '课程信息' },
{ id: 3, name: '通话记录' },
{ id: 4, name: '体测记录' },
{ id: 5, name: '学习计划' }
],
// 学生操作按钮配置 - 与StudentInfoCard组件默认actions匹配
studentActions: [
{ key: 'edit', text: '编辑学生' },
{ key: 'order', text: '查看订单' },
{ key: 'course', text: '课程安排' },
{ key: 'fitness', text: '体测记录' }
],
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: [], // 助教列表
// 体测记录相关
fitnessRecords: [], // 体测记录列表
// 学生信息相关 (基于school_student表结构)
studentList: [], // 学生列表
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: '🔧' }
], // 默认操作按钮
}
},
computed: {
// 判断是否有课程信息
hasCourseInfo() {
return this.courseInfo && Array.isArray(this.courseInfo) && this.courseInfo.length > 0
},
// 获取当前选中的学生
currentStudent() {
if (this.studentList.length > 0 && this.currentStudentIndex >= 0 && this.currentStudentIndex < this.studentList.length) {
return this.studentList[this.currentStudentIndex]
}
return null
},
// 获取当前学生的体测记录
currentStudentFitnessRecords() {
if (!this.currentStudent) return []
// 这里应该根据学生ID过滤体测记录
// 目前使用所有记录,实际项目中应该根据 student_id 过滤
return this.fitnessRecords.filter(record => record.student_id === this.currentStudent.id)
},
// 获取排序后的操作按钮
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
}
},
//跳转页面-订单列表(支持学生参数)
openViewOrder(student = null) {
// 检查必要参数是否存在
const resource_id = this.$util.safeGet(this.clientInfo, 'resource_id')
if (!resource_id) {
console.error('openViewOrder - resource_id为空,无法跳转')
uni.showToast({
title: '缺少必要参数',
icon: 'none',
})
return
}
let resource_name = this.$util.safeGet(this.clientInfo, 'customerResource.name', '') //客户资源id姓名
let staff_id = this.$util.safeGet(this.userInfo, 'id', '') //员工id
let staff_id_name = this.$util.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.$util.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() {
const phoneNumber = this.$util.safeGet(this.clientInfo, 'customerResource.phone_number', '')
this.$util.makePhoneCall(phoneNumber)
},
// 发送消息按钮点击
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}`,
})
},
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) {
console.log('打开教练配置编辑弹窗,课程信息:', course)
this.currentCourse = course
console.log('教练配置数据检查:', {
coachList: this.coachList,
educationList: this.educationList,
assistantList: this.assistantList,
coachListLength: this.coachList.length,
educationListLength: this.educationList.length,
assistantListLength: this.assistantList.length,
})
// 如果没有教练数据,先获取
if (!this.coachList.length && !this.educationList.length && !this.assistantList.length) {
console.log('教练数据为空,先获取教练列表')
await this.getPersonnelList()
}
// 打开弹窗并传递课程数据
this.$refs.courseEditPopup.open({
main_coach_id: course.main_coach_id,
education_id: course.education_id,
assistant_ids: course.assistant_ids
})
},
// 处理教练配置确认事件
async handleCourseEditConfirm(result) {
console.log('处理教练配置确认事件:', result)
try {
uni.showLoading({
title: '保存中...',
mask: true,
})
const params = {
student_course_id: this.currentCourse.id,
main_coach_id: result.main_coach_id,
education_id: result.education_id,
assistant_ids: result.assistant_ids,
}
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 === result.main_coach_id)
if (mainCoach) {
this.courseInfo[courseIndex].main_coach_id = result.main_coach_id
this.courseInfo[courseIndex].main_coach_name = mainCoach.name
}
// 更新教务
const education = this.educationList.find(e => e.person_id === result.education_id)
if (education) {
this.courseInfo[courseIndex].education_id = result.education_id
this.courseInfo[courseIndex].education_name = education.name
}
// 更新助教
const assistantIds = result.assistant_ids ? result.assistant_ids.split(',').map(Number) : []
const assistantNames = assistantIds.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 = result.assistant_ids
this.courseInfo[courseIndex].assistant_names = assistantNames || '无'
}
uni.showToast({
title: '修改成功(本地)',
icon: 'success',
})
}
} catch (error) {
console.error('handleCourseEditConfirm - 修改教练配置失败:', error)
uni.showToast({
title: '修改失败,请重试',
icon: 'none',
})
} finally {
uni.hideLoading()
}
},
// 处理教练配置关闭事件
handleCourseEditClose() {
console.log('教练配置弹窗已关闭')
this.currentCourse = null
},
// 查看课程详情
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.$util.safeGet(this.clientInfo, 'customerResource.name', '未知学生'))}`,
})
},
// 组件事件处理方法
// 标签切换事件处理
async handleTabChange({ tabId }) {
// 如果点击课程信息标签但没有课程数据,则不允许切换
if (tabId === 2 && !this.hasCourseInfo) {
uni.showToast({
title: '暂无课程信息',
icon: 'none',
})
return
}
this.switch_tags_type = tabId
// 当切换到课程信息时,刷新课程数据
if (tabId === 2) {
await this.getCourseInfo()
}
// 当切换到通话记录时,刷新通话记录数据
if (tabId === 3) {
await this.getListCallUp()
console.log('刷新通话记录数据,当前记录数:', this.listCallUp.length)
}
// 当切换到体测记录时,刷新体测记录数据
if (tabId === 4) {
await this.getFitnessRecords()
console.log('刷新体测记录数据,当前记录数:', this.fitnessRecords.length)
}
},
// 学生操作切换
toggleStudentActions(student) {
const index = this.studentList.findIndex(s => s.id === student.id)
if (index !== -1) {
this.$set(this.studentList[index], 'actionsExpanded', !student.actionsExpanded)
}
},
// 学生操作处理
handleStudentAction({ action, student }) {
console.log('学生操作:', action, student)
// 设置当前学生
this.setCurrentStudent(student)
switch (action.key) {
case 'course_info':
// 切换到课程信息标签
this.switch_tags_type = 2
break
case 'fitness_record':
// 切换到体测记录标签
this.switch_tags_type = 4
break
case 'study_plan':
// 切换到学习计划标签
this.switch_tags_type = 5
break
case 'course_arrangement':
// 跳转到课程安排页面
this.openViewEditClassLog(student)
break
case 'order_list':
// 跳转到订单列表页面
this.openViewOrder(student)
break
case 'service_list':
// 跳转到服务列表页面
this.openViewServiceList(student)
break
}
},
// 设置当前学生
setCurrentStudent(student) {
const index = this.studentList.findIndex(s => s.id === student.id)
if (index !== -1) {
this.currentStudentIndex = index
}
},
// 跳转到服务列表页面
openViewServiceList(student = null) {
// 检查必要参数是否存在
const resource_id = this.$util.safeGet(this.clientInfo, 'resource_id')
if (!resource_id) {
console.error('openViewServiceList - resource_id为空,无法跳转')
uni.showToast({
title: '缺少必要参数',
icon: 'none',
})
return
}
let resource_name = this.$util.safeGet(this.clientInfo, 'customerResource.name', '') //客户资源id姓名
let staff_id = this.$util.safeGet(this.userInfo, 'id', '') //员工id
let staff_id_name = this.$util.safeGet(this.userInfo, 'name', '') //员工姓名
// 如果有学生信息,添加学生参数
let url = `/pages/market/clue/service_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,
})
},
// 学生操作相关方法
editStudent(student) {
this.$util.navigateToPage('/pages/student/edit', {
student_id: student.id
})
},
viewStudentOrders(student) {
this.$util.navigateToPage('/pages/market/clue/order_list', {
resource_id: this.clientInfo.resource_id,
student_id: student.id,
student_name: student.name
})
},
viewStudentCourse(student) {
this.$util.navigateToPage('/pages/market/clue/course_arrange', {
resource_id: this.clientInfo.resource_id,
student_id: student.id,
student_name: student.name
})
},
viewStudentFitness(student) {
this.$util.navigateToPage('/pages/fitness/records', {
student_id: student.id
})
},
// 学生切换事件处理
onStudentSwiperChange(e) {
this.currentStudentIndex = e.detail.current
console.log('切换到学生索引:', this.currentStudentIndex)
// 如果当前在体测记录或其他学生相关页面,刷新数据
if (this.switch_tags_type === 4) {
// 体测记录页面,可以根据新的学生刷新数据
this.getFitnessRecordsForStudent(this.currentStudent)
}
},
// 体测记录相关方法
// 获取体测记录列表
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.$refs.fitnessRecordPopup.openAdd()
},
// 打开编辑体测记录弹窗
openEditFitnessRecord(record) {
this.$refs.fitnessRecordPopup.openEdit(record)
},
// 处理体测记录确认事件
async handleFitnessRecordConfirm(result) {
console.log('处理体测记录确认事件:', result)
try {
uni.showLoading({
title: '保存中...',
mask: true
})
console.log('保存体测记录参数:', result.data)
// 暂时使用本地更新,实际开发中应该调用真实API
if (result.isEditing) {
const index = this.fitnessRecords.findIndex(r => r.id === result.data.id)
if (index > -1) {
this.fitnessRecords[index] = { ...result.data }
}
} else {
const newRecord = {
...result.data,
id: Date.now() // 生成临时ID
}
this.fitnessRecords.unshift(newRecord)
}
uni.showToast({
title: '保存成功',
icon: 'success'
})
// 真实API调用代码(注释掉)
// const res = await apiRoute.saveFitnessRecord(result.data)
// 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()
}
},
// 处理体测记录关闭事件
handleFitnessRecordClose() {
console.log('体测记录弹窗已关闭')
},
// 学生信息相关方法
// 获取学生列表
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.restoreStudentExpandedStates()
// 强制触发视图更新
this.$forceUpdate()
return true
} else {
console.warn('getStudentList - API返回业务错误,使用Mock数据:', res.msg)
// API返回错误时,使用Mock数据
this.studentList = this.getMockStudentList()
// 恢复操作面板展开状态
this.restoreStudentExpandedStates()
console.log('getStudentList - 使用Mock学生列表:', this.studentList)
return true
}
} catch (error) {
console.error('getStudentList - 获取学生列表异常,使用Mock数据:', error)
// 发生异常时,使用Mock数据
this.studentList = this.getMockStudentList()
// 恢复操作面板展开状态
this.restoreStudentExpandedStates()
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
}
]
},
// 格式化年龄显示
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
},
// 处理客户操作按钮点击
handleClientAction(action) {
console.log('处理客户操作:', action)
switch (action.key) {
case 'edit_detail':
this.openViewEditClues()
break
case 'course_arrangement':
this.openViewEditClassLog()
break
case 'edit_record':
this.openViewEditCluesLog()
break
case 'order_list':
this.openViewOrder()
break
case 'service_list':
this.openViewOrder() // 暂时复用订单列表
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.$refs.studentEditPopup.openAdd()
},
// 打开编辑学生弹窗
openEditStudentDialog(student) {
this.$refs.studentEditPopup.openEdit(student)
},
// 处理学生编辑确认事件
async handleStudentEditConfirm(result) {
try {
uni.showLoading({
title: '保存中...',
mask: true
})
// 调用真实API
const res = await apiRoute.xs_addStudent(result)
if (res.code === 1) {
uni.showToast({
title: '保存成功',
icon: 'success'
})
// 刷新学生列表
await this.getStudentList()
} else {
uni.showToast({
title: res.msg || '保存失败',
icon: 'none'
})
}
} catch (error) {
console.error('保存学生信息失败:', error)
uni.showToast({
title: '保存失败,请重试',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
// 处理学生编辑关闭事件
handleStudentEditClose() {
// 弹窗关闭后的处理逻辑(如果需要)
console.log('学生编辑弹窗已关闭')
},
// 体测记录
handleFitnessRecord(student) {
// 切换到体测记录标签页并设置当前学生
this.switch_tags_type = 4
const studentIndex = this.studentList.findIndex(s => s.id === student.id)
if (studentIndex !== -1) {
this.currentStudentIndex = studentIndex
}
},
// 课程安排
handleCourseArrangement(student) {
// 切换到课程信息标签页
this.switch_tags_type = 2
uni.showToast({
title: `查看${student.name}的课程安排`,
icon: 'none'
})
},
// 订单列表
handleOrderList(student) {
uni.showToast({
title: `查看${student.name}的订单列表`,
icon: 'none'
})
// TODO: 跳转到订单列表页面
},
// 恢复学生操作面板展开状态
restoreStudentExpandedStates() {
const expandedStates = uni.getStorageSync('student_actions_expanded_states') || {}
this.studentList.forEach(student => {
// 如果学生数据中没有actionsExpanded属性,则初始化为false
if (typeof student.actionsExpanded === 'undefined') {
student.actionsExpanded = false
}
// 从本地存储恢复展开状态
if (expandedStates.hasOwnProperty(student.id)) {
student.actionsExpanded = expandedStates[student.id]
}
})
},
// 保存学生操作按钮排序
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>
@import './clue_info.less';
</style>