index.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. <template>
  2. <div class="page-container">
  3. <!-- 搜索区域 -->
  4. <el-card class="search-card">
  5. <el-form :model="queryForm" inline>
  6. <el-form-item label="方案名称">
  7. <el-input v-model="queryForm.name" placeholder="请输入方案名称" clearable style="width:180px" />
  8. </el-form-item>
  9. <el-form-item label="模式类型">
  10. <el-select v-model="queryForm.modeType" placeholder="全部" clearable style="width:130px">
  11. <el-option label="一键艾灸" :value="1" />
  12. <el-option label="专业模式" :value="2" />
  13. <el-option label="自定义模式" :value="3" />
  14. <el-option label="延年圣手" :value="4" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="作用类型">
  18. <el-select v-model="queryForm.effectType" placeholder="全部" clearable style="width:110px">
  19. <el-option v-for="e in effectOptions" :key="e" :label="e" :value="e" />
  20. </el-select>
  21. </el-form-item>
  22. <el-form-item label="创作人">
  23. <el-select v-model="queryForm.authorName" placeholder="全部" clearable filterable style="width:150px">
  24. <el-option v-for="name in authorOptions" :key="name" :label="name" :value="name" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="状态">
  28. <el-select v-model="queryForm.status" placeholder="全部" clearable style="width:110px">
  29. <el-option label="草稿" :value="0" />
  30. <el-option label="已发布" :value="1" />
  31. <el-option label="已下架" :value="2" />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="创建时间">
  35. <el-date-picker
  36. v-model="dateRange"
  37. type="daterange"
  38. range-separator="~"
  39. start-placeholder="开始日期"
  40. end-placeholder="结束日期"
  41. value-format="YYYY-MM-DD"
  42. style="width:220px"
  43. />
  44. </el-form-item>
  45. <el-form-item>
  46. <el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
  47. <el-button :icon="Refresh" @click="handleReset">重置</el-button>
  48. </el-form-item>
  49. </el-form>
  50. </el-card>
  51. <!-- 表格区域 -->
  52. <el-card class="table-card">
  53. <template #header>
  54. <div class="card-header">
  55. <span class="title">方案列表</span>
  56. <div class="btn-group">
  57. <el-button type="primary" :icon="Plus" @click="handleAdd">新增</el-button>
  58. <el-button
  59. type="success"
  60. :disabled="selectedIds.length === 0"
  61. @click="handleBatchPublish"
  62. >批量发布</el-button>
  63. <el-button
  64. type="warning"
  65. :disabled="selectedIds.length === 0"
  66. @click="handleBatchOffshelf"
  67. >批量下架</el-button>
  68. <el-button
  69. type="danger"
  70. :icon="Delete"
  71. :disabled="selectedIds.length === 0"
  72. @click="handleBatchDelete"
  73. >批量删除</el-button>
  74. </div>
  75. </div>
  76. </template>
  77. <el-table
  78. :data="tableData"
  79. v-loading="loading"
  80. border
  81. stripe
  82. @selection-change="handleSelectionChange"
  83. >
  84. <el-table-column type="selection" width="50" align="center" :selectable="isRowSelectable" />
  85. <el-table-column type="index" label="序号" width="60" align="center" />
  86. <el-table-column prop="planCode" label="方案ID" width="100" />
  87. <el-table-column prop="name" label="方案名称" min-width="140" show-overflow-tooltip />
  88. <el-table-column label="模式类型" width="110" align="center">
  89. <template #default="{ row }">
  90. <el-tag :type="modeTypeTag(row.modeType)" size="small">{{ modeTypeLabel(row.modeType) }}</el-tag>
  91. </template>
  92. </el-table-column>
  93. <el-table-column prop="effectType" label="作用类型" width="90" align="center">
  94. <template #default="{ row }">{{ row.effectType || '-' }}</template>
  95. </el-table-column>
  96. <el-table-column prop="authorName" label="创作人" width="100">
  97. <template #default="{ row }">{{ row.authorName || 'ADMIN' }}</template>
  98. </el-table-column>
  99. <el-table-column label="状态" width="90" align="center">
  100. <template #default="{ row }">
  101. <el-tag :type="statusTag(row.status)" size="small">{{ statusLabel(row.status) }}</el-tag>
  102. </template>
  103. </el-table-column>
  104. <el-table-column prop="createTime" label="创建时间" width="170">
  105. <template #default="{ row }">{{ formatDateTime(row.createTime) }}</template>
  106. </el-table-column>
  107. <el-table-column label="操作" width="220" align="center" fixed="right">
  108. <template #default="{ row }">
  109. <el-button size="small" type="primary" link @click="handleView(row)">查看</el-button>
  110. <el-button size="small" type="warning" link @click="handleEdit(row)">编辑</el-button>
  111. <template v-if="!isSystemPresetPlan(row)">
  112. <el-button v-if="row.status === 0 || row.status === 2" size="small" type="success" link @click="handlePublish(row)">发布</el-button>
  113. <el-button v-if="row.status === 1" size="small" type="info" link @click="handleOffshelf(row)">下架</el-button>
  114. <el-button v-if="canDeletePlan(row)" size="small" type="danger" link @click="handleDelete(row)">删除</el-button>
  115. </template>
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. <!-- 分页 -->
  120. <el-pagination
  121. v-model:current-page="queryForm.pageNum"
  122. v-model:page-size="queryForm.pageSize"
  123. :page-sizes="[10, 20, 50]"
  124. :total="total"
  125. :hide-on-single-page="false"
  126. layout="total, sizes, prev, pager, next, jumper"
  127. background
  128. class="pagination"
  129. @size-change="loadData"
  130. @current-change="loadData"
  131. />
  132. </el-card>
  133. <!-- 新增/编辑弹窗 -->
  134. <el-dialog
  135. v-model="dialogVisible"
  136. :title="dialogTitle"
  137. width="780px"
  138. destroy-on-close
  139. :close-on-click-modal="false"
  140. >
  141. <el-form
  142. :model="formData"
  143. :rules="formRules"
  144. ref="formRef"
  145. label-width="110px"
  146. :disabled="dialogMode === 'view'"
  147. >
  148. <el-row :gutter="20">
  149. <el-col :span="12">
  150. <el-form-item label="方案名称" prop="name">
  151. <el-input
  152. v-model="formData.name"
  153. placeholder="请输入方案名称"
  154. maxlength="100"
  155. :disabled="isPlanNameLocked"
  156. />
  157. </el-form-item>
  158. </el-col>
  159. <el-col :span="12">
  160. <el-form-item label="模式类型" prop="modeType">
  161. <el-select
  162. v-model="formData.modeType"
  163. placeholder="请选择模式类型"
  164. style="width:100%"
  165. :disabled="isModeTypeLocked"
  166. @change="handleModeTypeChange"
  167. >
  168. <el-option
  169. v-for="item in editableModeTypeOptions"
  170. :key="item.value"
  171. :label="item.label"
  172. :value="item.value"
  173. />
  174. </el-select>
  175. </el-form-item>
  176. </el-col>
  177. </el-row>
  178. <el-row :gutter="20">
  179. <el-col v-if="showEffectTypeField" :span="12">
  180. <el-form-item label="作用类型" prop="effectType">
  181. <el-select
  182. v-model="formData.effectType"
  183. placeholder="请选择作用"
  184. :clearable="!isEffectTypeLocked"
  185. :disabled="isEffectTypeLocked"
  186. style="width:100%"
  187. >
  188. <el-option v-for="e in effectOptions" :key="e" :label="e" :value="e" />
  189. </el-select>
  190. </el-form-item>
  191. </el-col>
  192. <el-col :span="12">
  193. <el-form-item label="适用人群" prop="applicableGender">
  194. <el-radio-group v-model="formData.applicableGender">
  195. <el-radio :label="0">不限</el-radio>
  196. <el-radio :label="1">仅男</el-radio>
  197. <el-radio :label="2">仅女</el-radio>
  198. </el-radio-group>
  199. </el-form-item>
  200. </el-col>
  201. </el-row>
  202. <el-row :gutter="20">
  203. <el-col :span="12">
  204. <el-form-item label="适用年龄" prop="ageMin">
  205. <el-input-number v-model="formData.ageMin" :min="1" :max="formData.ageMax - 1" style="width:110px" />
  206. 岁 ~
  207. <el-input-number v-model="formData.ageMax" :min="formData.ageMin + 1" style="width:110px" />
  208. 岁
  209. </el-form-item>
  210. </el-col>
  211. <el-col :span="12">
  212. <el-form-item label="创作人" prop="authorName">
  213. <el-input v-model="formData.authorName" disabled placeholder="当前登录用户" />
  214. </el-form-item>
  215. </el-col>
  216. </el-row>
  217. <el-form-item label="适用症状" prop="symptomsList">
  218. <el-checkbox-group v-model="formData.symptomsList" class="symptom-checkboxes">
  219. <el-checkbox v-for="s in symptomsOptions" :key="s" :label="s" />
  220. </el-checkbox-group>
  221. <div v-if="dialogMode !== 'view'" class="symptom-add-row">
  222. <el-input
  223. v-model="customSymptom"
  224. placeholder="输入症状名称"
  225. maxlength="20"
  226. clearable
  227. @keyup.enter="addCustomSymptom"
  228. />
  229. <el-button type="primary" :icon="Plus" @click="addCustomSymptom">添加</el-button>
  230. </div>
  231. </el-form-item>
  232. <el-form-item label="方案描述">
  233. <el-input v-model="formData.description" type="textarea" :rows="2" maxlength="500" show-word-limit />
  234. </el-form-item>
  235. <!-- 灸方参数 -->
  236. <el-divider>灸方参数</el-divider>
  237. <div v-for="(step, index) in formData.steps" :key="index" class="step-row">
  238. <div class="step-header">
  239. <span class="step-num">参数 {{ index + 1 }}</span>
  240. <div v-if="dialogMode !== 'view'" class="step-actions">
  241. <el-tooltip content="上移参数" placement="top">
  242. <el-button
  243. size="small"
  244. :icon="ArrowUp"
  245. link
  246. :disabled="index === 0"
  247. aria-label="上移参数"
  248. @click="moveStep(index, -1)"
  249. />
  250. </el-tooltip>
  251. <el-tooltip content="下移参数" placement="top">
  252. <el-button
  253. size="small"
  254. :icon="ArrowDown"
  255. link
  256. :disabled="index === formData.steps.length - 1"
  257. aria-label="下移参数"
  258. @click="moveStep(index, 1)"
  259. />
  260. </el-tooltip>
  261. <el-button
  262. size="small"
  263. type="danger"
  264. link
  265. :disabled="formData.steps.length <= 1"
  266. @click="removeStep(index)"
  267. >删除</el-button>
  268. </div>
  269. </div>
  270. <el-row :gutter="12">
  271. <el-col :span="8">
  272. <el-form-item :label="'穴位'" :prop="`steps.${index}.acupointId`" :rules="stepRules.acupointId">
  273. <el-select
  274. v-model="step.acupointId"
  275. placeholder="请选择穴位"
  276. style="width:100%"
  277. filterable
  278. @change="(val) => onAcupointChange(val, index)"
  279. >
  280. <el-option
  281. v-for="a in acupointOptions"
  282. :key="a.id"
  283. :label="a.name"
  284. :value="a.id"
  285. />
  286. </el-select>
  287. </el-form-item>
  288. </el-col>
  289. <el-col :span="8">
  290. <el-form-item :label="'侧别'" :prop="`steps.${index}.side`" :rules="stepRules.side">
  291. <el-select v-model="step.side" placeholder="侧别" style="width:100%">
  292. <el-option
  293. v-for="opt in getSideOptions(step.acupointId)"
  294. :key="opt.value"
  295. :label="opt.label"
  296. :value="opt.value"
  297. />
  298. </el-select>
  299. </el-form-item>
  300. </el-col>
  301. <el-col :span="8">
  302. <el-form-item :label="'手法'" :prop="`steps.${index}.techniqueId`" :rules="stepRules.techniqueId">
  303. <el-select
  304. v-model="step.techniqueId"
  305. placeholder="请选择手法"
  306. style="width:100%"
  307. filterable
  308. @change="(val) => onTechniqueChange(val, index)"
  309. >
  310. <el-option
  311. v-for="t in techniqueOptions"
  312. :key="t.id"
  313. :label="t.name"
  314. :value="t.id"
  315. />
  316. </el-select>
  317. </el-form-item>
  318. </el-col>
  319. </el-row>
  320. <el-row :gutter="12">
  321. <el-col :span="8">
  322. <el-form-item :label="'温度(°C)'" :prop="`steps.${index}.temperature`" :rules="stepRules.temperature">
  323. <el-input-number v-model="step.temperature" :min="35" :max="50" :precision="1" style="width:100%" />
  324. </el-form-item>
  325. </el-col>
  326. <el-col :span="8">
  327. <el-form-item :label="'时间(分)'" :prop="`steps.${index}.duration`" :rules="stepRules.duration">
  328. <el-input-number v-model="step.duration" :min="1" :max="30" style="width:100%" />
  329. </el-form-item>
  330. </el-col>
  331. <el-col :span="8">
  332. <el-form-item label="备注">
  333. <el-input v-model="step.remark" placeholder="备注(选填)" maxlength="100" />
  334. </el-form-item>
  335. </el-col>
  336. </el-row>
  337. </div>
  338. <el-button
  339. v-if="dialogMode !== 'view'"
  340. type="primary"
  341. plain
  342. size="small"
  343. @click="addStep"
  344. style="margin-top:4px"
  345. >+ 添加参数</el-button>
  346. </el-form>
  347. <template #footer>
  348. <el-button @click="dialogVisible = false">{{ dialogMode === 'view' ? '关闭' : '取消' }}</el-button>
  349. <template v-if="dialogMode !== 'view'">
  350. <el-button v-if="!isSystemPresetPlan(formData)" :loading="submitLoading" @click="handleSubmit(0)">保存为草稿</el-button>
  351. <el-button type="primary" :loading="submitLoading" @click="handleSubmit(isSystemPresetPlan(formData) ? formData.status : 1)">
  352. {{ isSystemPresetPlan(formData) ? '保存修改' : '发布方案' }}
  353. </el-button>
  354. </template>
  355. </template>
  356. </el-dialog>
  357. <!-- 方案详情弹窗(只读) -->
  358. <el-dialog v-model="detailVisible" title="方案详情" width="700px" destroy-on-close :close-on-click-modal="false">
  359. <template v-if="detailData">
  360. <el-descriptions :column="2" border size="small">
  361. <el-descriptions-item label="方案编码">{{ detailData.planCode }}</el-descriptions-item>
  362. <el-descriptions-item label="方案名称">{{ detailData.name }}</el-descriptions-item>
  363. <el-descriptions-item label="模式类型">{{ modeTypeLabel(detailData.modeType) }}</el-descriptions-item>
  364. <el-descriptions-item label="作用类型">{{ detailData.effectType || '-' }}</el-descriptions-item>
  365. <el-descriptions-item label="创作人">{{ detailData.authorName || 'ADMIN' }}</el-descriptions-item>
  366. <el-descriptions-item label="状态">{{ statusLabel(detailData.status) }}</el-descriptions-item>
  367. <el-descriptions-item label="适用人群">{{ ['不限', '仅男', '仅女'][detailData.applicableGender] || '-' }}</el-descriptions-item>
  368. <el-descriptions-item label="适用年龄">{{ detailData.ageMin }}-{{ detailData.ageMax }}岁</el-descriptions-item>
  369. <el-descriptions-item label="适用症状" :span="2">{{ detailData.symptoms || '-' }}</el-descriptions-item>
  370. <el-descriptions-item label="方案描述" :span="2">{{ detailData.description || '-' }}</el-descriptions-item>
  371. <el-descriptions-item label="使用人数">{{ detailData.useCount || 0 }}人</el-descriptions-item>
  372. <el-descriptions-item label="平均评分">{{ detailData.avgRating ?? '-' }}分</el-descriptions-item>
  373. <el-descriptions-item label="创建时间">{{ formatDateTime(detailData.createTime) }}</el-descriptions-item>
  374. <el-descriptions-item label="更新时间">{{ formatDateTime(detailData.updateTime) }}</el-descriptions-item>
  375. </el-descriptions>
  376. <el-divider>灸方参数</el-divider>
  377. <el-table :data="detailData.steps || []" border size="small">
  378. <el-table-column prop="stepOrder" label="参数" width="60" align="center" />
  379. <el-table-column prop="acupointName" label="穴位" width="100" />
  380. <el-table-column label="侧别" width="80" align="center">
  381. <template #default="{ row }">{{ ['', '中心', '左侧', '右侧', '双侧'][row.side] || '-' }}</template>
  382. </el-table-column>
  383. <el-table-column prop="temperature" label="温度(°C)" width="90" align="center" />
  384. <el-table-column prop="duration" label="时间(分)" width="90" align="center" />
  385. <el-table-column prop="techniqueName" label="艾灸手法" width="100" />
  386. <el-table-column prop="remark" label="备注" min-width="100">
  387. <template #default="{ row }">{{ row.remark || '-' }}</template>
  388. </el-table-column>
  389. </el-table>
  390. </template>
  391. <template #footer>
  392. <el-button @click="detailVisible = false">关闭</el-button>
  393. </template>
  394. </el-dialog>
  395. </div>
  396. </template>
  397. <script setup>
  398. import { ref, reactive, computed, onMounted } from 'vue'
  399. import { ElMessage, ElMessageBox } from 'element-plus'
  400. import { Search, Refresh, Plus, Delete, ArrowUp, ArrowDown } from '@element-plus/icons-vue'
  401. import {
  402. getPlanPage,
  403. getPlanDetail,
  404. addPlan,
  405. updatePlan,
  406. deletePlan,
  407. batchDeletePlan,
  408. publishPlan,
  409. batchPublishPlan,
  410. offshelfPlan,
  411. batchOffshelfPlan,
  412. getPlanAuthors
  413. } from '@/api/plan'
  414. import { getAcupointList } from '@/api/acupoint'
  415. import { getTechniqueList } from '@/api/moxibustion'
  416. import { useUserStore } from '@/store/user'
  417. import { formatDateTime } from '@/utils/date'
  418. import { parsePageData } from '@/utils/pagination'
  419. // ============ 枚举常量 ============
  420. const effectOptions = ['驱寒', '祛湿', '祛风', '化瘀', '活血', '化痰', '养颜', '扶阳']
  421. const modeTypeOptions = [
  422. { label: '一键艾灸', value: 1 },
  423. { label: '专业模式', value: 2 },
  424. { label: '自定义模式', value: 3 },
  425. { label: '延年圣手', value: 4 }
  426. ]
  427. const addModeTypeOptions = modeTypeOptions.filter(item => [3, 4].includes(item.value))
  428. const defaultSymptomsOptions = ['怕冷', '感冒', '咳嗽', '痰多', '疼痛', '腰酸', '失眠', '疲劳', '皮肤暗沉', '手脚冰凉']
  429. const symptomsOptions = ref([...defaultSymptomsOptions])
  430. const systemPresetPlanCodes = Array.from({ length: 9 }, (_, index) => `S00${index + 1}`)
  431. const professionalPresetEffectMap = {
  432. S002: '驱寒',
  433. S003: '祛湿',
  434. S004: '祛风',
  435. S005: '化瘀',
  436. S006: '活血',
  437. S007: '化痰',
  438. S008: '养颜',
  439. S009: '扶阳'
  440. }
  441. const userStore = useUserStore()
  442. // ============ 选项列表(用于选择框) ============
  443. const acupointOptions = ref([])
  444. const techniqueOptions = ref([])
  445. const authorOptions = ref([])
  446. /**
  447. * 加载穴位、手法、创作人选项列表
  448. */
  449. async function loadOptions() {
  450. try {
  451. const [acupointRes, techniqueRes, authorRes] = await Promise.all([
  452. getAcupointList(),
  453. getTechniqueList(),
  454. getPlanAuthors().catch(() => ({ data: [] }))
  455. ])
  456. acupointOptions.value = acupointRes.data || []
  457. techniqueOptions.value = techniqueRes.data || []
  458. authorOptions.value = authorRes.data || []
  459. } catch (e) {
  460. // 选项加载失败不影响主流程
  461. }
  462. }
  463. /**
  464. * 模式类型标签文字
  465. */
  466. function modeTypeLabel(val) {
  467. return ['', '一键艾灸', '专业模式', '自定义模式', '延年圣手'][val] || '-'
  468. }
  469. /**
  470. * 模式类型 Tag 颜色
  471. */
  472. function modeTypeTag(val) {
  473. return ['', '', 'success', 'warning', 'danger'][val] || ''
  474. }
  475. /**
  476. * 状态标签文字
  477. */
  478. function statusLabel(val) {
  479. return { 0: '草稿', 1: '已发布', 2: '已下架' }[val] ?? '-'
  480. }
  481. /**
  482. * 状态 Tag 颜色
  483. */
  484. function statusTag(val) {
  485. return { 0: 'info', 1: 'success', 2: 'warning' }[val] ?? ''
  486. }
  487. function isSystemPresetPlan(plan) {
  488. return systemPresetPlanCodes.includes(plan?.planCode)
  489. }
  490. function canDeletePlan(plan) {
  491. return !isSystemPresetPlan(plan) && (plan?.status === 0 || plan?.status === 2)
  492. }
  493. function isOneClickPresetPlan(plan) {
  494. return plan?.planCode === 'S001'
  495. }
  496. function isProfessionalPresetPlan(plan) {
  497. return Boolean(professionalPresetEffectMap[plan?.planCode])
  498. }
  499. function getProfessionalPresetEffect(plan) {
  500. return professionalPresetEffectMap[plan?.planCode] || ''
  501. }
  502. function isRowSelectable(row) {
  503. return !isSystemPresetPlan(row)
  504. }
  505. // ============ 查询 ============
  506. const queryForm = reactive({
  507. name: '',
  508. modeType: null,
  509. effectType: '',
  510. authorName: '',
  511. status: null,
  512. createTimeStart: '',
  513. createTimeEnd: '',
  514. pageNum: 1,
  515. pageSize: 10
  516. })
  517. const dateRange = ref([])
  518. const tableData = ref([])
  519. const total = ref(0)
  520. const loading = ref(false)
  521. const selectedRows = ref([])
  522. const selectedIds = ref([])
  523. /**
  524. * 加载方案列表
  525. */
  526. async function loadData() {
  527. loading.value = true
  528. // 同步日期范围
  529. queryForm.createTimeStart = dateRange.value?.[0] || ''
  530. queryForm.createTimeEnd = dateRange.value?.[1] || ''
  531. try {
  532. const res = await getPlanPage(queryForm)
  533. const { records, total: pageTotal } = parsePageData(res.data)
  534. tableData.value = records
  535. total.value = pageTotal
  536. } finally {
  537. loading.value = false
  538. }
  539. }
  540. /**
  541. * 查询
  542. */
  543. function handleSearch() {
  544. queryForm.pageNum = 1
  545. loadData()
  546. }
  547. /**
  548. * 重置查询条件
  549. */
  550. function handleReset() {
  551. queryForm.name = ''
  552. queryForm.modeType = null
  553. queryForm.effectType = ''
  554. queryForm.authorName = ''
  555. queryForm.status = null
  556. queryForm.createTimeStart = ''
  557. queryForm.createTimeEnd = ''
  558. queryForm.pageNum = 1
  559. dateRange.value = []
  560. loadData()
  561. }
  562. /**
  563. * 多选变化
  564. */
  565. function handleSelectionChange(selection) {
  566. selectedRows.value = selection
  567. selectedIds.value = selection.map(r => r.id)
  568. }
  569. // ============ 新增/编辑弹窗 ============
  570. const dialogVisible = ref(false)
  571. const dialogTitle = ref('')
  572. const dialogMode = ref('add')
  573. const submitLoading = ref(false)
  574. const formRef = ref(null)
  575. const customSymptom = ref('')
  576. const defaultStep = () => ({
  577. acupointId: null,
  578. acupointName: '',
  579. side: 1,
  580. temperature: 42,
  581. duration: 5,
  582. techniqueId: null,
  583. techniqueName: '',
  584. remark: ''
  585. })
  586. const defaultForm = () => ({
  587. id: null,
  588. planCode: '',
  589. name: '',
  590. modeType: 3,
  591. effectType: '',
  592. symptomsList: [],
  593. symptoms: '',
  594. applicableGender: 0,
  595. ageMin: 1,
  596. ageMax: 120,
  597. authorId: getCurrentAuthorId(),
  598. authorName: getCurrentAuthorName(),
  599. authorType: getCurrentAuthorType(),
  600. status: 0,
  601. description: '',
  602. steps: [defaultStep()]
  603. })
  604. const formData = reactive(defaultForm())
  605. const formRules = {
  606. name: [{ required: true, message: '请输入方案名称', trigger: 'blur' }],
  607. modeType: [{ required: true, message: '请选择模式类型', trigger: 'change' }],
  608. effectType: [
  609. {
  610. validator: (_rule, value, callback) => {
  611. if (formData.modeType === 2 && !value) {
  612. callback(new Error('请选择作用类型'))
  613. return
  614. }
  615. callback()
  616. },
  617. trigger: 'change'
  618. }
  619. ]
  620. }
  621. const stepRules = {
  622. acupointId: [{ required: true, message: '请选择穴位', trigger: 'change' }],
  623. side: [{ required: true, message: '请选择侧别', trigger: 'change' }],
  624. temperature: [{ required: true, message: '请填写温度', trigger: 'blur' }],
  625. duration: [{ required: true, message: '请填写时间', trigger: 'blur' }],
  626. techniqueId: [{ required: true, message: '请选择艾灸手法', trigger: 'change' }]
  627. }
  628. const allSideOptions = [
  629. { label: '中心', value: 1 },
  630. { label: '左侧', value: 2 },
  631. { label: '右侧', value: 3 },
  632. { label: '双侧', value: 4 }
  633. ]
  634. /**
  635. * 根据穴位的单/双穴属性返回可选的侧别选项
  636. * - 单穴:只能选"中心"
  637. * - 双穴:不能选"中心"(左侧/右侧/双侧)
  638. */
  639. function getSideOptions(acupointId) {
  640. if (!acupointId) return allSideOptions
  641. const found = acupointOptions.value.find(a => a.id === acupointId)
  642. if (!found || !found.singleDouble) return allSideOptions
  643. if (found.singleDouble.includes('单')) {
  644. return allSideOptions.filter(opt => opt.value === 1)
  645. }
  646. if (found.singleDouble.includes('双')) {
  647. return allSideOptions.filter(opt => opt.value !== 1)
  648. }
  649. return allSideOptions
  650. }
  651. /**
  652. * 穴位选择变更:同步填充 acupointName,并根据单/双穴自动调整侧别
  653. */
  654. function onAcupointChange(id, index) {
  655. const found = acupointOptions.value.find(a => a.id === id)
  656. formData.steps[index].acupointName = found ? found.name : ''
  657. if (found && found.singleDouble) {
  658. if (found.singleDouble.includes('单') && formData.steps[index].side !== 1) {
  659. formData.steps[index].side = 1
  660. } else if (found.singleDouble.includes('双') && formData.steps[index].side === 1) {
  661. formData.steps[index].side = 4
  662. }
  663. }
  664. }
  665. /**
  666. * 手法选择变更:同步填充 techniqueName
  667. */
  668. function onTechniqueChange(id, index) {
  669. const found = techniqueOptions.value.find(t => t.id === id)
  670. formData.steps[index].techniqueName = found ? found.name : ''
  671. }
  672. function parseSymptoms(symptoms) {
  673. return (symptoms || '')
  674. .split(',')
  675. .map(item => item.trim())
  676. .filter(Boolean)
  677. .filter((item, index, list) => list.indexOf(item) === index)
  678. }
  679. function syncSymptomOptions(symptoms) {
  680. symptoms.forEach(item => {
  681. if (!symptomsOptions.value.includes(item)) {
  682. symptomsOptions.value.push(item)
  683. }
  684. })
  685. }
  686. function addCustomSymptom() {
  687. const symptom = customSymptom.value.trim()
  688. if (!symptom) {
  689. ElMessage.warning('请输入症状名称')
  690. return
  691. }
  692. if (/[,,]/.test(symptom)) {
  693. ElMessage.warning('症状名称不能包含逗号')
  694. return
  695. }
  696. syncSymptomOptions([symptom])
  697. if (!formData.symptomsList.includes(symptom)) {
  698. formData.symptomsList.push(symptom)
  699. }
  700. customSymptom.value = ''
  701. }
  702. function getCurrentAuthorId() {
  703. return userStore.userInfo?.userId || null
  704. }
  705. function getCurrentAuthorName() {
  706. return userStore.nickname || userStore.username || 'ADMIN'
  707. }
  708. function getCurrentAuthorType() {
  709. const typeMap = { 1: 2, 2: 3, 3: 1 }
  710. return typeMap[userStore.userInfo?.userType] || 1
  711. }
  712. function applyCurrentAuthor() {
  713. formData.authorId = getCurrentAuthorId()
  714. formData.authorName = getCurrentAuthorName()
  715. formData.authorType = getCurrentAuthorType()
  716. }
  717. const editableModeTypeOptions = computed(() => {
  718. if (dialogMode.value === 'add') {
  719. return addModeTypeOptions
  720. }
  721. if (isOneClickPresetPlan(formData)) {
  722. return modeTypeOptions.filter(item => item.value === 1)
  723. }
  724. if (isProfessionalPresetPlan(formData)) {
  725. return modeTypeOptions.filter(item => item.value === 2)
  726. }
  727. return addModeTypeOptions
  728. })
  729. const isModeTypeLocked = computed(() => (
  730. dialogMode.value === 'edit' && (isOneClickPresetPlan(formData) || isProfessionalPresetPlan(formData))
  731. ))
  732. const isPlanNameLocked = computed(() => dialogMode.value === 'edit' && isSystemPresetPlan(formData))
  733. const isEffectTypeLocked = computed(() => dialogMode.value === 'edit' && isProfessionalPresetPlan(formData))
  734. const showEffectTypeField = computed(() => formData.modeType === 2 && !isOneClickPresetPlan(formData))
  735. function applyPlanModeRules() {
  736. if (isOneClickPresetPlan(formData)) {
  737. formData.modeType = 1
  738. formData.effectType = ''
  739. return
  740. }
  741. if (isProfessionalPresetPlan(formData)) {
  742. formData.modeType = 2
  743. formData.effectType = getProfessionalPresetEffect(formData)
  744. return
  745. }
  746. if (![3, 4].includes(formData.modeType)) {
  747. formData.modeType = 3
  748. }
  749. if (formData.modeType !== 2) {
  750. formData.effectType = ''
  751. }
  752. }
  753. function handleModeTypeChange() {
  754. applyPlanModeRules()
  755. }
  756. /**
  757. * 添加一个灸方参数
  758. */
  759. function addStep() {
  760. formData.steps.push(defaultStep())
  761. }
  762. /**
  763. * 调整灸方参数顺序
  764. */
  765. function moveStep(index, direction) {
  766. const targetIndex = index + direction
  767. if (targetIndex < 0 || targetIndex >= formData.steps.length) return
  768. const [step] = formData.steps.splice(index, 1)
  769. formData.steps.splice(targetIndex, 0, step)
  770. formRef.value?.clearValidate?.()
  771. }
  772. /**
  773. * 删除某个灸方参数
  774. */
  775. function removeStep(index) {
  776. if (formData.steps.length <= 1) return
  777. formData.steps.splice(index, 1)
  778. formRef.value?.clearValidate?.()
  779. }
  780. /**
  781. * 打开新增弹窗
  782. */
  783. function handleAdd() {
  784. Object.assign(formData, defaultForm())
  785. formData.steps = [defaultStep()]
  786. customSymptom.value = ''
  787. applyCurrentAuthor()
  788. dialogTitle.value = '新增方案'
  789. dialogMode.value = 'add'
  790. applyPlanModeRules()
  791. dialogVisible.value = true
  792. }
  793. /**
  794. * 打开编辑弹窗
  795. */
  796. async function handleEdit(row) {
  797. const res = await getPlanDetail(row.id)
  798. const detail = res.data
  799. const symptomsList = parseSymptoms(detail.symptoms)
  800. syncSymptomOptions(symptomsList)
  801. Object.assign(formData, defaultForm(), {
  802. ...detail,
  803. symptomsList,
  804. steps: detail.steps?.length > 0 ? detail.steps : [defaultStep()]
  805. })
  806. customSymptom.value = ''
  807. applyCurrentAuthor()
  808. dialogTitle.value = '编辑方案'
  809. dialogMode.value = 'edit'
  810. applyPlanModeRules()
  811. dialogVisible.value = true
  812. }
  813. /**
  814. * 提交保存(0=草稿,1=发布)
  815. */
  816. async function handleSubmit(publishFlag) {
  817. applyPlanModeRules()
  818. await formRef.value.validate()
  819. applyCurrentAuthor()
  820. submitLoading.value = true
  821. try {
  822. const shouldPublish = !isSystemPresetPlan(formData) && publishFlag === 1
  823. const payload = {
  824. ...formData,
  825. symptoms: formData.symptomsList.join(','),
  826. status: publishFlag
  827. }
  828. if (formData.id) {
  829. await updatePlan(payload)
  830. if (shouldPublish) {
  831. await publishPlan(formData.id)
  832. }
  833. } else {
  834. const res = await addPlan(payload)
  835. if (shouldPublish) {
  836. if (!res.data) {
  837. throw new Error('未获取到新增方案ID,无法同步发布')
  838. }
  839. await publishPlan(res.data)
  840. }
  841. }
  842. ElMessage.success(shouldPublish ? '发布成功' : '操作成功')
  843. dialogVisible.value = false
  844. loadData()
  845. } finally {
  846. submitLoading.value = false
  847. }
  848. }
  849. // ============ 方案详情弹窗 ============
  850. const detailVisible = ref(false)
  851. const detailData = ref(null)
  852. /**
  853. * 查看方案详情
  854. */
  855. async function handleView(row) {
  856. const res = await getPlanDetail(row.id)
  857. detailData.value = res.data
  858. detailVisible.value = true
  859. }
  860. // ============ 状态操作 ============
  861. /**
  862. * 发布单条方案
  863. */
  864. async function handlePublish(row) {
  865. await ElMessageBox.confirm(`确认发布方案「${row.name}」吗?`, '提示', { type: 'warning' })
  866. await publishPlan(row.id)
  867. ElMessage.success('发布成功')
  868. loadData()
  869. }
  870. /**
  871. * 下架单条方案
  872. */
  873. async function handleOffshelf(row) {
  874. await ElMessageBox.confirm(`确认下架方案「${row.name}」吗?`, '提示', { type: 'warning' })
  875. await offshelfPlan(row.id)
  876. ElMessage.success('下架成功')
  877. loadData()
  878. }
  879. /**
  880. * 批量发布
  881. */
  882. async function handleBatchPublish() {
  883. await ElMessageBox.confirm(`确认批量发布选中的 ${selectedIds.value.length} 条方案吗?`, '批量发布', { type: 'warning' })
  884. await batchPublishPlan(selectedIds.value)
  885. ElMessage.success('批量发布成功')
  886. loadData()
  887. }
  888. /**
  889. * 批量下架
  890. */
  891. async function handleBatchOffshelf() {
  892. await ElMessageBox.confirm(`确认批量下架选中的 ${selectedIds.value.length} 条方案吗?`, '批量下架', { type: 'warning' })
  893. await batchOffshelfPlan(selectedIds.value)
  894. ElMessage.success('批量下架成功')
  895. loadData()
  896. }
  897. /**
  898. * 删除单条方案
  899. */
  900. async function handleDelete(row) {
  901. await ElMessageBox.confirm(`确认删除方案「${row.name}」吗?`, '提示', { type: 'warning' })
  902. await deletePlan(row.id)
  903. ElMessage.success('删除成功')
  904. loadData()
  905. }
  906. /**
  907. * 批量删除
  908. */
  909. async function handleBatchDelete() {
  910. if (selectedRows.value.some(row => !canDeletePlan(row))) {
  911. ElMessage.warning('仅草稿或已下架方案可删除,请先下架已发布方案')
  912. return
  913. }
  914. await ElMessageBox.confirm(
  915. `确认批量删除选中的 ${selectedIds.value.length} 条方案吗?(仅草稿或已下架状态可删)`,
  916. '批量删除确认',
  917. { type: 'warning', confirmButtonText: '确认删除', cancelButtonText: '取消' }
  918. )
  919. await batchDeletePlan(selectedIds.value)
  920. ElMessage.success('批量删除成功')
  921. selectedRows.value = []
  922. selectedIds.value = []
  923. loadData()
  924. }
  925. onMounted(() => {
  926. loadData()
  927. loadOptions()
  928. })
  929. </script>
  930. <style lang="scss" scoped>
  931. .page-container {
  932. display: flex;
  933. flex-direction: column;
  934. gap: 16px;
  935. }
  936. .search-card {
  937. :deep(.el-card__body) {
  938. padding: 16px 20px 4px;
  939. }
  940. }
  941. .table-card {
  942. .card-header {
  943. display: flex;
  944. align-items: center;
  945. justify-content: space-between;
  946. .title {
  947. font-weight: 600;
  948. font-size: 15px;
  949. }
  950. .btn-group {
  951. display: flex;
  952. gap: 8px;
  953. align-items: center;
  954. }
  955. }
  956. }
  957. .pagination {
  958. margin-top: 16px;
  959. justify-content: flex-end;
  960. }
  961. .symptom-checkboxes {
  962. display: flex;
  963. flex-wrap: wrap;
  964. gap: 0 20px;
  965. }
  966. .symptom-add-row {
  967. display: flex;
  968. gap: 8px;
  969. width: 360px;
  970. max-width: 100%;
  971. margin-top: 8px;
  972. }
  973. .step-row {
  974. border: 1px solid #ebeef5;
  975. border-radius: 6px;
  976. padding: 12px 16px 0;
  977. margin-bottom: 12px;
  978. background: #fafafa;
  979. .step-header {
  980. display: flex;
  981. align-items: center;
  982. justify-content: space-between;
  983. margin-bottom: 8px;
  984. .step-num {
  985. font-weight: 600;
  986. color: #409eff;
  987. font-size: 13px;
  988. }
  989. .step-actions {
  990. display: flex;
  991. align-items: center;
  992. gap: 8px;
  993. :deep(.el-button + .el-button) {
  994. margin-left: 0;
  995. }
  996. }
  997. }
  998. }
  999. </style>