TaskExecutionDialog.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <el-dialog
  3. v-model="dialogVisible"
  4. :title="readonly ? `任务详情 — ${taskName}` : `任务执行 — ${taskName}`"
  5. width="96vw"
  6. class="dialog-form-layout execution-dialog"
  7. align-center
  8. destroy-on-close
  9. :close-on-click-modal="false"
  10. @close="handleClose"
  11. >
  12. <!-- 顶部:任务基本信息一行展示 -->
  13. <div v-if="editor.taskDetail.value" class="execution-header">
  14. <div class="execution-header-row">
  15. <span class="execution-header-item">任务号:<b>{{ editor.taskDetail.value.taskNo }}</b></span>
  16. <span class="execution-header-item">工单号:{{ editor.taskDetail.value.workOrderNo || '—' }}</span>
  17. <span class="execution-header-item">任务名称:{{ editor.taskDetail.value.taskName || '—' }}</span>
  18. <el-tag :type="editor.taskStatusTag(editor.taskDetail.value.taskStatus).type">
  19. {{ editor.taskStatusTag(editor.taskDetail.value.taskStatus).label }}
  20. </el-tag>
  21. <div v-if="!readonly" class="execution-header-actions">
  22. <el-button
  23. v-if="editor.taskDetail.value.taskStatus === 'dpz'"
  24. class="btn-main"
  25. type="primary"
  26. size="small"
  27. @click="editor.handleStartTask"
  28. >
  29. <el-icon><VideoPlay /></el-icon>开始执行
  30. </el-button>
  31. <el-button
  32. v-if="editor.taskDetail.value.taskStatus === 'jxz'"
  33. class="btn-main"
  34. type="success"
  35. size="small"
  36. @click="editor.handleCompleteTask"
  37. >
  38. <el-icon><Check /></el-icon>完成任务
  39. </el-button>
  40. </div>
  41. </div>
  42. <div v-if="editor.taskDetail.value.remark" class="execution-header-remark">{{ editor.taskDetail.value.remark }}</div>
  43. </div>
  44. <!-- 主体:可折叠工艺库 + 步骤列表 + 详情面板 -->
  45. <div class="execution-main">
  46. <!-- 可折叠工艺库侧栏(只读时隐藏) -->
  47. <template v-if="!readonly">
  48. <transition name="slide-lib">
  49. <div v-show="editor.processLibraryExpanded.value" class="execution-lib-panel">
  50. <div class="execution-lib-header">
  51. <h3>工艺库</h3>
  52. <el-input v-model="editor.processSearchKeyword.value" placeholder="搜索工序" clearable size="small" class="route-config-search" />
  53. </div>
  54. <el-collapse v-model="editor.expandedCategories.value" class="route-config-collapse">
  55. <el-collapse-item v-for="cat in editor.filteredProcessLibrary.value" :key="cat.categoryId" :name="cat.categoryId">
  56. <template #title>
  57. <span class="route-config-cat-bar"></span>
  58. <span>{{ cat.categoryName }}</span>
  59. </template>
  60. <div v-for="(proc, procIndex) in cat.processes" :key="proc.id" class="route-config-process-card" draggable="true" @dragstart="editor.onDragStart($event, proc)">
  61. <div class="route-config-process-info">
  62. <div class="route-config-process-name">
  63. <span class="route-config-process-seq">{{ procIndex + 1 }}</span>{{ proc.processName }}
  64. </div>
  65. <div class="route-config-process-code">{{ proc.processCode }}</div>
  66. </div>
  67. <el-icon class="route-config-process-drag"><Rank /></el-icon>
  68. </div>
  69. <el-empty v-if="!cat.processes.length" description="该分类暂无工序" :image-size="32" />
  70. </el-collapse-item>
  71. </el-collapse>
  72. <el-empty v-if="!editor.filteredProcessLibrary.value.length" description="暂无工艺数据" :image-size="48" />
  73. </div>
  74. </transition>
  75. <!-- 工艺库折叠把手 -->
  76. <div class="execution-lib-toggle" @click="editor.processLibraryExpanded.value = !editor.processLibraryExpanded.value">
  77. <span>{{ editor.processLibraryExpanded.value ? '‹' : '›' }}</span>
  78. <span class="execution-lib-toggle-text">工艺库</span>
  79. </div>
  80. </template>
  81. <!-- 步骤列表 -->
  82. <div class="execution-step-list" v-loading="editor.stepListLoading.value" @dragover.prevent @drop="editor.onDropToCenter">
  83. <div class="execution-step-list-header">
  84. <h3>工序步骤</h3>
  85. <span class="execution-progress-badge">{{ editor.completedStepCount.value }}/{{ editor.stepList.value.length }}</span>
  86. </div>
  87. <div class="execution-step-list-body">
  88. <!-- 虚拟步骤:任务输入 -->
  89. <div
  90. class="virtual-step-card"
  91. :class="{ 'is-active': editor.selectedVirtualStep.value === 'input' }"
  92. @click="editor.selectVirtualStep('input')"
  93. >
  94. <div class="virtual-step-icon virtual-step-icon--input">📥</div>
  95. <div class="virtual-step-info">
  96. <div class="virtual-step-name">任务输入</div>
  97. </div>
  98. <el-tag v-if="editor.virtualInputStatus.value === 'filled'" type="success" size="small">已填写 {{ editor.taskInputs.value.length }} 项</el-tag>
  99. <el-tag v-else type="danger" size="small">未填写</el-tag>
  100. </div>
  101. <!-- 虚拟步骤:任务输出 -->
  102. <div
  103. class="virtual-step-card"
  104. :class="{ 'is-active': editor.selectedVirtualStep.value === 'output' }"
  105. @click="editor.selectVirtualStep('output')"
  106. >
  107. <div class="virtual-step-icon virtual-step-icon--output">📤</div>
  108. <div class="virtual-step-info">
  109. <div class="virtual-step-name">任务输出</div>
  110. </div>
  111. <el-tag v-if="editor.virtualOutputStatus.value === 'filled'" type="success" size="small">已填写 {{ editor.taskOutputs.value.length }} 项</el-tag>
  112. <el-tag v-else type="danger" size="small">未填写</el-tag>
  113. </div>
  114. <!-- 分割线 -->
  115. <div class="step-divider"><span>工艺步骤</span></div>
  116. <!-- 真实步骤列表 -->
  117. <draggable v-model="editor.stepList.value" :handle="readonly ? undefined : '.route-config-step-handle'" :animation="200" @end="editor.onStepDragEnd">
  118. <div
  119. v-for="(element, index) in editor.stepList.value"
  120. :key="element.id"
  121. class="route-config-step-card"
  122. :class="{
  123. 'is-active': editor.selectedStepId.value === element.id,
  124. 'is-done': element.stepStatus === 'ywc'
  125. }"
  126. @click="editor.selectStep(element)"
  127. >
  128. <div v-if="!readonly" class="route-config-step-handle"><el-icon><Rank /></el-icon></div>
  129. <div class="route-config-step-order" :class="stepSeqClass(element.stepStatus)">{{ element.stepStatus === 'ywc' ? '✓' : index + 1 }}</div>
  130. <div class="route-config-step-info">
  131. <div class="route-config-step-name">{{ element.processName || '未命名步骤' }}</div>
  132. <div class="route-config-step-desc">{{ element.description || '' }}</div>
  133. </div>
  134. <el-tag v-if="element.stepStatus" :type="editor.stepStatusTag(element.stepStatus).type" size="small" style="margin-right:4px">{{ editor.stepStatusTag(element.stepStatus).label }}</el-tag>
  135. <template v-if="!readonly">
  136. <el-button link type="primary" size="small" title="复制步骤" @click.stop="editor.handleCopyStep(element)">
  137. <el-icon><CopyDocument /></el-icon>
  138. </el-button>
  139. <el-button link type="danger" size="small" @click.stop="editor.handleDeleteStep(element)">
  140. <el-icon><Delete /></el-icon>
  141. </el-button>
  142. </template>
  143. </div>
  144. </draggable>
  145. <div v-if="!editor.stepList.value.length" class="execution-step-list-empty">
  146. <el-icon :size="32" color="#a7f3d0"><Plus /></el-icon>
  147. <p>从左侧拖拽工序到此处,添加任务步骤</p>
  148. </div>
  149. </div>
  150. </div>
  151. <!-- 右侧详情面板 -->
  152. <div class="execution-detail-panel">
  153. <!-- 任务输入详情 -->
  154. <template v-if="editor.selectedVirtualStep.value === 'input'">
  155. <div class="execution-detail-header">
  156. <h3>📥 任务输入</h3>
  157. <div v-if="!readonly" class="execution-detail-actions">
  158. <el-button class="btn-main" type="primary" size="small" @click="editor.addTaskInputRow"><el-icon><Plus /></el-icon>添加输入</el-button>
  159. <el-button class="btn-main" type="primary" size="small" :loading="editor.inputSaving.value" @click="editor.saveTaskInputs"><el-icon><Check /></el-icon>保存</el-button>
  160. </div>
  161. </div>
  162. <div class="execution-detail-body">
  163. <el-table :data="editor.taskInputs.value" stripe class="inner-table">
  164. <el-table-column type="index" label="序号" width="56" align="center" :index="(i: number) => i + 1" />
  165. <el-table-column label="输入类型" min-width="120" align="center">
  166. <template #default="{ row }">
  167. <span v-if="readonly">{{ row.inputType === 'sample' ? '样本' : row.inputType === 'cell_product' ? '细胞产品' : row.inputType }}</span>
  168. <el-select v-else v-model="row.inputType" placeholder="选择类型" class="inner-cell-select" @change="() => { row.inputId = ''; row.inputCode = ''; row.inputName = '' }">
  169. <el-option label="样本" value="sample" />
  170. <el-option label="细胞产品" value="cell_product" />
  171. </el-select>
  172. </template>
  173. </el-table-column>
  174. <el-table-column label="输入编码" min-width="150" align="center">
  175. <template #default="{ row }">
  176. <template v-if="row.inputType === 'cell_product'">
  177. <el-select
  178. v-if="!readonly"
  179. v-model="row.inputId"
  180. placeholder="选择细胞产品"
  181. filterable
  182. class="inner-cell-select"
  183. :loading="editor.cellProductOptionsLoading.value"
  184. @change="(val: string) => editor.onCellProductInputSelect(row, val)"
  185. >
  186. <el-option v-for="opt in editor.cellProductOptions.value" :key="opt.id" :label="opt.label" :value="opt.id" />
  187. </el-select>
  188. <span v-else>{{ row.inputCode || '—' }}</span>
  189. </template>
  190. <template v-else>
  191. <span>{{ row.inputCode || '—' }}</span>
  192. </template>
  193. </template>
  194. </el-table-column>
  195. <el-table-column label="输入名称" min-width="150" align="center">
  196. <template #default="{ row }">
  197. <span v-if="readonly">{{ row.inputName || '—' }}</span>
  198. <el-input v-else v-model="row.inputName" placeholder="输入名称" class="inner-cell-input" />
  199. </template>
  200. </el-table-column>
  201. <el-table-column label="备注" min-width="120" align="center">
  202. <template #default="{ row }">
  203. <span v-if="readonly">{{ row.remark || '—' }}</span>
  204. <el-input v-else v-model="row.remark" placeholder="备注" class="inner-cell-input" />
  205. </template>
  206. </el-table-column>
  207. <el-table-column v-if="!readonly" label="操作" width="80" align="center">
  208. <template #default="{ $index }">
  209. <el-button link type="danger" size="small" @click="editor.removeTaskInputRow($index)">删除</el-button>
  210. </template>
  211. </el-table-column>
  212. </el-table>
  213. <el-empty v-if="!editor.taskInputs.value.length" description="暂无输入项" :image-size="48" />
  214. </div>
  215. </template>
  216. <!-- 任务输出详情 -->
  217. <template v-else-if="editor.selectedVirtualStep.value === 'output'">
  218. <div class="execution-detail-header">
  219. <h3>📤 任务输出</h3>
  220. <div v-if="!readonly" class="execution-detail-actions">
  221. <el-button class="btn-main" type="primary" size="small" @click="editor.addTaskOutputRow"><el-icon><Plus /></el-icon>添加输出</el-button>
  222. <el-button class="btn-main" type="primary" size="small" :loading="editor.outputSaving.value" @click="editor.saveTaskOutputs"><el-icon><Check /></el-icon>保存</el-button>
  223. </div>
  224. </div>
  225. <div class="execution-detail-body">
  226. <el-table :data="editor.taskOutputs.value" stripe class="inner-table">
  227. <el-table-column type="index" label="序号" width="56" align="center" :index="(i: number) => i + 1" />
  228. <el-table-column label="输出名称" min-width="140" align="center">
  229. <template #default="{ row }">
  230. <span v-if="readonly">{{ row.outputName || '—' }}</span>
  231. <el-input v-else v-model="row.outputName" placeholder="输出名称" class="inner-cell-input" />
  232. </template>
  233. </el-table-column>
  234. <el-table-column label="输出条码" min-width="140" align="center">
  235. <template #default="{ row }">
  236. <span v-if="readonly">{{ row.outputBarcode || '—' }}</span>
  237. <el-input v-else v-model="row.outputBarcode" placeholder="扫码或输入" class="inner-cell-input" />
  238. </template>
  239. </el-table-column>
  240. <el-table-column label="数量" min-width="100" align="center">
  241. <template #default="{ row }">
  242. <span v-if="readonly">{{ row.quantity ?? '—' }}</span>
  243. <el-input-number v-else v-model="row.quantity" :min="0" :precision="2" controls-position="right" style="width: 100%" />
  244. </template>
  245. </el-table-column>
  246. <el-table-column label="单位" min-width="80" align="center">
  247. <template #default="{ row }">
  248. <span v-if="readonly">{{ row.unit || '—' }}</span>
  249. <el-input v-else v-model="row.unit" placeholder="单位" class="inner-cell-input" />
  250. </template>
  251. </el-table-column>
  252. <el-table-column label="备注" min-width="120" align="center">
  253. <template #default="{ row }">
  254. <span v-if="readonly">{{ row.remark || '—' }}</span>
  255. <el-input v-else v-model="row.remark" placeholder="备注" class="inner-cell-input" />
  256. </template>
  257. </el-table-column>
  258. <el-table-column v-if="!readonly" label="操作" width="80" align="center">
  259. <template #default="{ $index }">
  260. <el-button link type="danger" size="small" @click="editor.removeTaskOutputRow($index)">删除</el-button>
  261. </template>
  262. </el-table-column>
  263. </el-table>
  264. <el-empty v-if="!editor.taskOutputs.value.length" description="暂无输出项" :image-size="48" />
  265. </div>
  266. </template>
  267. <!-- 步骤详情 -->
  268. <template v-else>
  269. <StepDetailPanel :editor="editor" :readonly="readonly" />
  270. </template>
  271. </div>
  272. </div>
  273. </el-dialog>
  274. </template>
  275. <script setup lang="ts">
  276. import { Rank, Plus, Check, VideoPlay, CopyDocument, Delete } from '@element-plus/icons-vue'
  277. import { VueDraggable as draggable } from 'vue-draggable-plus'
  278. import { useTaskStepEditor } from './useTaskStepEditor'
  279. import StepDetailPanel from './StepDetailPanel.vue'
  280. const props = defineProps<{
  281. visible: boolean
  282. taskId: string
  283. taskName: string
  284. readonly?: boolean
  285. }>()
  286. const emit = defineEmits<{
  287. (e: 'update:visible', val: boolean): void
  288. (e: 'success'): void
  289. }>()
  290. const dialogVisible = computed({
  291. get: () => props.visible,
  292. set: (val) => emit('update:visible', val)
  293. })
  294. const editor = useTaskStepEditor()
  295. function handleClose() {
  296. dialogVisible.value = false
  297. emit('success')
  298. }
  299. function stepSeqClass(status: string) {
  300. if (status === 'ywc') return 'seq-done'
  301. if (status === 'jxz') return 'seq-running'
  302. return 'seq-pending'
  303. }
  304. watch(() => props.visible, async (val) => {
  305. if (val && props.taskId) {
  306. await editor.initEditor(props.taskId, { mode: 'execution' })
  307. }
  308. })
  309. </script>
  310. <style scoped lang="scss">
  311. @use '../../../styles/route-config' as *;
  312. .execution-dialog {
  313. :deep(.el-dialog) {
  314. margin: 2vh auto !important;
  315. }
  316. :deep(.el-dialog__body) {
  317. max-height: calc(96vh - 54px);
  318. overflow-y: auto;
  319. padding: 10px 14px;
  320. }
  321. }
  322. /* 顶部信息 */
  323. .execution-header {
  324. padding: 6px 16px;
  325. background: #f0fdf4;
  326. border-radius: 6px;
  327. margin-bottom: 8px;
  328. border: 1px solid #d1fae5;
  329. }
  330. .execution-header-row {
  331. display: flex; align-items: center; gap: 16px;
  332. font-size: 13px; color: #475569;
  333. b { color: #1e293b; }
  334. }
  335. .execution-header-item { white-space: nowrap; }
  336. .execution-header-actions { display: flex; gap: 8px; margin-left: auto; }
  337. .execution-header-remark { margin-top: 4px; font-size: 12px; color: #64748b; }
  338. /* 主体三区域 */
  339. .execution-main {
  340. display: flex; gap: 0;
  341. height: calc(96vh - 110px);
  342. min-height: 400px;
  343. }
  344. /* 工艺库折叠侧栏 */
  345. .execution-lib-panel {
  346. width: 260px; flex-shrink: 0;
  347. display: flex; flex-direction: column;
  348. border: 1px solid #e5e7eb; border-radius: 8px;
  349. overflow: hidden;
  350. }
  351. .execution-lib-header {
  352. padding: 10px 12px; border-bottom: 1px solid #e5e7eb; flex-shrink: 0;
  353. h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: #1f2937; }
  354. }
  355. .slide-lib-enter-active, .slide-lib-leave-active {
  356. transition: width 0.2s ease, opacity 0.2s ease;
  357. overflow: hidden;
  358. }
  359. .slide-lib-enter-from, .slide-lib-leave-to {
  360. width: 0 !important; opacity: 0;
  361. }
  362. /* 工艺库折叠把手 */
  363. .execution-lib-toggle {
  364. width: 24px; flex-shrink: 0;
  365. display: flex; flex-direction: column;
  366. align-items: center; justify-content: center;
  367. gap: 4px; cursor: pointer;
  368. background: #f9fafb; border-left: 1px solid #e5e7eb; border-right: 1px solid #e5e7eb;
  369. transition: background 0.15s;
  370. font-size: 14px; color: #9ca3af;
  371. &:hover { background: #ecfdf5; color: #10b981; }
  372. }
  373. .execution-lib-toggle-text {
  374. writing-mode: vertical-lr; font-size: 11px; letter-spacing: 2px;
  375. }
  376. /* 步骤列表 */
  377. .execution-step-list {
  378. width: 340px; flex-shrink: 0;
  379. display: flex; flex-direction: column;
  380. border: 1px solid #e5e7eb; border-radius: 8px;
  381. overflow: hidden; margin: 0 8px;
  382. }
  383. .execution-step-list-header {
  384. padding: 10px 14px; border-bottom: 1px solid #e5e7eb;
  385. display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
  386. h3 { margin: 0; font-size: 14px; font-weight: 600; color: #1f2937; }
  387. }
  388. .execution-progress-badge {
  389. font-size: 12px; color: #6b7280; background: #f3f4f6;
  390. padding: 2px 10px; border-radius: 10px;
  391. }
  392. .execution-step-list-body {
  393. flex: 1; overflow-y: auto; padding: 8px;
  394. }
  395. .execution-step-list-empty {
  396. display: flex; flex-direction: column;
  397. align-items: center; justify-content: center;
  398. padding: 40px 0; color: #9ca3af;
  399. p { margin-top: 8px; font-size: 13px; }
  400. }
  401. /* 虚拟步骤卡片 */
  402. .virtual-step-card {
  403. display: flex; align-items: center; gap: 10px;
  404. padding: 10px 12px; margin-bottom: 4px;
  405. border-radius: 8px; cursor: pointer;
  406. border: 2px solid #bfdbfe; background: #eff6ff;
  407. transition: all 0.15s;
  408. &:hover { border-color: #93c5fd; background: #dbeafe; }
  409. &.is-active { border-color: #3b82f6; background: #dbeafe; box-shadow: 0 0 0 1px #3b82f6; }
  410. }
  411. .virtual-step-icon {
  412. width: 28px; height: 28px; border-radius: 6px;
  413. display: flex; align-items: center; justify-content: center;
  414. font-size: 14px; flex-shrink: 0;
  415. &--input { background: #dbeafe; }
  416. &--output { background: #fef3c7; }
  417. }
  418. .virtual-step-info { flex: 1; min-width: 0; }
  419. .virtual-step-name { font-size: 13px; font-weight: 500; color: #1e293b; }
  420. /* 分割线 */
  421. .step-divider {
  422. display: flex; align-items: center; gap: 8px;
  423. margin: 8px 0; padding: 0 4px;
  424. color: #9ca3af; font-size: 11px;
  425. &::before, &::after { content: ''; flex: 1; height: 1px; background: #e5e7eb; }
  426. }
  427. /* 步骤序号状态 */
  428. .seq-done { background: #d1fae5 !important; color: #059669 !important; }
  429. .seq-running { background: #10b981 !important; color: #fff !important; }
  430. .seq-pending { background: #f3f4f6 !important; color: #6b7280 !important; }
  431. .route-config-step-card.is-done { opacity: 0.6; }
  432. /* 右侧详情面板 */
  433. .execution-detail-panel {
  434. flex: 1; min-width: 0;
  435. display: flex; flex-direction: column;
  436. border: 1px solid #e5e7eb; border-radius: 8px;
  437. overflow: hidden;
  438. }
  439. .execution-detail-header {
  440. padding: 10px 16px; border-bottom: 1px solid #e5e7eb;
  441. display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
  442. h3 { margin: 0; font-size: 14px; font-weight: 600; color: #1e293b; }
  443. }
  444. .execution-detail-actions { display: flex; gap: 8px; }
  445. .execution-detail-body {
  446. flex: 1; overflow-y: auto; padding: 16px;
  447. }
  448. .section-bar {
  449. display: inline-block; width: 3px; height: 14px;
  450. background: #10b981; border-radius: 2px; margin-right: 8px;
  451. }
  452. </style>