| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /**
- * 方案管理 mixin
- * 负责:方案列表加载、子方案选择、模式切换时刷新方案
- */
- import { getCustomPlanList, getCustomPlanDetail, deleteCustomPlan, getProfessionalPlanList, getProfessionalPlanDetail, getMasterPlanList, getMasterPlanDetail } 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 {
- let res
- if (mode === 2) {
- // 自定义模式 - 使用自定义方案列表接口
- 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 if (mode === 1) {
- // 专业模式 - 使用专业模式方案列表接口
- res = await getProfessionalPlanList()
- this.planList = this._mapSystemPlanList(res)
- } else if (mode === 3) {
- // 延年圣手模式 - 使用延年圣手方案列表接口
- res = await getMasterPlanList()
- this.planList = this._mapSystemPlanList(res)
- }
- } catch (e) {
- console.error('加载方案列表失败', e)
- this.planList = []
- }
- this.planLoading = false
- },
- /** 映射系统方案列表数据(专业模式/延年圣手模式通用) */
- _mapSystemPlanList(res) {
- if (res && Array.isArray(res)) {
- return res.map(item => ({
- id: item.id,
- name: item.name || item.title || '未命名方案',
- description: item.description || item.remark || '',
- steps: item.stepCount || item.steps || 0,
- duration: item.totalDuration || item.duration || 0
- }))
- }
- // 兼容分页结构
- if (res && res.records) {
- return res.records.map(item => ({
- id: item.id,
- name: item.name || item.title || '未命名方案',
- description: item.description || item.remark || '',
- steps: item.stepCount || item.steps || 0,
- duration: item.totalDuration || item.duration || 0
- }))
- }
- return []
- },
- /** 打开方案选择弹窗 */
- 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)
- },
- /** 跳转新增自定义方案 */
- goAddCustomPlan() {
- uni.navigateTo({
- url: `/pages/device/acupointEdit/acupointEdit?profileId=${this.profileId}&mode=create`
- })
- },
- /** 跳转编辑自定义方案 */
- goEditCustomPlan(plan) {
- this.isShowPlanDrawer = false
- uni.navigateTo({
- url: `/pages/device/acupointEdit/acupointEdit?profileId=${this.profileId}&mode=edit&planId=${plan.id}`
- })
- },
- /** 删除自定义方案 */
- confirmDeletePlan(plan) {
- uni.showModal({
- title: '确认删除',
- content: `确定删除方案「${plan.name}」?删除后不可恢复。`,
- success: async (res) => {
- if (res.confirm) {
- try {
- await deleteCustomPlan(plan.id)
- uni.showToast({ title: '删除成功', icon: 'success' })
- // 从列表中移除
- this.planList = this.planList.filter(p => p.id !== plan.id)
- // 如果删除的是当前选中的方案,清空选择
- if (this.selectedPlan && this.selectedPlan.id === plan.id) {
- this.selectedPlan = null
- }
- } catch (e) {
- console.error('删除方案失败', e)
- uni.showToast({ title: '删除失败', icon: 'none' })
- }
- }
- }
- })
- },
- /**
- * 将方案数据应用到当前穴位配置
- */
- async _applyPlanToCase(plan) {
- if (!plan || !plan.id) return
- try {
- let res
- if (this.modeType === 2) {
- // 自定义模式 - 使用自定义方案详情接口
- res = await getCustomPlanDetail(plan.id)
- } else if (this.modeType === 1) {
- // 专业模式 - 使用专业模式方案详情接口
- res = await getProfessionalPlanDetail(plan.id)
- } else if (this.modeType === 3) {
- // 延年圣手模式 - 使用延年圣手方案详情接口
- res = await getMasterPlanDetail(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)
- }
- }
- }
- }
|