| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- /**
- * 方案管理 mixin
- * 负责:方案列表加载、子方案选择、模式切换时刷新方案
- */
- import { getCareList, getCareDetail, getCustomPlanList, getCustomPlanDetail } 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 {
- if (mode === 2) {
- // 自定义模式 - 使用自定义方案列表接口
- const res = await getCustomPlanList()
- if (res && Array.isArray(res)) {
- this.planList = res.map(item => ({
- id: item.id,
- name: item.name || '未命名方案',
- description: item.description || '',
- symptoms: item.symptoms || '',
- status: item.status,
- useCount: item.useCount || 0,
- avgRating: item.avgRating
- }))
- } else {
- this.planList = []
- }
- } else {
- // 专业模式/延年圣手模式 - 使用原有调理方案列表接口
- const modeMap = {
- 1: 'PROFESSIONAL',
- 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)
- },
- /**
- * 将方案数据应用到当前穴位配置
- */
- async _applyPlanToCase(plan) {
- if (!plan || !plan.id) return
- try {
- let res
- if (this.modeType === 2) {
- // 自定义模式 - 使用自定义方案详情接口
- res = await getCustomPlanDetail(plan.id)
- } else {
- res = await getCareDetail(plan.id)
- }
- if (res && res.steps) {
- this.curCase = res.steps.map(step => ({
- id: step.acupointId || step.id,
- name: step.acupointName || '',
- time: step.duration || 15,
- temperature: step.temperature || 42,
- _x: step.x || 0,
- _y: step.y || 0
- }))
- this.curCaseIndex = 0
- }
- } catch (e) {
- console.error('加载方案详情失败', e)
- }
- }
- }
- }
|