AddInspectionplanDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <!--
  2. * @Author: zhuMingXi
  3. * @Date: 2025/07/26 14:35:00
  4. * @LastEditors: zhuMingXi
  5. * @LastEditTime: 2025/07/26 14:35:00
  6. * @Description: 编辑检验方案弹窗
  7. * @FilePath: D:\yiqun\yudao-admin\yudao-ui-admin-vue3\src\views\pressure\taskorder\components\AddInspectionplanDetail.vue
  8. -->
  9. <template>
  10. <ContentWrap
  11. v-show="!showInlineEditRecord"
  12. title="检验方案"
  13. class="check-record-wrapper"
  14. v-loading="pdfLoading"
  15. >
  16. <div class="designer-inner" ref="wrapperContainerRef" v-if="['add', 'edit'].includes(isEdit)">
  17. <!-- <SpreadViewer :initData="initData" ref="spreadRef" />-->
  18. <SpreadViewer :initData="editData" ref="editSpreadRecordRef" @saveSuccess="saveSuccessRecord"/>
  19. </div>
  20. <div class="designer-inner" ref="wrapperContainerRef" v-else>
  21. <SpreadViewer :initData="initData" ref="spreadRef" />
  22. </div>
  23. <div class="operation-inner relative">
  24. <div class="btn-list">
  25. <template v-if="['add', 'edit'].includes(isEdit)">
  26. <el-button type="primary" @click="handleSubmitBefore" v-if="props.editInspectionplanParams.isSelfType">提交审核</el-button>
  27. <el-button v-else @click="handleSubmitNotApproval">提交</el-button>
  28. <!-- <el-button type="primary" plain @click="handleEditSpreadRecord">编辑封面</el-button>-->
  29. </template>
  30. <el-button type="default" plain @click="handleCloseModal">取 消</el-button>
  31. </div>
  32. <div class="operation-item" style="max-height: calc(100% / 2); overflow-y: auto" v-if="props.editInspectionplanParams.isSelfType">
  33. <div class="item-header"> 方案上传 </div>
  34. <div class="item-content">
  35. <el-upload
  36. ref="uploadRef"
  37. action="#"
  38. v-model:file-list="fileList"
  39. :http-request="handlePostFile"
  40. :auto-upload="false"
  41. :disabled="isEdit === 'view'"
  42. :limit="1"
  43. :on-change="handleChange"
  44. :on-error="handleUploadError"
  45. :on-exceed="handleExceed"
  46. :accept="accept"
  47. drag
  48. >
  49. <Icon icon="ep:upload" />
  50. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  51. <template #tip>
  52. <div class="el-upload__tip text-center">
  53. <span>{{ `仅允许导入${accept} 格式文件。` }}</span>
  54. </div>
  55. </template>
  56. </el-upload>
  57. </div>
  58. </div>
  59. <div class="operation-item">
  60. <div class="item-header"> 退回原因 </div>
  61. <div class="item-content">
  62. <el-input
  63. v-model="returnReason"
  64. :autosize="{ minRows: 10, maxRows: 50 }"
  65. type="textarea"
  66. readonly
  67. />
  68. </div>
  69. </div>
  70. </div>
  71. </ContentWrap>
  72. <!-- 检验录入-模板 -->
  73. <CustomDialog v-model="showInlineEditRecord" title="检验录入" :show-footer="false" fullscreen>
  74. <!-- <SpreadViewer :initData="editData" ref="editSpreadRecordRef" @saveSuccess="saveSuccessRecord"/>-->
  75. </CustomDialog>
  76. <CustomDialog
  77. ref="customUnitDialogRef"
  78. title="选择审核人"
  79. v-model="approvalUserVisible"
  80. width="650px"
  81. :dialogAttrs="{ zIndex: 10006 }"
  82. >
  83. <el-form ref="formRef" :model="formData" :rules="formRules" label-width="135px">
  84. <el-form-item label="检验方案审核人" prop="inspectionAuditId">
  85. <el-select v-model="formData.inspectionAuditId" clearable placeholder="请选择">
  86. <el-option
  87. v-for="item in optionList.schemeReviewerList.list"
  88. :key="item.id"
  89. :label="item.nickname"
  90. :value="item.id"
  91. />
  92. </el-select>
  93. </el-form-item>
  94. <!-- <el-form-item label="检验方案批准人" prop="inspectionApproveId">-->
  95. <!-- <el-select v-model="formData.inspectionApproveId" clearable placeholder="请选择">-->
  96. <!-- <el-option-->
  97. <!-- v-for="item in optionList.schemeApproveList.list"-->
  98. <!-- :key="item.id"-->
  99. <!-- :label="item.nickname"-->
  100. <!-- :value="item.id"-->
  101. <!-- />-->
  102. <!-- </el-select>-->
  103. <!-- </el-form-item>-->
  104. </el-form>
  105. <template #footer>
  106. <el-button @click="approvalUserVisible = false">取消</el-button>
  107. <el-button type="primary" @click="handleSubmitUser">确定</el-button>
  108. </template>
  109. </CustomDialog>
  110. </template>
  111. <script lang="tsx" setup>
  112. import { BoilerTaskOrderApi } from '@/api/pressure2/boilertaskorder'
  113. import {defineModel, PropType, ref} from 'vue'
  114. import VuePdfEmbed from 'vue-pdf-embed'
  115. import EditInspectionplanReport from './EditInspectionplanReport.vue'
  116. import { getPressureReportTemplatePDF } from '@/api/pressure/reportTemplate'
  117. import { ElForm, UploadFile, UploadProps, UploadRequestOptions } from 'element-plus'
  118. import { uploadFile } from '@/api/common'
  119. import VueOfficeDocx from '@vue-office/docx/lib/v3/vue-office-docx.mjs'
  120. import '@vue-office/docx/lib/v3/index.css'
  121. import * as UserGroupApi from '@/api/bpm/userGroup'
  122. import * as UserApi from '@/api/system/user'
  123. import { debounce } from 'lodash-es'
  124. import { PressureReportType } from '@/utils/constants'
  125. import SpreadDesigner from "@/components/SpreadDesigner/index.vue";
  126. import {DynamicTbValApi} from "@/api/pressure2/dynamictbval";
  127. import * as GC from "@grapecity-software/spread-sheets";
  128. import {getPDF, getStandardTemplateInfo} from "@/api/laboratory/standard/template";
  129. import {buildFileUrl} from "@/utils";
  130. import axios from "axios";
  131. import {editReport} from "@/utils/reportUtil";
  132. import {DynamicTbColApi} from "@/api/pressure2/dynamictbcol";
  133. import {SpreadViewer} from "@/components/DynamicReport";
  134. import {InitParams} from "@/components/DynamicReport/SpreadInterface";
  135. import {PipeTaskOrderApi} from "@/api/pressure2/pipetaskorder";
  136. const props = defineProps({
  137. taskOrderDetail: {
  138. type: Object,
  139. default: () => ({})
  140. },
  141. inspectionplanDetail: {
  142. type: Object,
  143. default: () => ({})
  144. },
  145. isEdit: {
  146. type: String as PropType<'add' | 'edit' | 'view'>,
  147. required: true
  148. },
  149. editInspectionplanParams: {
  150. type: Object,
  151. default: () => ({})
  152. }
  153. })
  154. const emits = defineEmits(['success', 'refresh'])
  155. const visible = defineModel('visible', { type: Boolean, default: false })
  156. const returnReason = ref(props.inspectionplanDetail?.returnReason)
  157. // 选择审核人
  158. const formRef = ref<InstanceType<typeof ElForm>>()
  159. const formData = ref<Recordable>({})
  160. const formRules = reactive({
  161. inspectionAuditId: [{ required: true, message: '请选择审核人', trigger: 'change' }],
  162. inspectionApproveId: [{ required: true, message: '请选择批准人', trigger: 'change' }]
  163. })
  164. const optionList = reactive<{
  165. schemeReviewerList: Recordable[]
  166. schemeApproveList: Recordable[]
  167. }>({
  168. schemeReviewerList: [],
  169. schemeApproveList: []
  170. })
  171. const approvalUserVisible = ref(false)
  172. // 获取审核人信息
  173. const getSchemeReviewerList = async () => {
  174. try {
  175. // const { inspectionAuditId, inspectionApproveId } = await UserApi.getApprovalDetail({})
  176. // formData.value = {
  177. // inspectionAuditId,
  178. // inspectionApproveId
  179. // }
  180. optionList.schemeReviewerList = await BoilerTaskOrderApi.getAuditList({
  181. roleCode: 'Boiler Director'
  182. })
  183. optionList.schemeApproveList = await BoilerTaskOrderApi.getAuditList({
  184. roleCode: 'Boiler_Department_Head'
  185. })
  186. approvalUserVisible.value = true
  187. } catch (error) {}
  188. }
  189. const handleSubmitUser = () => {
  190. formRef.value?.validate(async (valid) => {
  191. if (valid) {
  192. handleSubmitConfirm()
  193. }
  194. })
  195. }
  196. // PDF相关状态
  197. const pdfLoading = ref(false)
  198. const showInlineEditRecord = ref(false)
  199. const handleEditSpreadRecord = () => {
  200. editPreview()
  201. showInlineEditRecord.value = true
  202. }
  203. const handleSuccess = (info) => {
  204. // 更新相关的信息,reportId prepareJson 等
  205. console.log('handleSuccess-info:', info )
  206. emits('success', info)
  207. initPreview()
  208. }
  209. const uploadRef = ref()
  210. const fileList = ref<UploadFile[]>([]) // 文件列表
  211. const accept = '.docx,.pdf'
  212. const fileLoading = ref(false) // 表单的加载中
  213. // 获取文件类型
  214. const getFileExtension = (fileName: string) => {
  215. return fileName.split('.').pop()?.toLowerCase()
  216. }
  217. const previewUrl = ref()
  218. const getPreviewFileUrl = (file: File) => {
  219. let fileReader = new FileReader()
  220. fileReader.onload = () => {
  221. previewUrl.value = fileReader.result
  222. }
  223. if (getFileExtension(file.name) === 'docx') fileReader.readAsArrayBuffer(file)
  224. else {
  225. const pdfBlob = new Blob([file], { type: 'application/pdf' })
  226. previewUrl.value = URL.createObjectURL(pdfBlob)
  227. }
  228. }
  229. // 文件类型校验
  230. const handleChange: UploadProps['onChange'] = (file, uploadFiles) => {
  231. console.log(file, uploadFiles)
  232. const allowedExtensions = accept.toLowerCase().split(',')
  233. const fileExt = '.' + (getFileExtension(file.name) || '')
  234. if (!allowedExtensions.includes(fileExt)) {
  235. ElMessage.error(`不支持的文件类型,仅允许上传: ${allowedExtensions.join(',')}类型文件`)
  236. uploadFiles.splice(uploadFiles.indexOf(file), 1)
  237. return false // 阻止上传
  238. }
  239. previewUrl.value = null
  240. file.raw && getPreviewFileUrl(file.raw as File)
  241. }
  242. /** 文件数超出提示 */
  243. const handleExceed = (): void => {
  244. ElMessage.error('最多只能上传一个文件!')
  245. }
  246. /** 上传错误处理 */
  247. const handleUploadError = (): void => {
  248. fileLoading.value = false
  249. }
  250. // 文件上传方法
  251. const handlePostFile = async (options: UploadRequestOptions) => {
  252. const { file, onProgress, onSuccess, onError } = options
  253. fileLoading.value = true
  254. try {
  255. // 上传文件
  256. const formData = new FormData()
  257. formData.append('file', file)
  258. const manualUrl = await uploadFile(formData)
  259. // 更新文件列表
  260. fileList.value = [
  261. {
  262. ...file,
  263. response: manualUrl,
  264. name: file.name,
  265. status: 'success',
  266. url: manualUrl,
  267. uid: file.uid || Date.now() + Math.random()
  268. }
  269. ]
  270. onSuccess(manualUrl)
  271. handleSubmitOperationReport(manualUrl)
  272. } catch (error: any) {
  273. onError(error)
  274. ElMessage.error('上传失败,请您重新上传!')
  275. } finally {
  276. fileLoading.value = false
  277. }
  278. }
  279. // 提交审核
  280. const handleSubmitOperationReport = async (manualUrl = '') => {
  281. // 弹窗选择审批人
  282. const { reportId, templateId, prepareJson } = props.editInspectionplanParams
  283. const params: Recordable = {
  284. id: reportId,
  285. prepareJson: prepareJson,
  286. auditUserIds: [formData.value.inspectionAuditId],
  287. approveUserIds: [formData.value.inspectionApproveId],
  288. reportType: PressureReportType['INSPECTIONPLAN']
  289. // 检验方案,
  290. // reportUrl: uploadUrl,
  291. }
  292. if(manualUrl) params.manualUrl = manualUrl
  293. const submitRes = await BoilerTaskOrderApi.submitOpinionNoticeApproval(params)
  294. if (submitRes) {
  295. ElMessage.success('提交审核成功')
  296. handleCloseModal()
  297. }
  298. }
  299. // 提交保存 - 不需要审核
  300. const handleSubmitNotApproval = async () => {
  301. // 弹窗选择审批人
  302. const { reportId} = props.editInspectionplanParams
  303. const params: Recordable = {
  304. id: reportId,
  305. reportType: PressureReportType['INSPECTIONPLAN'],
  306. }
  307. const submitRes = await BoilerTaskOrderApi.generateInspectionPlan(params)
  308. if (submitRes) {
  309. ElMessage.success('提交成功')
  310. handleCloseModal()
  311. }
  312. }
  313. const handleSubmitConfirm = () => {
  314. approvalUserVisible.value = false
  315. // if(props.isEdit === 'add'){
  316. // fileList.value[0]?.url ? handleSubmitOperationReport(fileList.value[0].url) : uploadRef.value.submit()
  317. // } else {
  318. // handleSubmitOperationReport()
  319. // }
  320. fileList.value[0]?.url ? handleSubmitOperationReport(fileList.value[0].url) : uploadRef.value.submit()
  321. }
  322. const handleSubmitBefore = async () => {
  323. try {
  324. await editSpreadRecordRef.value?.handleSave()
  325. } catch (error) {
  326. console.error('保存数据失败:', error)
  327. ElMessage.error('保存数据失败,请重试')
  328. return
  329. }
  330. // console.log(props.editInspectionplanParams, 'props.editInspectionplanParams')
  331. // if (props.isEdit === 'add' && !fileList.value.length) return ElMessage.error('请先上传方案文件')
  332. if (!fileList.value.length) return ElMessage.error('请先上传方案文件')
  333. getSchemeReviewerList()
  334. }
  335. // 关闭弹窗
  336. const handleCloseModal = () => {
  337. visible.value = false
  338. emits('refresh')
  339. }
  340. const pdfContentWidth = ref(0)
  341. const wrapperContainerRef = ref<HTMLDivElement | null>(null)
  342. const handleWindowResize = debounce(() => {
  343. if(wrapperContainerRef.value){
  344. console.log('wrapperContainerRef.value:log', wrapperContainerRef.value)
  345. const currentWidth = wrapperContainerRef.value?.clientWidth
  346. pdfContentWidth.value = currentWidth > 950 ? 950 : currentWidth - 20
  347. }
  348. }, 100)
  349. const initData=ref<InitParams>(
  350. {
  351. templateId: '',
  352. refId: '',
  353. refName:'',
  354. insId:'',
  355. opType: 1, // 0:excel,1: pdf
  356. manualUrl: '',
  357. });
  358. const editData=ref<InitParams>(
  359. {
  360. templateId: '',
  361. refId: '',
  362. refName:'',
  363. insId:'',
  364. opType: 0, // 0:excel,1: pdf
  365. });
  366. const spreadRef=ref();
  367. const editSpreadRecordRef=ref();
  368. const saveSuccessRecord = async (data)=>{
  369. handleSuccess()
  370. showInlineEditRecord.value = false
  371. }
  372. const editPreview=()=>{
  373. editData.value.templateId = props.editInspectionplanParams.templateId;
  374. editData.value.refId = props.editInspectionplanParams.reportId;
  375. editData.value.opType = 0;
  376. setTimeout(()=>{
  377. editSpreadRecordRef.value?.reloadView();
  378. },50)
  379. console.log('editDataPreview', editData.value)
  380. }
  381. const initPreview=()=>{
  382. initData.value.templateId = props.editInspectionplanParams.templateId;
  383. initData.value.refId = props.editInspectionplanParams.reportId;
  384. initData.value.opType = 1;
  385. initData.value.manualUrl = props.inspectionplanDetail?.manualUrl;
  386. setTimeout(()=>{
  387. spreadRef.value?.reloadView();
  388. },50)
  389. console.log('initPreview', initData.value)
  390. }
  391. onMounted(()=>{
  392. handleWindowResize()
  393. // console.log('wrapperContainerHeight.value ', wrapperContainerHeight.value)
  394. window.addEventListener('resize', handleWindowResize)
  395. // initPreview()
  396. if (['add', 'edit'].includes(props.isEdit)){
  397. editPreview()
  398. }else{
  399. initPreview()
  400. }
  401. })
  402. onUnmounted(() => {
  403. window.removeEventListener('resize', handleWindowResize)
  404. })
  405. </script>
  406. <style lang="scss" scoped>
  407. :deep(.app-container) {
  408. position: relative;
  409. }
  410. .check-record-wrapper {
  411. position: absolute;
  412. left: 0;
  413. right: 0;
  414. top: 0;
  415. bottom: 0;
  416. z-index: 2000;
  417. :deep(.el-card__body) {
  418. display: flex;
  419. justify-content: space-between;
  420. align-items: stretch;
  421. height: calc(100% - 58px);
  422. }
  423. :deep(.spread-designer-container) {
  424. height: calc(
  425. 100vh - var(--top-tool-height) - var(--tags-view-height) - var(--app-footer-height) - 64px
  426. );
  427. padding: 0;
  428. border: 1px solid var(--el-border-color);
  429. border-right-width: 0px;
  430. }
  431. .designer-inner {
  432. width: calc(100% - 440px);
  433. flex: 1;
  434. position: relative;
  435. }
  436. .operation-inner {
  437. display: flex;
  438. flex-direction: column;
  439. gap: 10px;
  440. height: 100%;
  441. flex-basis: 440px;
  442. padding: 7px 10px 20px 10px;
  443. border: 1px solid var(--el-border-color);
  444. background-color: #fff;
  445. box-sizing: border-box;
  446. overflow: hidden;
  447. .btn-list {
  448. padding: 5px 0 2px;
  449. }
  450. .version-box {
  451. padding: 8px 0 12px;
  452. }
  453. .operation-item {
  454. position: relative;
  455. // max-height: calc(100% / 3);
  456. overflow: hidden;
  457. .item-header {
  458. position: sticky;
  459. left: 0;
  460. top: 0;
  461. z-index: 1000;
  462. width: 100%;
  463. height: 28px;
  464. padding-left: 20px;
  465. font-size: 16px;
  466. line-height: 28px;
  467. color: #fff;
  468. background: #fff url(@/assets/imgs/pressure/my-task-detail-operation-bg.png) no-repeat left
  469. top;
  470. background-size: 100% 28px;
  471. }
  472. .item-content {
  473. // height: calc(100% - 48px);
  474. height: auto;
  475. padding: 10px 0;
  476. font-size: 14px;
  477. overflow-y: auto;
  478. overflow-x: hidden;
  479. box-sizing: content-box;
  480. .el-empty {
  481. width: 100%;
  482. height: 150px;
  483. padding: 0;
  484. box-sizing: border-box;
  485. }
  486. }
  487. &:last-child {
  488. // max-height: unset;
  489. // flex-grow: 1;
  490. flex: 1;
  491. .item-content {
  492. height: calc(100% - 48px);
  493. }
  494. }
  495. :deep(.smart-table-inner .toolbar) {
  496. margin: 0 !important;
  497. }
  498. .error-item {
  499. display: flex;
  500. align-items: center;
  501. padding: 7px 10px;
  502. color: #41475c;
  503. border: 1px solid var(--el-border-color);
  504. border-width: 1px 0 1px 0;
  505. background-color: #f5f5fa;
  506. .el-icon {
  507. margin-right: 6px;
  508. }
  509. &:nth-child(n + 1) {
  510. margin-top: -1px;
  511. }
  512. &:nth-child(even) {
  513. background-color: #fff;
  514. }
  515. }
  516. }
  517. }
  518. }
  519. .history-version-table {
  520. height: 100%;
  521. display: flex;
  522. flex-direction: column;
  523. overflow: hidden;
  524. :deep(.smart-table-inner) {
  525. flex: 1;
  526. display: flex;
  527. flex-direction: column;
  528. // border: 1px solid red;
  529. overflow: hidden;
  530. .smart-table-table {
  531. flex: 1;
  532. overflow: hidden;
  533. .el-table {
  534. height: calc(100% - 52px);
  535. }
  536. }
  537. }
  538. }
  539. </style>
  540. <style>
  541. .docx-wrapper {
  542. background-color: #fff !important;
  543. }
  544. .docx-wrapper > section.docx {
  545. box-shadow: none !important;
  546. }
  547. </style>