index.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. <template>
  2. <el-row :gutter="20" class="standard-class-list">
  3. <div class="left-tree">
  4. <el-tree
  5. :data="getPressureEquipmentCategory"
  6. node-key="value"
  7. default-expand-all
  8. :highlight-current="false"
  9. :expand-on-click-node="false"
  10. :icon="''"
  11. :draggable="true"
  12. @node-click="handleNodeClick"
  13. >
  14. <template #default="{ data }">
  15. <div class="class-content">
  16. <el-icon size="16" color="#015293">
  17. <Management/>
  18. </el-icon>
  19. <span class="custom-tree-node">
  20. {{ data.label }}
  21. </span>
  22. </div>
  23. </template>
  24. </el-tree>
  25. </div>
  26. <div class="right-table">
  27. <!-- 搜索表单 -->
  28. <!-- <el-form :inline="true" :model="searchForm" class="search-form">
  29. <el-form-item label="检验性质">
  30. <el-select v-model="searchForm.inspectionNature" placeholder="请选择" clearable
  31. style="width: 180px">
  32. <el-option
  33. v-for="item in pressureInspectionNature"
  34. :key="item.value"
  35. :label="item.label"
  36. :value="item.value"
  37. />
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button type="primary" @click="fetchInspectionNatureList">查询</el-button>
  42. <el-button @click="handleReset">重置</el-button>
  43. </el-form-item>
  44. </el-form>-->
  45. <!-- 操作按钮 -->
  46. <div class="table-buttons">
  47. <el-button type="primary" @click="handleCreateOrEditInspectionNature()">新增</el-button>
  48. <el-button type="danger" @click="handleDeleteInspectionNature">删除</el-button>
  49. </div>
  50. <!-- 数据表格 -->
  51. <el-table
  52. ref="tableRef"
  53. :data="inspectionNatureList"
  54. border
  55. @selection-change="handleSelectionChange"
  56. >
  57. <el-table-column type="selection" width="50" align="center"/>
  58. <el-table-column label="检验性质" prop="inspectionNature" min-width="120">
  59. <template #default="{ row }">
  60. {{
  61. getPressureInspectionNatureType[row.equipmentCategory]?.find(x => x.value === row.inspectionNature)?.label || '-'
  62. }}
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="所属设备" prop="equipmentCategory" min-width="100">
  66. <template #default="{ row }">
  67. {{
  68. getPressureEquipmentCategory[0].children.find(x => x.value === row.equipmentCategory)?.label || '-'
  69. }}
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="设备类型" prop="equipmentType" min-width="120">
  73. <template #default="{ row }">
  74. {{
  75. getPressureEquipType[row.equipmentCategory]?.find(x => x.value === row.equipmentType)?.label || '-'
  76. }}
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="默认报告模板数" prop="defaultTemplateCount" min-width="120"/>
  80. <el-table-column label="关联报告模板数" prop="templateCount" min-width="120"/>
  81. <el-table-column label="最近修改人" prop="updaterName" min-width="100"/>
  82. <el-table-column label="最近修改时间" prop="updateTime" min-width="160">
  83. <template #default="{ row }">
  84. {{ row.updateTime ? dayjs(row.updateTime).format('YYYY-MM-DD HH:mm:ss') : '' }}
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" width="80" fixed="right">
  88. <template #default="{ row }">
  89. <el-button link type="primary" @click="handleCreateOrEditInspectionNature(row)">编辑
  90. </el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <!-- 分页 -->
  95. <el-pagination
  96. v-model:current-page="pageNo"
  97. v-model:page-size="pageSize"
  98. :total="total"
  99. :page-sizes="[10, 20, 50, 100]"
  100. layout="total, sizes, prev, pager, next, jumper"
  101. @current-change="fetchInspectionNatureList"
  102. @size-change="fetchInspectionNatureList"
  103. class="pagination"
  104. />
  105. </div>
  106. </el-row>
  107. <CustomDialog
  108. v-model="inspectionNatureCreateOrEditDialog"
  109. :title="(editType === 'edit' ? '编辑' : '添加') + '检验性质'"
  110. width="1200px"
  111. style="padding-right: 40px;"
  112. :showFooter="false"
  113. @cancel="handleInspectionNatureDialogClose"
  114. >
  115. <el-form ref="inspectionNatureFormRef" :model="inspectionNatureForm"
  116. :rules="inspectionNatureFormRules"
  117. label-width="110px">
  118. <el-row :gutter="20">
  119. <el-col :span="8">
  120. <el-form-item label="所属设备" prop="equipmentCategory">
  121. <el-select v-model="inspectionNatureForm.equipmentCategory" placeholder="请选择所属设备"
  122. @change="handleEquipmentCategoryChange">
  123. <el-option
  124. v-for="item in getPressureEquipmentCategory[0].children"
  125. :key="item.value"
  126. :label="item.label"
  127. :value="item.value"
  128. />
  129. </el-select>
  130. </el-form-item>
  131. </el-col>
  132. <el-col :span="8">
  133. <el-form-item label="检验性质" prop="inspectionNature" >
  134. <el-select v-model="inspectionNatureForm.inspectionNature" placeholder="请选择检验性质">
  135. <el-option
  136. v-for="item in getPressureInspectionNature"
  137. :key="item.value"
  138. :label="item.label"
  139. :value="item.value"
  140. />
  141. </el-select>
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="8">
  145. <el-form-item label="设备类型" prop="equipmentType">
  146. <el-select v-model="inspectionNatureForm.equipmentType" placeholder="请选择设备类型">
  147. <el-option
  148. v-for="item in getPressureEquipContainerType"
  149. :key="item.value"
  150. :label="item.label"
  151. :value="item.value"
  152. />
  153. </el-select>
  154. </el-form-item>
  155. </el-col>
  156. </el-row>
  157. <el-form-item label="检验项目" prop="templateSaveReqVOList">
  158. <!-- <el-select readonly placeholder="请选择关联报告模板" @click.stop.prevent="handleShowReportList"/> -->
  159. <el-select
  160. :model-value="getTemplateNames"
  161. clearable
  162. multiple
  163. @remove-tag="handleRemoveTag"
  164. @click.stop.prevent="() => handleShowReportList()"
  165. @clear="handleClearSelectedItem"
  166. placeholder="请选择检验项目"
  167. />
  168. <!-- <div class="custom-select" @click.stop.prevent="handleShowReportList">
  169. <el-input readonly placeholder="请选择关联报告模板"/>
  170. <el-icon size="14"><ArrowDown /></el-icon>
  171. </div> -->
  172. </el-form-item>
  173. </el-form>
  174. <el-table ref="sortTableRef" :data="inspectionNatureForm.templateSaveReqVOList" row-key="templateId">
  175. <el-table-column label="" width="40" align="center">
  176. <template #default>
  177. <div class="drag-handle">
  178. <el-icon style="cursor: move; color: #909399"><Menu /></el-icon>
  179. </div>
  180. </template>
  181. </el-table-column>
  182. <el-table-column label="检验项目名称" prop="name">
  183. <template #default="{ row }">
  184. <div style="display: flex; align-items: center; gap: 4px;">
  185. <span v-if="row.projectType === 'MAIN'" style="display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; background-color: #6cbcf5; color: #fff; font-size: 12px; border-radius: 2px; font-weight: bold;">主</span>
  186. <span>{{ row.name }}</span>
  187. </div>
  188. </template>
  189. </el-table-column>
  190. <el-table-column label="是否默认" prop="isDefault" width="200">
  191. <template #default="scope">
  192. <div style="display: flex; align-items: center; gap: 6px;">
  193. <el-switch v-model="scope.row.isDefault" active-value="1" inactive-value="0"
  194. style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"/>
  195. <el-input-number
  196. v-if="scope.row.isDefault === '1' && scope.row.projectType !== 'MAIN'"
  197. v-model="scope.row.defaultCount"
  198. :min="1"
  199. :max="999"
  200. size="small"
  201. controls-position="right"
  202. style="width: 70px;"
  203. />
  204. </div>
  205. </template>
  206. </el-table-column>
  207. <!-- 电站锅炉内检时显示部件选择 -->
  208. <el-table-column label="部件" prop="part" v-if="isPowerStationBoiler">
  209. <template #default="scope">
  210. <el-select
  211. v-model="scope.row.part"
  212. multiple
  213. placeholder="请选择部件"
  214. style="width: 100%"
  215. >
  216. <el-option
  217. v-for="item in getPressureBoilerPartType"
  218. :key="item.value"
  219. :label="item.label"
  220. :value="item.value"
  221. />
  222. </el-select>
  223. </template>
  224. </el-table-column>
  225. <el-table-column label="操作" width="100" align="center">
  226. <template #default="scope">
  227. <el-button link type="primary" @click="() => handleDeleteReport(scope.row, scope.$index)">
  228. 解除关联
  229. </el-button>
  230. </template>
  231. </el-table-column>
  232. </el-table>
  233. <div style="display: flex; justify-content: center; padding-top: 24px;">
  234. <el-button type="default" @click="handleInspectionNatureDialogClose">取消</el-button>
  235. <el-button type="primary" @click="handleInspectionNatureSubmit">确定</el-button>
  236. </div>
  237. </CustomDialog>
  238. <CustomDialog
  239. v-model="reportTemplateDialog_Boiler"
  240. title="选择检验项目"
  241. width="1200px"
  242. append-to-body
  243. @confirm="handleReportTemplateConfirm"
  244. >
  245. <!-- 搜索表单 -->
  246. <el-form :inline="true" :model="reportSearchForm" class="search-form" @submit.prevent>
  247. <el-form-item label="检验项目">
  248. <el-input v-model="reportSearchKeyword" placeholder="输入关键词高亮匹配项" clearable style="width: 240px"/>
  249. </el-form-item>
  250. </el-form>
  251. <!-- 检验项目列表 - 复选框网格布局 -->
  252. <div class="checkItemContentWrapper" v-loading="reportLoading">
  253. <div class="inspection-grid">
  254. <!-- 标题行 -->
  255. <template v-if="reportTemplateList.length > 0">
  256. <!-- Grid 容器 -->
  257. <div
  258. class="grid-container"
  259. :style="{
  260. 'grid-template-columns':
  261. reportTemplateList.length < 5
  262. ? `repeat(${reportTemplateList.length}, 1fr)`
  263. : `repeat(5, 1fr)`
  264. }"
  265. >
  266. <!-- 循环渲染子项 -->
  267. <div class="grid-item" v-for="item in reportTemplateList" :key="item.id">
  268. <el-checkbox
  269. :disabled="isReportSelected(item)"
  270. v-model="item.selected"
  271. @change="(val) => handleReportItemSelect(item, val)"
  272. />
  273. <div style="display: flex; align-items: center; gap: 4px;">
  274. <span v-if="item.projectType === 'MAIN'" style="display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; background-color: #6cbcf5; color: #fff; font-size: 12px; border-radius: 2px; font-weight: bold;">主</span>
  275. <span v-html="highlightText(item.projectName)"></span>
  276. </div>
  277. </div>
  278. </div>
  279. </template>
  280. <el-empty v-else :description="`暂无【${groupName}】检验项目`"/>
  281. </div>
  282. </div>
  283. </CustomDialog>
  284. </template>
  285. <script lang="ts" setup>
  286. defineOptions({ name: 'InspectionNatureBolierList' })
  287. import {DynamicTbApi} from '@/api/pressure2/dynamictb'
  288. import CustomDialog from '@/components/CustomDialog/index.vue'
  289. import {Management, Menu} from '@element-plus/icons-vue'
  290. import {useDictStore} from '@/store/modules/dict'
  291. import dayjs from 'dayjs'
  292. import {
  293. getPressure2InspectionNatureList,
  294. createPressure2InspectionNature,
  295. updatePressure2InspectionNature,
  296. deletePressure2InspectionNature,
  297. getPressure2InspectionNatureInfo
  298. } from '@/api/pressure2/inspectionNature'
  299. import {has} from 'lodash'
  300. import {ElMessage, ElMessageBox} from 'element-plus'
  301. import Sortable from 'sortablejs'
  302. const dictStore = useDictStore()
  303. // 检验性质字典
  304. const getPressureInspectionNatureType = ref<Record<string, any[]>>({
  305. '300': computed(() => dictStore.getDictMap['pressure_inspection_nature_pipe']), //管道
  306. '200': computed(() => dictStore.getDictMap['pressure_inspection_nature_boiler']) //锅炉
  307. })
  308. let getPressureInspectionNature = ref([...getPressureInspectionNatureType.value['300'], ...getPressureInspectionNatureType.value['200']])
  309. let pressureInspectionNature = ref([...getPressureInspectionNatureType.value['300'], ...getPressureInspectionNatureType.value['200']])
  310. // 所属设备
  311. const getPressureEquipmentCategory = computed(() => [{
  312. value: '-1', label: '全部设备', children: [
  313. {label: '锅炉', value: '200'},
  314. {label: '管道', value: '300'}
  315. ]
  316. }])
  317. // 设备类型字典
  318. const getPressureEquipType = ref<Record<string, any[]>>({
  319. '300': computed(() => dictStore.getDictMap['system_equip_pipe_type']), //管道
  320. '200': computed(() => dictStore.getDictMap['system_equip_boiler_type']) //锅炉
  321. })
  322. let getPressureEquipContainerType = []
  323. // 锅炉检验部件类型字典
  324. const getPressureBoilerPartType = computed(() => dictStore.getDictMap['pressure2_boiler_part_type'])
  325. // 主表格相关
  326. const tableRef = ref()
  327. const inspectionNatureList = ref([])
  328. const pageNo = ref(1)
  329. const pageSize = ref(10)
  330. const total = ref(0)
  331. const searchForm = ref<any>({})
  332. const selectedRows = ref<any[]>([])
  333. const currentEquipmentCategory = ref<string | null>(null)
  334. const getTemplateNames = computed(() => inspectionNatureForm.value.templateSaveReqVOList.map(x => x.name))
  335. // 获取检验性质列表
  336. const fetchInspectionNatureList = async () => {
  337. const params: any = {
  338. pageNo: pageNo.value,
  339. pageSize: pageSize.value,
  340. equipmentCategory: currentEquipmentCategory.value,
  341. ...searchForm.value
  342. }
  343. const result = await getPressure2InspectionNatureList(params)
  344. if (result) {
  345. inspectionNatureList.value = result.list.filter(x => {
  346. return x.equipmentCategory !== '100';
  347. })
  348. total.value = result.total
  349. }
  350. }
  351. onMounted(() => {
  352. fetchInspectionNatureList()
  353. })
  354. // 表格选择变化
  355. const handleSelectionChange = (rows: any[]) => {
  356. selectedRows.value = rows
  357. }
  358. // 设备类型查询
  359. const handleNodeClick = (data) => {
  360. const equipmentCategory = data.value === '-1' ? null : data.value
  361. currentEquipmentCategory.value = equipmentCategory
  362. pageNo.value = 1
  363. fetchInspectionNatureList()
  364. // 更新检验性质字典
  365. if (data.value === '-1') {
  366. pressureInspectionNature.value = [...getPressureInspectionNatureType.value['200'], ...getPressureInspectionNatureType.value['300']]
  367. } else {
  368. pressureInspectionNature.value = getPressureInspectionNatureType.value[data.value] || []
  369. }
  370. }
  371. // 编辑 & 新增 检验性质按钮
  372. const handleCreateOrEditInspectionNature = async (row?: any) => {
  373. if (row) {
  374. editInspectionNatureId.value = row.id
  375. editType.value = 'edit'
  376. // 判断是否为锅炉或管道(需要特殊处理)
  377. getPressureInspectionNature = getPressureInspectionNatureType.value[row.equipmentCategory]
  378. getPressureEquipContainerType = getPressureEquipType.value[row.equipmentCategory]
  379. inspectionNatureCreateOrEditDialog.value = true
  380. await loadDetailInfo(row.id)
  381. return
  382. } else {
  383. editType.value = 'create'
  384. // 重置为默认字典
  385. getPressureInspectionNature = getPressureInspectionNatureType.value['100']
  386. getPressureEquipContainerType = getPressureEquipType.value['100']
  387. }
  388. inspectionNatureCreateOrEditDialog.value = true
  389. }
  390. // 加载详情信息(锅炉/管道专用)
  391. const loadDetailInfo = async (id: string) => {
  392. try {
  393. const detailInfo = await DynamicTbApi.getPressureInspectionNatureInfoBoiler({id})
  394. inspectionNatureForm.value = {
  395. ...detailInfo,
  396. templateSaveReqVOList: detailInfo.templateDetailRespVOList.map(item => ({
  397. ...item,
  398. name: item.templateName,
  399. // 将后端返回的 part 字符串转换为数组
  400. part: item.part ? (typeof item.part === 'string' ? item.part.split('/').filter(p => p) : (item.part || [])) : [],
  401. defaultCount: item.defaultCount || 1
  402. }))
  403. }
  404. } catch (error) {
  405. console.error('加载详情失败:', error)
  406. ElMessage.error('加载详情失败')
  407. }
  408. }
  409. const handleEquipmentCategoryChange = (value) => {
  410. getPressureInspectionNature = getPressureInspectionNatureType.value[value]
  411. getPressureEquipContainerType = getPressureEquipType.value[value]
  412. // 切换设备类别时清空设备类型
  413. inspectionNatureForm.value.equipmentType = ''
  414. }
  415. // 删除检验性质
  416. const handleDeleteInspectionNature = () => {
  417. if (!selectedRows.value.length) return ElMessage.warning('请选择检验性质')
  418. if (selectedRows.value.length > 1) return ElMessage.warning('仅限选择一个检验性质')
  419. ElMessageBox.confirm('确定删除选中的检验性质吗?', '删除提示', {
  420. confirmButtonText: '确 认',
  421. cancelButtonText: '取 消'
  422. }).then(async () => {
  423. const res = await deletePressure2InspectionNature({id: selectedRows.value[0].id})
  424. if (res) {
  425. ElMessage.success('删除成功')
  426. fetchInspectionNatureList()
  427. }
  428. })
  429. }
  430. // 新增&编辑 检验性质
  431. const inspectionNatureCreateOrEditDialog = ref(false)
  432. const editType = ref('')
  433. const editInspectionNatureId = ref('')
  434. const inspectionNatureFormRef = ref()
  435. const inspectionNatureForm = ref({
  436. inspectionNature: '',
  437. equipmentCategory: '',
  438. equipmentType: '',
  439. templateSaveReqVOList: [] as any[]
  440. })
  441. const inspectionNatureFormRules = ref({
  442. inspectionNature: [
  443. {required: true, message: '请选择检验性质', trigger: 'blur'}
  444. ],
  445. equipmentCategory: [
  446. {required: true, message: '请选择设备类别', trigger: 'blur'}
  447. ],
  448. equipmentType: [
  449. {required: true, message: '请选择设备类型', trigger: 'blur'}
  450. ],
  451. templateSaveReqVOList: [
  452. {required: true, message: '请选择关联报告模板', trigger: 'blur'}
  453. ]
  454. })
  455. const handleDeleteReport = (row, $index) => {
  456. inspectionNatureForm.value.templateSaveReqVOList.splice($index, 1)
  457. }
  458. const handleInspectionNatureDialogClose = () => {
  459. inspectionNatureCreateOrEditDialog.value = false
  460. editType.value = ''
  461. inspectionNatureFormRef.value.resetFields()
  462. inspectionNatureForm.value.templateSaveReqVOList = []
  463. reportTemplateList.value = []
  464. reportSearchKeyword.value = ''
  465. }
  466. // 提交检验性质
  467. const handleInspectionNatureSubmit = async () => {
  468. try {
  469. await inspectionNatureFormRef.value.validate()
  470. // 判断是否为电站锅炉内检
  471. const isPowerStationBoiler = inspectionNatureForm.value.equipmentType == '1' &&
  472. inspectionNatureForm.value.equipmentCategory == '200' &&
  473. inspectionNatureForm.value.inspectionNature == '100'
  474. console.log(inspectionNatureForm.value.templateSaveReqVOList)
  475. const params = {
  476. ...inspectionNatureForm.value,
  477. templateSaveReqVOList: inspectionNatureForm.value.templateSaveReqVOList.map((item: any, index: number) => ({
  478. id: item.id,
  479. templateId: item.templateId,
  480. isDefault: item.isDefault,
  481. defaultCount: item.defaultCount,
  482. sort: index + 1,
  483. inspectionNatureId: has(item, 'inspectionNatureId') ? item.inspectionNatureId : (editType.value === 'edit' ? editInspectionNatureId.value : undefined),
  484. // 如果是电站锅炉内检,将 part 数组转换为字符串
  485. part: isPowerStationBoiler ? (item.part || []).join('/') : ""
  486. })),
  487. id: editType.value === 'edit' ? editInspectionNatureId.value : undefined
  488. }
  489. // 根据设备类型选择不同的更新接口
  490. const result = editType.value === 'edit' ? await updatePressure2InspectionNature(params) : await createPressure2InspectionNature(params)
  491. if (result) {
  492. ElMessage.success((editType.value === 'edit' ? '编辑' : '新增') + '成功')
  493. handleInspectionNatureDialogClose()
  494. fetchInspectionNatureList()
  495. }
  496. } catch (error) {
  497. console.error('提交失败:', error)
  498. }
  499. }
  500. // 报告模板列表相关
  501. const reportTotal = ref(0)
  502. const reportSearchForm = ref<any>({})
  503. const reportTemplateList = ref<any[]>([])
  504. const reportLoading = ref(false)
  505. const reportSearchKeyword = ref('') // 搜索关键词
  506. // 高亮匹配文本
  507. const highlightText = (text: string) => {
  508. if (!text) return ''
  509. const keyword = reportSearchKeyword.value
  510. if (!keyword) return text
  511. // 转义正则特殊字符
  512. const escaped = keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
  513. const regex = new RegExp(`(${escaped})`, 'gi')
  514. return text.replace(regex, '<mark style="background-color: #fff3cd; padding: 0 2px;">$1</mark>')
  515. }
  516. // 判断报告是否已选中
  517. const isReportSelected = (item: any) => {
  518. // 判断是否已经有主项目
  519. if (inspectionNatureForm.value.templateSaveReqVOList.some((x: any) => x.projectType === 'MAIN') && item.projectType === 'MAIN'){
  520. console.log(item)
  521. return true
  522. }
  523. return inspectionNatureForm.value.templateSaveReqVOList.some(
  524. (x: any) => x.templateId === item.id
  525. )
  526. }
  527. // 处理报告项选择变化
  528. const handleReportItemSelect = (item: any, checked: boolean) => {
  529. if (checked) {
  530. // 添加到已选列表
  531. if (!isReportSelected(item.id)) {
  532. inspectionNatureForm.value.templateSaveReqVOList.push({
  533. templateId: item.id,
  534. name: item.projectName,
  535. isDefault: item.isDefault || '0',
  536. defaultCount: 1,
  537. part: []
  538. })
  539. }
  540. } else {
  541. // 从已选列表移除
  542. const index = inspectionNatureForm.value.templateSaveReqVOList.findIndex(
  543. (x: any) => x.id === item.id
  544. )
  545. if (index > -1) {
  546. inspectionNatureForm.value.templateSaveReqVOList.splice(index, 1)
  547. }
  548. }
  549. }
  550. const fetchReportTemplateList_Boiler = async () => {
  551. reportLoading.value = true
  552. try {
  553. const params = {
  554. pageNo: 1,
  555. pageSize: 999,
  556. reportType: 100,
  557. ...reportSearchForm.value
  558. }
  559. const result = await DynamicTbApi.getDynamicTbPageInspection(params)
  560. if (result) {
  561. reportTemplateList.value = result.list
  562. reportTotal.value = result.total
  563. }
  564. } catch (error) {
  565. console.error('获取报告模板列表失败:', error)
  566. } finally {
  567. reportLoading.value = false
  568. }
  569. }
  570. // 报告模板弹窗
  571. const reportTemplateDialog_Boiler = ref(false)
  572. const handleShowReportList = () => {
  573. reportTemplateDialog_Boiler.value = true
  574. fetchReportTemplateList_Boiler()
  575. }
  576. const handleClearSelectedItem = () => {
  577. inspectionNatureForm.value.templateSaveReqVOList = []
  578. }
  579. const handleRemoveTag = (name) => {
  580. inspectionNatureForm.value.templateSaveReqVOList = inspectionNatureForm.value.templateSaveReqVOList.filter(item => item.name !== name)
  581. }
  582. const handleReportTemplateConfirm = () => {
  583. // 直接关闭弹窗,数据已在 handleReportItemSelect 中实时更新
  584. reportTemplateDialog_Boiler.value = false
  585. }
  586. // 判断是否为电站锅炉内检
  587. const isPowerStationBoiler = computed(() => {
  588. return inspectionNatureForm.value.equipmentType == '1' &&
  589. inspectionNatureForm.value.equipmentCategory == '200' &&
  590. inspectionNatureForm.value.inspectionNature == '100'
  591. })
  592. // 拖拽排序
  593. const sortTableRef = ref()
  594. const sortableInstance = ref<any>(null)
  595. const initSortable = () => {
  596. nextTick(() => {
  597. if (sortableInstance.value) {
  598. sortableInstance.value.destroy()
  599. sortableInstance.value = null
  600. }
  601. const tableBody = sortTableRef.value?.$el?.querySelector('.el-table__body-wrapper tbody')
  602. if (!tableBody) return
  603. sortableInstance.value = Sortable.create(tableBody, {
  604. animation: 150,
  605. handle: '.drag-handle',
  606. ghostClass: 'sortable-ghost',
  607. chosenClass: 'sortable-chosen',
  608. dragClass: 'sortable-drag',
  609. onEnd: (evt: any) => {
  610. const { oldIndex, newIndex } = evt
  611. if (oldIndex !== undefined && newIndex !== undefined && oldIndex !== newIndex) {
  612. const list = inspectionNatureForm.value.templateSaveReqVOList
  613. const movedItem = list.splice(oldIndex, 1)[0]
  614. list.splice(newIndex, 0, movedItem)
  615. }
  616. }
  617. })
  618. })
  619. }
  620. // 弹窗打开且数据变化时重新初始化拖拽
  621. watch(
  622. () => [inspectionNatureCreateOrEditDialog.value, inspectionNatureForm.value.templateSaveReqVOList.length],
  623. () => {
  624. if (inspectionNatureCreateOrEditDialog.value) {
  625. initSortable()
  626. }
  627. }
  628. )
  629. onBeforeUnmount(() => {
  630. if (sortableInstance.value) {
  631. sortableInstance.value.destroy()
  632. sortableInstance.value = null
  633. }
  634. })
  635. </script>
  636. <style lang="scss" scoped>
  637. .standard-class-list {
  638. display: flex;
  639. align-items: stretch;
  640. flex-wrap: nowrap;
  641. margin: 0 !important;
  642. min-height: calc(100vh - 120px);
  643. .right-table {
  644. flex: 1;
  645. display: flex;
  646. flex-direction: column;
  647. }
  648. .left-tree {
  649. min-width: 240px;
  650. max-width: 280px;
  651. margin-right: 24px;
  652. padding: 16px;
  653. border-radius: 8px;
  654. border-right: none;
  655. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  656. }
  657. .search-form {
  658. margin-bottom: 16px;
  659. padding: 16px;
  660. background-color: var(--el-fill-color-blank);
  661. border-radius: 8px;
  662. border: 1px solid var(--el-border-color-lighter);
  663. }
  664. .table-buttons {
  665. margin-bottom: 16px;
  666. display: flex;
  667. gap: 12px;
  668. }
  669. .pagination {
  670. margin-top: 16px;
  671. justify-content: flex-end;
  672. padding: 12px 0;
  673. }
  674. :deep(.el-table) {
  675. border-radius: 8px;
  676. overflow: hidden;
  677. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  678. .el-table__header-wrapper {
  679. th {
  680. color: var(--el-text-color-primary);
  681. font-weight: 600;
  682. }
  683. }
  684. .el-table__row {
  685. &:hover {
  686. background-color: var(--el-color-primary-light-9) !important;
  687. }
  688. }
  689. }
  690. :deep(.el-tree) {
  691. .el-tree-node {
  692. &.is-current {
  693. // background: none !important;
  694. }
  695. }
  696. .el-tree-node__content {
  697. height: 48px;
  698. border-radius: 6px;
  699. margin-bottom: 4px;
  700. transition: all 0.3s;
  701. .el-tree-node__expand-icon {
  702. display: none;
  703. }
  704. &:hover {
  705. background-color: var(--el-color-primary-light-9);
  706. transform: translateX(4px);
  707. }
  708. &.is-current {
  709. background-color: var(--el-color-primary-light-8);
  710. color: var(--el-color-primary);
  711. font-weight: 600;
  712. }
  713. }
  714. }
  715. .add-class-btn {
  716. width: 100%;
  717. height: 38px;
  718. margin-right: 10px;
  719. border-radius: 0;
  720. .el-icon {
  721. margin-right: 6px;
  722. }
  723. }
  724. .class-content {
  725. position: relative;
  726. display: flex;
  727. align-items: center;
  728. width: 100%;
  729. height: 100%;
  730. .el-icon {
  731. margin-top: 2px;
  732. }
  733. .custom-tree-node {
  734. padding-left: 8px;
  735. font-size: 14px;
  736. }
  737. .more {
  738. position: absolute;
  739. right: 12px;
  740. top: 50%;
  741. transform: translateY(-50%) rotate(90deg);
  742. margin: 0;
  743. }
  744. }
  745. }
  746. .custom-tree-node-popover {
  747. color: var(--el-text-color-primary);
  748. .el-button {
  749. display: block;
  750. margin-left: 0;
  751. margin-bottom: 8px;
  752. height: 36px;
  753. width: 100%;
  754. line-height: 36px;
  755. text-align: center;
  756. &:last-child {
  757. margin-bottom: 0;
  758. }
  759. }
  760. }
  761. .inspection-grid {
  762. width: 100%;
  763. padding: 16px;
  764. }
  765. /* Grid 容器核心配置 */
  766. .grid-container {
  767. display: grid;
  768. /* 5列等宽,列间距 12px,行间距 16px */
  769. grid-template-columns: repeat(5, 1fr);
  770. align-items: center; /* 垂直居中 */
  771. grid-gap: 1px;
  772. background-color: var(--el-border-color-light);
  773. border: 1px solid var(--el-border-color-light);
  774. }
  775. /* 子项布局:复选框 + 文本 + 图标 */
  776. .grid-item {
  777. display: flex;
  778. align-items: center;
  779. padding-left: 20px;
  780. padding-right: 12px;
  781. height: 52px;
  782. background-color: #fff;
  783. .el-checkbox {
  784. margin-right: 6px;
  785. }
  786. }
  787. /* 复选框样式优化(可选) */
  788. .grid-item input[type='checkbox'] {
  789. width: 16px;
  790. height: 16px;
  791. cursor: pointer;
  792. }
  793. .custom-select {
  794. position: relative;
  795. display: flex;
  796. align-items: center;
  797. width: 100%;
  798. line-height: 32px;
  799. min-height: 32px;
  800. :deep(.el-input) {
  801. width: 100%;
  802. height: 100%;
  803. flex: 1;
  804. .el-input__inner {
  805. cursor: pointer;
  806. }
  807. }
  808. :deep(.el-icon) {
  809. position: absolute;
  810. right: 12px;
  811. top: 50%;
  812. transform: translateY(-50%);
  813. color: var(--el-text-color-placeholder);
  814. }
  815. }
  816. // 拖拽排序样式
  817. .sortable-ghost {
  818. opacity: 0.4;
  819. background: #c8ebfb;
  820. }
  821. .sortable-chosen {
  822. opacity: 0.8;
  823. }
  824. .sortable-drag {
  825. opacity: 0.8;
  826. }
  827. .drag-handle {
  828. cursor: move;
  829. display: flex;
  830. align-items: center;
  831. justify-content: center;
  832. }
  833. </style>