/** * 方案管理 mixin * 负责:方案列表加载、子方案选择、模式切换时刷新方案 */ import { getCareList, getCareDetail } from '@/utils/api/care.js' export default { data() { return { planList: [], // 当前模式下的方案列表 selectedPlan: null, // 当前选中的方案 { id, name, description } isShowPlanDrawer: false, // 方案选择弹窗 planLoading: false } }, methods: { /** * 切换模式 - 覆盖原始changeMode,加入方案加载逻辑 */ changeMode(mode) { this.isShowDrawer2 = false if (this.modeType === mode) return this.modeType = mode // 切换模式时重置方案选择 this.selectedPlan = null this.planList = [] // 非休闲模式加载对应方案列表 if (mode !== 0) { this.loadPlanList(mode) } // 停止音频(休闲模式专属) if (mode !== 0 && this._stopAudioOnModeChange) { this._stopAudioOnModeChange() } }, /** * 加载指定模式的方案列表 * @param {Number} mode - 1专业 2自定义 3专家 */ async loadPlanList(mode) { this.planLoading = true try { // modeType映射为后端模式标识 const modeMap = { 1: 'PROFESSIONAL', 2: 'CUSTOM', 3: 'EXPERT' } const res = await getCareList({ modeType: modeMap[mode] || '' }) if (res && res.records) { this.planList = res.records.map(item => ({ id: item.id, name: item.title || item.name || '未命名方案', description: item.description || item.remark || '', steps: item.stepCount || item.steps || 0, duration: item.totalDuration || 0 })) } else { this.planList = [] } } catch (e) { console.error('加载方案列表失败', e) this.planList = [] } this.planLoading = false }, /** 打开方案选择弹窗 */ showPlanDrawer() { if (this.planList.length === 0 && this.modeType !== 0) { this.loadPlanList(this.modeType) } this.isShowPlanDrawer = true }, /** 选择方案 */ selectPlan(plan) { this.selectedPlan = plan this.isShowPlanDrawer = false // 选中方案后,可在此触发方案数据加载到curCase this._applyPlanToCase(plan) }, /** * 将方案数据应用到当前穴位配置 * TODO: 后续对接方案详情接口,获取具体步骤和穴位坐标 */ async _applyPlanToCase(plan) { if (!plan || !plan.id) return try { const res = await getCareDetail(plan.id) if (res && res.steps) { this.curCase = res.steps.map(step => ({ id: step.acupointId || step.id, time: step.duration || 15, _x: step.x || 0, _y: step.y || 0 })) this.curCaseIndex = 0 } } catch (e) { console.error('加载方案详情失败', e) } } } }