AddInspectionplanDetail.vue 16 KB

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