| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- <template>
- <div class="page-container">
- <!-- 搜索区域 -->
- <el-card class="search-card">
- <el-form :model="queryForm" inline>
- <el-form-item label="方案名称">
- <el-input v-model="queryForm.name" placeholder="请输入方案名称" clearable style="width:180px" />
- </el-form-item>
- <el-form-item label="模式类型">
- <el-select v-model="queryForm.modeType" placeholder="全部" clearable style="width:130px">
- <el-option label="一键艾灸" :value="1" />
- <el-option label="专业模式" :value="2" />
- <el-option label="自定义模式" :value="3" />
- <el-option label="延年圣手" :value="4" />
- </el-select>
- </el-form-item>
- <el-form-item label="作用类型">
- <el-select v-model="queryForm.effectType" placeholder="全部" clearable style="width:110px">
- <el-option v-for="e in effectOptions" :key="e" :label="e" :value="e" />
- </el-select>
- </el-form-item>
- <el-form-item label="创作人">
- <el-select v-model="queryForm.authorName" placeholder="全部" clearable filterable style="width:150px">
- <el-option v-for="name in authorOptions" :key="name" :label="name" :value="name" />
- </el-select>
- </el-form-item>
- <el-form-item label="状态">
- <el-select v-model="queryForm.status" placeholder="全部" clearable style="width:110px">
- <el-option label="草稿" :value="0" />
- <el-option label="已发布" :value="1" />
- <el-option label="已下架" :value="2" />
- </el-select>
- </el-form-item>
- <el-form-item label="创建时间">
- <el-date-picker
- v-model="dateRange"
- type="daterange"
- range-separator="~"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- value-format="YYYY-MM-DD"
- style="width:220px"
- />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
- <el-button :icon="Refresh" @click="handleReset">重置</el-button>
- </el-form-item>
- </el-form>
- </el-card>
- <!-- 表格区域 -->
- <el-card class="table-card">
- <template #header>
- <div class="card-header">
- <span class="title">方案列表</span>
- <div class="btn-group">
- <el-button type="primary" :icon="Plus" @click="handleAdd">新增</el-button>
- <el-button
- type="success"
- :disabled="selectedIds.length === 0"
- @click="handleBatchPublish"
- >批量发布</el-button>
- <el-button
- type="warning"
- :disabled="selectedIds.length === 0"
- @click="handleBatchOffshelf"
- >批量下架</el-button>
- <el-button
- type="danger"
- :icon="Delete"
- :disabled="selectedIds.length === 0"
- @click="handleBatchDelete"
- >批量删除</el-button>
- </div>
- </div>
- </template>
- <el-table
- :data="tableData"
- v-loading="loading"
- border
- stripe
- @selection-change="handleSelectionChange"
- >
- <el-table-column type="selection" width="50" align="center" :selectable="isRowSelectable" />
- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="planCode" label="方案ID" width="100" />
- <el-table-column prop="name" label="方案名称" min-width="140" show-overflow-tooltip />
- <el-table-column label="模式类型" width="110" align="center">
- <template #default="{ row }">
- <el-tag :type="modeTypeTag(row.modeType)" size="small">{{ modeTypeLabel(row.modeType) }}</el-tag>
- </template>
- </el-table-column>
- <el-table-column prop="effectType" label="作用类型" width="90" align="center">
- <template #default="{ row }">{{ row.effectType || '-' }}</template>
- </el-table-column>
- <el-table-column prop="authorName" label="创作人" width="100">
- <template #default="{ row }">{{ row.authorName || 'ADMIN' }}</template>
- </el-table-column>
- <el-table-column label="状态" width="90" align="center">
- <template #default="{ row }">
- <el-tag :type="statusTag(row.status)" size="small">{{ statusLabel(row.status) }}</el-tag>
- </template>
- </el-table-column>
- <el-table-column prop="createTime" label="创建时间" width="170">
- <template #default="{ row }">{{ formatDateTime(row.createTime) }}</template>
- </el-table-column>
- <el-table-column label="操作" width="220" align="center" fixed="right">
- <template #default="{ row }">
- <el-button size="small" type="primary" link @click="handleView(row)">查看</el-button>
- <el-button size="small" type="warning" link @click="handleEdit(row)">编辑</el-button>
- <template v-if="!isSystemPresetPlan(row)">
- <el-button v-if="row.status === 0 || row.status === 2" size="small" type="success" link @click="handlePublish(row)">发布</el-button>
- <el-button v-if="row.status === 1" size="small" type="info" link @click="handleOffshelf(row)">下架</el-button>
- <el-button v-if="canDeletePlan(row)" size="small" type="danger" link @click="handleDelete(row)">删除</el-button>
- </template>
- </template>
- </el-table-column>
- </el-table>
- <!-- 分页 -->
- <el-pagination
- v-model:current-page="queryForm.pageNum"
- v-model:page-size="queryForm.pageSize"
- :page-sizes="[10, 20, 50]"
- :total="total"
- :hide-on-single-page="false"
- layout="total, sizes, prev, pager, next, jumper"
- background
- class="pagination"
- @size-change="loadData"
- @current-change="loadData"
- />
- </el-card>
- <!-- 新增/编辑弹窗 -->
- <el-dialog
- v-model="dialogVisible"
- :title="dialogTitle"
- width="780px"
- destroy-on-close
- :close-on-click-modal="false"
- >
- <el-form
- :model="formData"
- :rules="formRules"
- ref="formRef"
- label-width="110px"
- :disabled="dialogMode === 'view'"
- >
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="方案名称" prop="name">
- <el-input
- v-model="formData.name"
- placeholder="请输入方案名称"
- maxlength="100"
- :disabled="isPlanNameLocked"
- />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="模式类型" prop="modeType">
- <el-select
- v-model="formData.modeType"
- placeholder="请选择模式类型"
- style="width:100%"
- :disabled="isModeTypeLocked"
- @change="handleModeTypeChange"
- >
- <el-option
- v-for="item in editableModeTypeOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col v-if="showEffectTypeField" :span="12">
- <el-form-item label="作用类型" prop="effectType">
- <el-select
- v-model="formData.effectType"
- placeholder="请选择作用"
- :clearable="!isEffectTypeLocked"
- :disabled="isEffectTypeLocked"
- style="width:100%"
- >
- <el-option v-for="e in effectOptions" :key="e" :label="e" :value="e" />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="适用人群" prop="applicableGender">
- <el-radio-group v-model="formData.applicableGender">
- <el-radio :label="0">不限</el-radio>
- <el-radio :label="1">仅男</el-radio>
- <el-radio :label="2">仅女</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="适用年龄" prop="ageMin">
- <el-input-number v-model="formData.ageMin" :min="1" :max="formData.ageMax - 1" style="width:110px" />
- 岁 ~
- <el-input-number v-model="formData.ageMax" :min="formData.ageMin + 1" style="width:110px" />
- 岁
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="创作人" prop="authorName">
- <el-input v-model="formData.authorName" disabled placeholder="当前登录用户" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-form-item label="适用症状" prop="symptomsList">
- <el-checkbox-group v-model="formData.symptomsList" class="symptom-checkboxes">
- <el-checkbox v-for="s in symptomsOptions" :key="s" :label="s" />
- </el-checkbox-group>
- <div v-if="dialogMode !== 'view'" class="symptom-add-row">
- <el-input
- v-model="customSymptom"
- placeholder="输入症状名称"
- maxlength="20"
- clearable
- @keyup.enter="addCustomSymptom"
- />
- <el-button type="primary" :icon="Plus" @click="addCustomSymptom">添加</el-button>
- </div>
- </el-form-item>
- <el-form-item label="方案描述">
- <el-input v-model="formData.description" type="textarea" :rows="2" maxlength="500" show-word-limit />
- </el-form-item>
- <!-- 灸方参数 -->
- <el-divider>灸方参数</el-divider>
- <div v-for="(step, index) in formData.steps" :key="index" class="step-row">
- <div class="step-header">
- <span class="step-num">参数 {{ index + 1 }}</span>
- <div v-if="dialogMode !== 'view'" class="step-actions">
- <el-tooltip content="上移参数" placement="top">
- <el-button
- size="small"
- :icon="ArrowUp"
- link
- :disabled="index === 0"
- aria-label="上移参数"
- @click="moveStep(index, -1)"
- />
- </el-tooltip>
- <el-tooltip content="下移参数" placement="top">
- <el-button
- size="small"
- :icon="ArrowDown"
- link
- :disabled="index === formData.steps.length - 1"
- aria-label="下移参数"
- @click="moveStep(index, 1)"
- />
- </el-tooltip>
- <el-button
- size="small"
- type="danger"
- link
- :disabled="formData.steps.length <= 1"
- @click="removeStep(index)"
- >删除</el-button>
- </div>
- </div>
- <el-row :gutter="12">
- <el-col :span="8">
- <el-form-item :label="'穴位'" :prop="`steps.${index}.acupointId`" :rules="stepRules.acupointId">
- <el-select
- v-model="step.acupointId"
- placeholder="请选择穴位"
- style="width:100%"
- filterable
- @change="(val) => onAcupointChange(val, index)"
- >
- <el-option
- v-for="a in acupointOptions"
- :key="a.id"
- :label="a.name"
- :value="a.id"
- />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item :label="'侧别'" :prop="`steps.${index}.side`" :rules="stepRules.side">
- <el-select v-model="step.side" placeholder="侧别" style="width:100%">
- <el-option
- v-for="opt in getSideOptions(step.acupointId)"
- :key="opt.value"
- :label="opt.label"
- :value="opt.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item :label="'手法'" :prop="`steps.${index}.techniqueId`" :rules="stepRules.techniqueId">
- <el-select
- v-model="step.techniqueId"
- placeholder="请选择手法"
- style="width:100%"
- filterable
- @change="(val) => onTechniqueChange(val, index)"
- >
- <el-option
- v-for="t in techniqueOptions"
- :key="t.id"
- :label="t.name"
- :value="t.id"
- />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="12">
- <el-col :span="8">
- <el-form-item :label="'温度(°C)'" :prop="`steps.${index}.temperature`" :rules="stepRules.temperature">
- <el-input-number v-model="step.temperature" :min="35" :max="50" :precision="1" style="width:100%" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item :label="'时间(分)'" :prop="`steps.${index}.duration`" :rules="stepRules.duration">
- <el-input-number v-model="step.duration" :min="1" :max="30" style="width:100%" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="备注">
- <el-input v-model="step.remark" placeholder="备注(选填)" maxlength="100" />
- </el-form-item>
- </el-col>
- </el-row>
- </div>
- <el-button
- v-if="dialogMode !== 'view'"
- type="primary"
- plain
- size="small"
- @click="addStep"
- style="margin-top:4px"
- >+ 添加参数</el-button>
- </el-form>
- <template #footer>
- <el-button @click="dialogVisible = false">{{ dialogMode === 'view' ? '关闭' : '取消' }}</el-button>
- <template v-if="dialogMode !== 'view'">
- <el-button v-if="!isSystemPresetPlan(formData)" :loading="submitLoading" @click="handleSubmit(0)">保存为草稿</el-button>
- <el-button type="primary" :loading="submitLoading" @click="handleSubmit(isSystemPresetPlan(formData) ? formData.status : 1)">
- {{ isSystemPresetPlan(formData) ? '保存修改' : '发布方案' }}
- </el-button>
- </template>
- </template>
- </el-dialog>
- <!-- 方案详情弹窗(只读) -->
- <el-dialog v-model="detailVisible" title="方案详情" width="700px" destroy-on-close :close-on-click-modal="false">
- <template v-if="detailData">
- <el-descriptions :column="2" border size="small">
- <el-descriptions-item label="方案编码">{{ detailData.planCode }}</el-descriptions-item>
- <el-descriptions-item label="方案名称">{{ detailData.name }}</el-descriptions-item>
- <el-descriptions-item label="模式类型">{{ modeTypeLabel(detailData.modeType) }}</el-descriptions-item>
- <el-descriptions-item label="作用类型">{{ detailData.effectType || '-' }}</el-descriptions-item>
- <el-descriptions-item label="创作人">{{ detailData.authorName || 'ADMIN' }}</el-descriptions-item>
- <el-descriptions-item label="状态">{{ statusLabel(detailData.status) }}</el-descriptions-item>
- <el-descriptions-item label="适用人群">{{ ['不限', '仅男', '仅女'][detailData.applicableGender] || '-' }}</el-descriptions-item>
- <el-descriptions-item label="适用年龄">{{ detailData.ageMin }}-{{ detailData.ageMax }}岁</el-descriptions-item>
- <el-descriptions-item label="适用症状" :span="2">{{ detailData.symptoms || '-' }}</el-descriptions-item>
- <el-descriptions-item label="方案描述" :span="2">{{ detailData.description || '-' }}</el-descriptions-item>
- <el-descriptions-item label="使用人数">{{ detailData.useCount || 0 }}人</el-descriptions-item>
- <el-descriptions-item label="平均评分">{{ detailData.avgRating ?? '-' }}分</el-descriptions-item>
- <el-descriptions-item label="创建时间">{{ formatDateTime(detailData.createTime) }}</el-descriptions-item>
- <el-descriptions-item label="更新时间">{{ formatDateTime(detailData.updateTime) }}</el-descriptions-item>
- </el-descriptions>
- <el-divider>灸方参数</el-divider>
- <el-table :data="detailData.steps || []" border size="small">
- <el-table-column prop="stepOrder" label="参数" width="60" align="center" />
- <el-table-column prop="acupointName" label="穴位" width="100" />
- <el-table-column label="侧别" width="80" align="center">
- <template #default="{ row }">{{ ['', '中心', '左侧', '右侧', '双侧'][row.side] || '-' }}</template>
- </el-table-column>
- <el-table-column prop="temperature" label="温度(°C)" width="90" align="center" />
- <el-table-column prop="duration" label="时间(分)" width="90" align="center" />
- <el-table-column prop="techniqueName" label="艾灸手法" width="100" />
- <el-table-column prop="remark" label="备注" min-width="100">
- <template #default="{ row }">{{ row.remark || '-' }}</template>
- </el-table-column>
- </el-table>
- </template>
- <template #footer>
- <el-button @click="detailVisible = false">关闭</el-button>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup>
- import { ref, reactive, computed, onMounted } from 'vue'
- import { ElMessage, ElMessageBox } from 'element-plus'
- import { Search, Refresh, Plus, Delete, ArrowUp, ArrowDown } from '@element-plus/icons-vue'
- import {
- getPlanPage,
- getPlanDetail,
- addPlan,
- updatePlan,
- deletePlan,
- batchDeletePlan,
- publishPlan,
- batchPublishPlan,
- offshelfPlan,
- batchOffshelfPlan,
- getPlanAuthors
- } from '@/api/plan'
- import { getAcupointList } from '@/api/acupoint'
- import { getTechniqueList } from '@/api/moxibustion'
- import { useUserStore } from '@/store/user'
- import { formatDateTime } from '@/utils/date'
- import { parsePageData } from '@/utils/pagination'
- // ============ 枚举常量 ============
- const effectOptions = ['驱寒', '祛湿', '祛风', '化瘀', '活血', '化痰', '养颜', '扶阳']
- const modeTypeOptions = [
- { label: '一键艾灸', value: 1 },
- { label: '专业模式', value: 2 },
- { label: '自定义模式', value: 3 },
- { label: '延年圣手', value: 4 }
- ]
- const addModeTypeOptions = modeTypeOptions.filter(item => [3, 4].includes(item.value))
- const defaultSymptomsOptions = ['怕冷', '感冒', '咳嗽', '痰多', '疼痛', '腰酸', '失眠', '疲劳', '皮肤暗沉', '手脚冰凉']
- const symptomsOptions = ref([...defaultSymptomsOptions])
- const systemPresetPlanCodes = Array.from({ length: 9 }, (_, index) => `S00${index + 1}`)
- const professionalPresetEffectMap = {
- S002: '驱寒',
- S003: '祛湿',
- S004: '祛风',
- S005: '化瘀',
- S006: '活血',
- S007: '化痰',
- S008: '养颜',
- S009: '扶阳'
- }
- const userStore = useUserStore()
- // ============ 选项列表(用于选择框) ============
- const acupointOptions = ref([])
- const techniqueOptions = ref([])
- const authorOptions = ref([])
- /**
- * 加载穴位、手法、创作人选项列表
- */
- async function loadOptions() {
- try {
- const [acupointRes, techniqueRes, authorRes] = await Promise.all([
- getAcupointList(),
- getTechniqueList(),
- getPlanAuthors().catch(() => ({ data: [] }))
- ])
- acupointOptions.value = acupointRes.data || []
- techniqueOptions.value = techniqueRes.data || []
- authorOptions.value = authorRes.data || []
- } catch (e) {
- // 选项加载失败不影响主流程
- }
- }
- /**
- * 模式类型标签文字
- */
- function modeTypeLabel(val) {
- return ['', '一键艾灸', '专业模式', '自定义模式', '延年圣手'][val] || '-'
- }
- /**
- * 模式类型 Tag 颜色
- */
- function modeTypeTag(val) {
- return ['', '', 'success', 'warning', 'danger'][val] || ''
- }
- /**
- * 状态标签文字
- */
- function statusLabel(val) {
- return { 0: '草稿', 1: '已发布', 2: '已下架' }[val] ?? '-'
- }
- /**
- * 状态 Tag 颜色
- */
- function statusTag(val) {
- return { 0: 'info', 1: 'success', 2: 'warning' }[val] ?? ''
- }
- function isSystemPresetPlan(plan) {
- return systemPresetPlanCodes.includes(plan?.planCode)
- }
- function canDeletePlan(plan) {
- return !isSystemPresetPlan(plan) && (plan?.status === 0 || plan?.status === 2)
- }
- function isOneClickPresetPlan(plan) {
- return plan?.planCode === 'S001'
- }
- function isProfessionalPresetPlan(plan) {
- return Boolean(professionalPresetEffectMap[plan?.planCode])
- }
- function getProfessionalPresetEffect(plan) {
- return professionalPresetEffectMap[plan?.planCode] || ''
- }
- function isRowSelectable(row) {
- return !isSystemPresetPlan(row)
- }
- // ============ 查询 ============
- const queryForm = reactive({
- name: '',
- modeType: null,
- effectType: '',
- authorName: '',
- status: null,
- createTimeStart: '',
- createTimeEnd: '',
- pageNum: 1,
- pageSize: 10
- })
- const dateRange = ref([])
- const tableData = ref([])
- const total = ref(0)
- const loading = ref(false)
- const selectedRows = ref([])
- const selectedIds = ref([])
- /**
- * 加载方案列表
- */
- async function loadData() {
- loading.value = true
- // 同步日期范围
- queryForm.createTimeStart = dateRange.value?.[0] || ''
- queryForm.createTimeEnd = dateRange.value?.[1] || ''
- try {
- const res = await getPlanPage(queryForm)
- const { records, total: pageTotal } = parsePageData(res.data)
- tableData.value = records
- total.value = pageTotal
- } finally {
- loading.value = false
- }
- }
- /**
- * 查询
- */
- function handleSearch() {
- queryForm.pageNum = 1
- loadData()
- }
- /**
- * 重置查询条件
- */
- function handleReset() {
- queryForm.name = ''
- queryForm.modeType = null
- queryForm.effectType = ''
- queryForm.authorName = ''
- queryForm.status = null
- queryForm.createTimeStart = ''
- queryForm.createTimeEnd = ''
- queryForm.pageNum = 1
- dateRange.value = []
- loadData()
- }
- /**
- * 多选变化
- */
- function handleSelectionChange(selection) {
- selectedRows.value = selection
- selectedIds.value = selection.map(r => r.id)
- }
- // ============ 新增/编辑弹窗 ============
- const dialogVisible = ref(false)
- const dialogTitle = ref('')
- const dialogMode = ref('add')
- const submitLoading = ref(false)
- const formRef = ref(null)
- const customSymptom = ref('')
- const defaultStep = () => ({
- acupointId: null,
- acupointName: '',
- side: 1,
- temperature: 42,
- duration: 5,
- techniqueId: null,
- techniqueName: '',
- remark: ''
- })
- const defaultForm = () => ({
- id: null,
- planCode: '',
- name: '',
- modeType: 3,
- effectType: '',
- symptomsList: [],
- symptoms: '',
- applicableGender: 0,
- ageMin: 1,
- ageMax: 120,
- authorId: getCurrentAuthorId(),
- authorName: getCurrentAuthorName(),
- authorType: getCurrentAuthorType(),
- status: 0,
- description: '',
- steps: [defaultStep()]
- })
- const formData = reactive(defaultForm())
- const formRules = {
- name: [{ required: true, message: '请输入方案名称', trigger: 'blur' }],
- modeType: [{ required: true, message: '请选择模式类型', trigger: 'change' }],
- effectType: [
- {
- validator: (_rule, value, callback) => {
- if (formData.modeType === 2 && !value) {
- callback(new Error('请选择作用类型'))
- return
- }
- callback()
- },
- trigger: 'change'
- }
- ]
- }
- const stepRules = {
- acupointId: [{ required: true, message: '请选择穴位', trigger: 'change' }],
- side: [{ required: true, message: '请选择侧别', trigger: 'change' }],
- temperature: [{ required: true, message: '请填写温度', trigger: 'blur' }],
- duration: [{ required: true, message: '请填写时间', trigger: 'blur' }],
- techniqueId: [{ required: true, message: '请选择艾灸手法', trigger: 'change' }]
- }
- const allSideOptions = [
- { label: '中心', value: 1 },
- { label: '左侧', value: 2 },
- { label: '右侧', value: 3 },
- { label: '双侧', value: 4 }
- ]
- /**
- * 根据穴位的单/双穴属性返回可选的侧别选项
- * - 单穴:只能选"中心"
- * - 双穴:不能选"中心"(左侧/右侧/双侧)
- */
- function getSideOptions(acupointId) {
- if (!acupointId) return allSideOptions
- const found = acupointOptions.value.find(a => a.id === acupointId)
- if (!found || !found.singleDouble) return allSideOptions
- if (found.singleDouble.includes('单')) {
- return allSideOptions.filter(opt => opt.value === 1)
- }
- if (found.singleDouble.includes('双')) {
- return allSideOptions.filter(opt => opt.value !== 1)
- }
- return allSideOptions
- }
- /**
- * 穴位选择变更:同步填充 acupointName,并根据单/双穴自动调整侧别
- */
- function onAcupointChange(id, index) {
- const found = acupointOptions.value.find(a => a.id === id)
- formData.steps[index].acupointName = found ? found.name : ''
- if (found && found.singleDouble) {
- if (found.singleDouble.includes('单') && formData.steps[index].side !== 1) {
- formData.steps[index].side = 1
- } else if (found.singleDouble.includes('双') && formData.steps[index].side === 1) {
- formData.steps[index].side = 4
- }
- }
- }
- /**
- * 手法选择变更:同步填充 techniqueName
- */
- function onTechniqueChange(id, index) {
- const found = techniqueOptions.value.find(t => t.id === id)
- formData.steps[index].techniqueName = found ? found.name : ''
- }
- function parseSymptoms(symptoms) {
- return (symptoms || '')
- .split(',')
- .map(item => item.trim())
- .filter(Boolean)
- .filter((item, index, list) => list.indexOf(item) === index)
- }
- function syncSymptomOptions(symptoms) {
- symptoms.forEach(item => {
- if (!symptomsOptions.value.includes(item)) {
- symptomsOptions.value.push(item)
- }
- })
- }
- function addCustomSymptom() {
- const symptom = customSymptom.value.trim()
- if (!symptom) {
- ElMessage.warning('请输入症状名称')
- return
- }
- if (/[,,]/.test(symptom)) {
- ElMessage.warning('症状名称不能包含逗号')
- return
- }
- syncSymptomOptions([symptom])
- if (!formData.symptomsList.includes(symptom)) {
- formData.symptomsList.push(symptom)
- }
- customSymptom.value = ''
- }
- function getCurrentAuthorId() {
- return userStore.userInfo?.userId || null
- }
- function getCurrentAuthorName() {
- return userStore.nickname || userStore.username || 'ADMIN'
- }
- function getCurrentAuthorType() {
- const typeMap = { 1: 2, 2: 3, 3: 1 }
- return typeMap[userStore.userInfo?.userType] || 1
- }
- function applyCurrentAuthor() {
- formData.authorId = getCurrentAuthorId()
- formData.authorName = getCurrentAuthorName()
- formData.authorType = getCurrentAuthorType()
- }
- const editableModeTypeOptions = computed(() => {
- if (dialogMode.value === 'add') {
- return addModeTypeOptions
- }
- if (isOneClickPresetPlan(formData)) {
- return modeTypeOptions.filter(item => item.value === 1)
- }
- if (isProfessionalPresetPlan(formData)) {
- return modeTypeOptions.filter(item => item.value === 2)
- }
- return addModeTypeOptions
- })
- const isModeTypeLocked = computed(() => (
- dialogMode.value === 'edit' && (isOneClickPresetPlan(formData) || isProfessionalPresetPlan(formData))
- ))
- const isPlanNameLocked = computed(() => dialogMode.value === 'edit' && isSystemPresetPlan(formData))
- const isEffectTypeLocked = computed(() => dialogMode.value === 'edit' && isProfessionalPresetPlan(formData))
- const showEffectTypeField = computed(() => formData.modeType === 2 && !isOneClickPresetPlan(formData))
- function applyPlanModeRules() {
- if (isOneClickPresetPlan(formData)) {
- formData.modeType = 1
- formData.effectType = ''
- return
- }
- if (isProfessionalPresetPlan(formData)) {
- formData.modeType = 2
- formData.effectType = getProfessionalPresetEffect(formData)
- return
- }
- if (![3, 4].includes(formData.modeType)) {
- formData.modeType = 3
- }
- if (formData.modeType !== 2) {
- formData.effectType = ''
- }
- }
- function handleModeTypeChange() {
- applyPlanModeRules()
- }
- /**
- * 添加一个灸方参数
- */
- function addStep() {
- formData.steps.push(defaultStep())
- }
- /**
- * 调整灸方参数顺序
- */
- function moveStep(index, direction) {
- const targetIndex = index + direction
- if (targetIndex < 0 || targetIndex >= formData.steps.length) return
- const [step] = formData.steps.splice(index, 1)
- formData.steps.splice(targetIndex, 0, step)
- formRef.value?.clearValidate?.()
- }
- /**
- * 删除某个灸方参数
- */
- function removeStep(index) {
- if (formData.steps.length <= 1) return
- formData.steps.splice(index, 1)
- formRef.value?.clearValidate?.()
- }
- /**
- * 打开新增弹窗
- */
- function handleAdd() {
- Object.assign(formData, defaultForm())
- formData.steps = [defaultStep()]
- customSymptom.value = ''
- applyCurrentAuthor()
- dialogTitle.value = '新增方案'
- dialogMode.value = 'add'
- applyPlanModeRules()
- dialogVisible.value = true
- }
- /**
- * 打开编辑弹窗
- */
- async function handleEdit(row) {
- const res = await getPlanDetail(row.id)
- const detail = res.data
- const symptomsList = parseSymptoms(detail.symptoms)
- syncSymptomOptions(symptomsList)
- Object.assign(formData, defaultForm(), {
- ...detail,
- symptomsList,
- steps: detail.steps?.length > 0 ? detail.steps : [defaultStep()]
- })
- customSymptom.value = ''
- applyCurrentAuthor()
- dialogTitle.value = '编辑方案'
- dialogMode.value = 'edit'
- applyPlanModeRules()
- dialogVisible.value = true
- }
- /**
- * 提交保存(0=草稿,1=发布)
- */
- async function handleSubmit(publishFlag) {
- applyPlanModeRules()
- await formRef.value.validate()
- applyCurrentAuthor()
- submitLoading.value = true
- try {
- const shouldPublish = !isSystemPresetPlan(formData) && publishFlag === 1
- const payload = {
- ...formData,
- symptoms: formData.symptomsList.join(','),
- status: publishFlag
- }
- if (formData.id) {
- await updatePlan(payload)
- if (shouldPublish) {
- await publishPlan(formData.id)
- }
- } else {
- const res = await addPlan(payload)
- if (shouldPublish) {
- if (!res.data) {
- throw new Error('未获取到新增方案ID,无法同步发布')
- }
- await publishPlan(res.data)
- }
- }
- ElMessage.success(shouldPublish ? '发布成功' : '操作成功')
- dialogVisible.value = false
- loadData()
- } finally {
- submitLoading.value = false
- }
- }
- // ============ 方案详情弹窗 ============
- const detailVisible = ref(false)
- const detailData = ref(null)
- /**
- * 查看方案详情
- */
- async function handleView(row) {
- const res = await getPlanDetail(row.id)
- detailData.value = res.data
- detailVisible.value = true
- }
- // ============ 状态操作 ============
- /**
- * 发布单条方案
- */
- async function handlePublish(row) {
- await ElMessageBox.confirm(`确认发布方案「${row.name}」吗?`, '提示', { type: 'warning' })
- await publishPlan(row.id)
- ElMessage.success('发布成功')
- loadData()
- }
- /**
- * 下架单条方案
- */
- async function handleOffshelf(row) {
- await ElMessageBox.confirm(`确认下架方案「${row.name}」吗?`, '提示', { type: 'warning' })
- await offshelfPlan(row.id)
- ElMessage.success('下架成功')
- loadData()
- }
- /**
- * 批量发布
- */
- async function handleBatchPublish() {
- await ElMessageBox.confirm(`确认批量发布选中的 ${selectedIds.value.length} 条方案吗?`, '批量发布', { type: 'warning' })
- await batchPublishPlan(selectedIds.value)
- ElMessage.success('批量发布成功')
- loadData()
- }
- /**
- * 批量下架
- */
- async function handleBatchOffshelf() {
- await ElMessageBox.confirm(`确认批量下架选中的 ${selectedIds.value.length} 条方案吗?`, '批量下架', { type: 'warning' })
- await batchOffshelfPlan(selectedIds.value)
- ElMessage.success('批量下架成功')
- loadData()
- }
- /**
- * 删除单条方案
- */
- async function handleDelete(row) {
- await ElMessageBox.confirm(`确认删除方案「${row.name}」吗?`, '提示', { type: 'warning' })
- await deletePlan(row.id)
- ElMessage.success('删除成功')
- loadData()
- }
- /**
- * 批量删除
- */
- async function handleBatchDelete() {
- if (selectedRows.value.some(row => !canDeletePlan(row))) {
- ElMessage.warning('仅草稿或已下架方案可删除,请先下架已发布方案')
- return
- }
- await ElMessageBox.confirm(
- `确认批量删除选中的 ${selectedIds.value.length} 条方案吗?(仅草稿或已下架状态可删)`,
- '批量删除确认',
- { type: 'warning', confirmButtonText: '确认删除', cancelButtonText: '取消' }
- )
- await batchDeletePlan(selectedIds.value)
- ElMessage.success('批量删除成功')
- selectedRows.value = []
- selectedIds.value = []
- loadData()
- }
- onMounted(() => {
- loadData()
- loadOptions()
- })
- </script>
- <style lang="scss" scoped>
- .page-container {
- display: flex;
- flex-direction: column;
- gap: 16px;
- }
- .search-card {
- :deep(.el-card__body) {
- padding: 16px 20px 4px;
- }
- }
- .table-card {
- .card-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- .title {
- font-weight: 600;
- font-size: 15px;
- }
- .btn-group {
- display: flex;
- gap: 8px;
- align-items: center;
- }
- }
- }
- .pagination {
- margin-top: 16px;
- justify-content: flex-end;
- }
- .symptom-checkboxes {
- display: flex;
- flex-wrap: wrap;
- gap: 0 20px;
- }
- .symptom-add-row {
- display: flex;
- gap: 8px;
- width: 360px;
- max-width: 100%;
- margin-top: 8px;
- }
- .step-row {
- border: 1px solid #ebeef5;
- border-radius: 6px;
- padding: 12px 16px 0;
- margin-bottom: 12px;
- background: #fafafa;
- .step-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 8px;
- .step-num {
- font-weight: 600;
- color: #409eff;
- font-size: 13px;
- }
- .step-actions {
- display: flex;
- align-items: center;
- gap: 8px;
- :deep(.el-button + .el-button) {
- margin-left: 0;
- }
- }
- }
- }
- </style>
|