plan-mixin.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * 方案管理 mixin
  3. * 负责:方案列表加载、子方案选择、模式切换时刷新方案
  4. */
  5. import { getCareList, getCareDetail, getCustomPlanList, getCustomPlanDetail } from '@/utils/api/care.js'
  6. export default {
  7. data() {
  8. return {
  9. planList: [], // 当前模式下的方案列表
  10. selectedPlan: null, // 当前选中的方案 { id, name, description }
  11. isShowPlanDrawer: false, // 方案选择弹窗
  12. planLoading: false
  13. }
  14. },
  15. methods: {
  16. /**
  17. * 切换模式 - 覆盖原始changeMode,加入方案加载逻辑
  18. */
  19. changeMode(mode) {
  20. this.isShowDrawer2 = false
  21. if (this.modeType === mode) return
  22. this.modeType = mode
  23. // 切换模式时重置方案选择
  24. this.selectedPlan = null
  25. this.planList = []
  26. // 非休闲模式加载对应方案列表
  27. if (mode !== 0) {
  28. this.loadPlanList(mode)
  29. }
  30. // 停止音频(休闲模式专属)
  31. if (mode !== 0 && this._stopAudioOnModeChange) {
  32. this._stopAudioOnModeChange()
  33. }
  34. },
  35. /**
  36. * 加载指定模式的方案列表
  37. * @param {Number} mode - 1专业 2自定义 3延年圣手
  38. */
  39. async loadPlanList(mode) {
  40. this.planLoading = true
  41. try {
  42. if (mode === 2) {
  43. // 自定义模式 - 使用自定义方案列表接口
  44. const res = await getCustomPlanList()
  45. if (res && Array.isArray(res)) {
  46. this.planList = res.map(item => ({
  47. id: item.id,
  48. name: item.name || '未命名方案',
  49. description: item.description || '',
  50. symptoms: item.symptoms || '',
  51. status: item.status,
  52. useCount: item.useCount || 0,
  53. avgRating: item.avgRating
  54. }))
  55. } else {
  56. this.planList = []
  57. }
  58. } else {
  59. // 专业模式/延年圣手模式 - 使用原有调理方案列表接口
  60. const modeMap = {
  61. 1: 'PROFESSIONAL',
  62. 3: 'EXPERT'
  63. }
  64. const res = await getCareList({ modeType: modeMap[mode] || '' })
  65. if (res && res.records) {
  66. this.planList = res.records.map(item => ({
  67. id: item.id,
  68. name: item.title || item.name || '未命名方案',
  69. description: item.description || item.remark || '',
  70. steps: item.stepCount || item.steps || 0,
  71. duration: item.totalDuration || 0
  72. }))
  73. } else {
  74. this.planList = []
  75. }
  76. }
  77. } catch (e) {
  78. console.error('加载方案列表失败', e)
  79. this.planList = []
  80. }
  81. this.planLoading = false
  82. },
  83. /** 打开方案选择弹窗 */
  84. showPlanDrawer() {
  85. if (this.planList.length === 0 && this.modeType !== 0) {
  86. this.loadPlanList(this.modeType)
  87. }
  88. this.isShowPlanDrawer = true
  89. },
  90. /** 选择方案 */
  91. selectPlan(plan) {
  92. this.selectedPlan = plan
  93. this.isShowPlanDrawer = false
  94. // 选中方案后,可在此触发方案数据加载到curCase
  95. this._applyPlanToCase(plan)
  96. },
  97. /**
  98. * 将方案数据应用到当前穴位配置
  99. */
  100. async _applyPlanToCase(plan) {
  101. if (!plan || !plan.id) return
  102. try {
  103. let res
  104. if (this.modeType === 2) {
  105. // 自定义模式 - 使用自定义方案详情接口
  106. res = await getCustomPlanDetail(plan.id)
  107. } else {
  108. res = await getCareDetail(plan.id)
  109. }
  110. if (res && res.steps) {
  111. this.curCase = res.steps.map(step => ({
  112. id: step.acupointId || step.id,
  113. name: step.acupointName || '',
  114. time: step.duration || 15,
  115. temperature: step.temperature || 42,
  116. _x: step.x || 0,
  117. _y: step.y || 0
  118. }))
  119. this.curCaseIndex = 0
  120. }
  121. } catch (e) {
  122. console.error('加载方案详情失败', e)
  123. }
  124. }
  125. }
  126. }