InspectionNatureDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <script setup lang="ts">
  2. import {ref, computed, nextTick} from 'vue'
  3. import {ElMessage} from 'element-plus'
  4. import {DynamicTbApi} from '@/api/pressure2/dynamictb'
  5. import {useDictStore} from '@/store/modules/dict'
  6. import dayjs from 'dayjs'
  7. import {
  8. createPressureInspectionNature,
  9. updatePressureInspectionNature
  10. } from "@/api/pressure/inspectionNature";
  11. import {updatePressure2InspectionNature} from "@/api/pressure2/inspectionNature";
  12. const props = defineProps({
  13. modelValue: {
  14. type: Boolean,
  15. default: false
  16. },
  17. editType: {
  18. type: String,
  19. default: 'create'
  20. },
  21. editId: {
  22. type: String,
  23. default: ''
  24. }
  25. })
  26. const emit = defineEmits(['update:modelValue', 'success'])
  27. const dictStore = useDictStore()
  28. // 锅炉检验部件类型字典
  29. const getPressureBoilerPartType = computed(() => dictStore.getDictMap['pressure2_boiler_part_type'])
  30. const getPressureEquipmentCategory = computed(() => [{
  31. value: '-1',
  32. label: '全部设备',
  33. children: dictStore.getDictMap['pressure_equipment_category']
  34. }])
  35. // 字典数据
  36. const getPressureInspectionNatureType = ref({
  37. '200': computed(() => dictStore.getDictMap['pressure_inspection_nature']),
  38. '300': computed(() => dictStore.getDictMap['pressure_inspection_nature_boiler'])
  39. })
  40. const getPressureEquipType = ref({
  41. '200': computed(() => dictStore.getDictMap['system_equip_pipe_type']),
  42. '300': computed(() => dictStore.getDictMap['system_equip_boiler_type'])
  43. })
  44. // 表单相关
  45. const inspectionNatureFormRef = ref()
  46. const inspectionNatureForm = ref({
  47. inspectionNature: '',
  48. equipmentCategory: '',
  49. equipmentType: '',
  50. templateSaveReqVOList: [] as any[]
  51. })
  52. // 判断是否为电站锅炉内检
  53. const isPowerStationBoiler = computed(() => {
  54. return inspectionNatureForm.value.equipmentType == '1' && inspectionNatureForm.value.equipmentCategory == '300' && inspectionNatureForm.value.inspectionNature == '100'
  55. })
  56. const inspectionNatureFormRules = ref({
  57. inspectionNature: [
  58. {required: true, message: '请选择检验性质', trigger: 'blur'}
  59. ],
  60. equipmentCategory: [
  61. {required: true, message: '请选择设备类别', trigger: 'blur'}
  62. ],
  63. equipmentType: [
  64. {required: true, message: '请选择设备类型', trigger: 'blur'}
  65. ],
  66. templateSaveReqVOList: [
  67. {required: true, message: '请选择关联报告模板', trigger: 'blur'}
  68. ]
  69. })
  70. const getTemplateNames = computed(() => inspectionNatureForm.value.templateSaveReqVOList.map(x => x.name))
  71. // 报告模板弹窗
  72. const reportTemplateDialog_Boiler = ref(false)
  73. const reportTemplateTableRef = ref()
  74. const reportPageNo = ref(1)
  75. const reportPageSize = ref(10)
  76. const reportTotal = ref(0)
  77. const reportTemplateListSearchForm = ref({})
  78. const reportTemplateList = ref([])
  79. const getPressureReportTemplateType = computed(() => dictStore.getDictMap['pressure_report_template_type'])
  80. const reportColumns = computed(() => ([
  81. {
  82. type: 'selection',
  83. width: 55,
  84. fieldProps: {
  85. reserveSelection: true,
  86. selectable: (row) => {
  87. return inspectionNatureForm.value.templateSaveReqVOList.findIndex(item => item.templateId === row.id) < 0
  88. }
  89. }
  90. },
  91. {
  92. label: '报告编号',
  93. prop: 'id',
  94. },
  95. {
  96. label: '报告名称',
  97. prop: 'name',
  98. search: {
  99. type: 'input',
  100. placeholder: '请输入报告名称'
  101. }
  102. },
  103. {
  104. label: '报告分类',
  105. prop: 'className',
  106. search: {
  107. type: 'select',
  108. options: [],
  109. prop: 'classId'
  110. },
  111. },
  112. {
  113. label: '报告类型',
  114. prop: 'type',
  115. render: (row) => {
  116. return getPressureReportTemplateType.value[row.type]?.label || '未知'
  117. }
  118. },
  119. {
  120. label: '生效日期',
  121. prop: 'effectiveDate',
  122. },
  123. {
  124. label: '失效日期',
  125. prop: 'expiryDate',
  126. }
  127. ]))
  128. // 监听弹窗打开
  129. const handleDialogOpen = async () => {
  130. if (props.editType === 'edit' && props.editId) {
  131. await loadDetailInfo()
  132. } else {
  133. resetForm()
  134. }
  135. }
  136. // 加载详情信息
  137. const loadDetailInfo = async () => {
  138. try {
  139. const detailInfo = await DynamicTbApi.getPressureInspectionNatureInfoBoiler({id: props.editId})
  140. inspectionNatureForm.value = {
  141. ...detailInfo,
  142. templateSaveReqVOList: detailInfo.templateDetailRespVOList.map(item => ({
  143. ...item,
  144. name: item.templateName,
  145. // 将后端返回的 part 字符串转换为数组
  146. part: item.part ? (typeof item.part === 'string' ? item.part.split('/').filter(p => p) : (item.part || [])) : []
  147. }))
  148. }
  149. } catch (error) {
  150. console.error('加载详情失败:', error)
  151. ElMessage.error('加载详情失败')
  152. }
  153. }
  154. // 重置表单
  155. const resetForm = () => {
  156. inspectionNatureForm.value = {
  157. inspectionNature: '',
  158. equipmentCategory: '',
  159. equipmentType: '',
  160. templateSaveReqVOList: []
  161. }
  162. inspectionNatureFormRef.value?.resetFields()
  163. }
  164. // 关闭弹窗
  165. const handleClose = () => {
  166. emit('update:modelValue', false)
  167. resetForm()
  168. }
  169. // 提交表单
  170. const handleSubmit = async () => {
  171. try {
  172. await inspectionNatureFormRef.value.validate()
  173. const params = {
  174. ...inspectionNatureForm.value,
  175. templateSaveReqVOList: inspectionNatureForm.value.templateSaveReqVOList.map((item: any) => ({
  176. id: item.id,
  177. templateId: item.templateId,
  178. isDefault: item.isDefault,
  179. inspectionNatureId: item.inspectionNatureId || (props.editType === 'edit' ? props.editId : undefined),
  180. part: isPowerStationBoiler.value ? (item.part || []).join('/') : ""
  181. })),
  182. id: props.editType === 'edit' ? props.editId : undefined
  183. }
  184. const result = props.editType === 'edit' ? await updatePressure2InspectionNature(params) : await createPressureInspectionNature(params)
  185. if (result) {
  186. ElMessage.success((props.editType === 'edit' ? '编辑' : '新增') + '成功')
  187. emit('success')
  188. handleClose()
  189. }
  190. } catch (error) {
  191. console.error('提交失败:', error)
  192. }
  193. }
  194. // 显示报告模板列表
  195. const handleShowReportList = () => {
  196. reportTemplateDialog_Boiler.value = true
  197. fetchReportTemplateList_Boiler()
  198. }
  199. // 获取报告模板列表
  200. const fetchReportTemplateList_Boiler = async () => {
  201. const params = {
  202. pageNo: reportPageNo.value,
  203. pageSize: reportPageSize.value,
  204. reportType: 100,
  205. ...reportTemplateListSearchForm.value
  206. }
  207. const result = await DynamicTbApi.getDynamicTbPageInspection(params)
  208. if (result) {
  209. reportTemplateList.value = result.list
  210. reportTotal.value = result.total
  211. const selectedIds = inspectionNatureForm.value.templateSaveReqVOList.map(item => item.templateId)
  212. nextTick(() => {
  213. const tableRef = reportTemplateTableRef.value?.getTableRef()
  214. if (tableRef) {
  215. reportTemplateList.value.forEach(row => {
  216. if (selectedIds.includes(row.id)) {
  217. tableRef.toggleRowSelection(row, true)
  218. }
  219. })
  220. }
  221. })
  222. }
  223. }
  224. // 确认选择报告模板
  225. const handleReportTemplateConfirm = () => {
  226. const selectedRows = reportTemplateTableRef.value?.getTableRef().getSelectionRows() || []
  227. selectedRows.forEach(item => {
  228. const templateIds = inspectionNatureForm.value.templateSaveReqVOList.map(x => x.templateId)
  229. if (!templateIds.includes(item.id)) {
  230. inspectionNatureForm.value.templateSaveReqVOList.push({
  231. templateId: item.id,
  232. name: item.name,
  233. effectiveDate: item.effectiveDate,
  234. expiryDate: item.expiryDate,
  235. isDefault: '0',
  236. part: [] // 初始化部件类型数组
  237. })
  238. }
  239. })
  240. }
  241. // 删除报告模板
  242. const handleDeleteReport = (row, index) => {
  243. inspectionNatureForm.value.templateSaveReqVOList.splice(index, 1)
  244. }
  245. // 清除选中项
  246. const handleClearSelectedItem = () => {
  247. inspectionNatureForm.value.templateSaveReqVOList = []
  248. }
  249. // 移除标签
  250. const handleRemoveTag = (name) => {
  251. inspectionNatureForm.value.templateSaveReqVOList = inspectionNatureForm.value.templateSaveReqVOList.filter(item => item.name !== name)
  252. }
  253. </script>
  254. <template>
  255. <CustomDialog
  256. :model-value="modelValue"
  257. :title="(editType === 'edit' ? '编辑' : '添加') + '检验性质'"
  258. width="1200px"
  259. :showFooter="false"
  260. @open="handleDialogOpen"
  261. @close="handleClose"
  262. >
  263. <el-form
  264. ref="inspectionNatureFormRef"
  265. :model="inspectionNatureForm"
  266. :rules="inspectionNatureFormRules"
  267. style="width: 400px;"
  268. label-width="110px"
  269. >
  270. <el-form-item label="检验性质" prop="inspectionNature">
  271. <el-select v-model="inspectionNatureForm.inspectionNature" placeholder="请选择检验性质">
  272. <el-option
  273. v-for="item in getPressureInspectionNatureType[inspectionNatureForm.equipmentCategory]"
  274. :key="item.value"
  275. :label="item.label"
  276. :value="item.value"
  277. />
  278. </el-select>
  279. </el-form-item>
  280. <el-form-item label="所属设备" prop="equipmentCategory">
  281. <el-select
  282. v-model="inspectionNatureForm.equipmentCategory"
  283. placeholder="请选择所属设备"
  284. @change="inspectionNatureForm.equipmentType = ''"
  285. >
  286. <el-option
  287. v-for="item in getPressureEquipmentCategory[0].children"
  288. :key="item.value"
  289. :label="item.label"
  290. :value="item.value"
  291. />
  292. </el-select>
  293. </el-form-item>
  294. <el-form-item label="设备类型" prop="equipmentType">
  295. <el-select v-model="inspectionNatureForm.equipmentType" placeholder="请选择设备类型">
  296. <el-option
  297. v-for="item in getPressureEquipType[inspectionNatureForm.equipmentCategory]"
  298. :key="item.value"
  299. :label="item.label"
  300. :value="item.value"
  301. />
  302. </el-select>
  303. </el-form-item>
  304. <el-form-item label="关联报告模板" prop="templateSaveReqVOList">
  305. <el-select
  306. :model-value="getTemplateNames"
  307. clearable
  308. multiple
  309. @remove-tag="handleRemoveTag"
  310. @click.stop.prevent="handleShowReportList"
  311. @clear="handleClearSelectedItem"
  312. placeholder="请选择关联报告模板"
  313. />
  314. </el-form-item>
  315. </el-form>
  316. <el-table :data="inspectionNatureForm.templateSaveReqVOList">
  317. <el-table-column label="检验项目名称" prop="name"/>
  318. <el-table-column label="是否默认" prop="isDefault">
  319. <template #default="scope">
  320. <el-switch
  321. v-model="scope.row.isDefault"
  322. active-value="1"
  323. inactive-value="0"
  324. style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
  325. />
  326. </template>
  327. </el-table-column>
  328. <el-table-column label="部件" prop="part" v-if="isPowerStationBoiler">
  329. <template #default="scope">
  330. <el-select
  331. v-model="scope.row.part"
  332. multiple
  333. placeholder="请选择部件"
  334. style="width: 100%"
  335. >
  336. <el-option
  337. v-for="item in getPressureBoilerPartType"
  338. :key="item.value"
  339. :label="item.label"
  340. :value="item.value"
  341. />
  342. </el-select>
  343. </template>
  344. </el-table-column>
  345. <el-table-column label="操作">
  346. <template #default="scope">
  347. <el-button link type="primary" @click="handleDeleteReport(scope.row, scope.$index)">
  348. 解除关联
  349. </el-button>
  350. </template>
  351. </el-table-column>
  352. </el-table>
  353. <div style="display: flex; justify-content: center; padding-top: 24px;">
  354. <el-button type="default" @click="handleClose">取消</el-button>
  355. <el-button type="primary" @click="handleSubmit">确定</el-button>
  356. </div>
  357. </CustomDialog>
  358. <!-- 报告模板选择弹窗 -->
  359. <CustomDialog
  360. v-model="reportTemplateDialog_Boiler"
  361. title="报告模板列表"
  362. width="1200px"
  363. @confirm="handleReportTemplateConfirm"
  364. >
  365. <SmartTable
  366. ref="reportTemplateTableRef"
  367. v-model:columns="reportColumns"
  368. v-model:pageNo="reportPageNo"
  369. v-model:pageSize="reportPageSize"
  370. v-model:formData="reportTemplateListSearchForm"
  371. :data="reportTemplateList"
  372. :total="reportTotal"
  373. :refresh="false"
  374. @on-page-no-change="fetchReportTemplateList_Boiler"
  375. @on-page-size-change="fetchReportTemplateList_Boiler"
  376. @on-reset="fetchReportTemplateList_Boiler"
  377. @on-search="fetchReportTemplateList_Boiler"
  378. @refresh="fetchReportTemplateList_Boiler"
  379. :tableProps="{
  380. height: 500
  381. }"
  382. />
  383. </CustomDialog>
  384. </template>
  385. <style scoped lang="scss">
  386. </style>