reportTemplateWrapper.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <ele-modal
  3. :visible="visible"
  4. width="70%"
  5. append-to-body
  6. title="检测报告"
  7. @close="cancel"
  8. :maxable="true"
  9. >
  10. <div class="switch">
  11. <div class="switch_left">
  12. <ul>
  13. <li
  14. v-for="item in tabOptions"
  15. :key="item.key"
  16. :class="{ active: activeComp == item.key }"
  17. @click="activeComp = item.key"
  18. >
  19. {{ item.name }}
  20. </li>
  21. </ul>
  22. </div>
  23. </div>
  24. <component
  25. :is="targetComponent"
  26. ref="templateRef"
  27. v-if="visible"
  28. v-show="activeComp == 'main'"
  29. :key="componentName"
  30. :isView="isView"
  31. :type="type"
  32. ></component>
  33. <template v-slot:footer>
  34. <el-button v-if="isView" type="primary" @click="print">打印</el-button>
  35. <el-button v-if="!isView" type="primary" @click="save">确认</el-button>
  36. <el-button
  37. v-if="!isView && isReportApproval == 1"
  38. type="primary"
  39. @click="save('submit')"
  40. >提交</el-button
  41. >
  42. <el-button @click="cancel">关闭</el-button>
  43. </template>
  44. <unqualifiedProduct
  45. ref="unqualifiedProductRef"
  46. v-show="activeComp == 'unqualifiedList'"
  47. @setQualifiedNumber="setQualifiedNumber"
  48. :total="basicInfoData.total"
  49. :isView="isView"
  50. @setLossNumber="setLossNumber"
  51. >
  52. </unqualifiedProduct>
  53. <div style="margin-top: 10px" v-if="activeComp != 'bpm'">
  54. 结论:
  55. <el-select
  56. v-model="basicInfoData.qualityResults"
  57. placeholder="请选择"
  58. style="width: 120px"
  59. @change="selectResult"
  60. :disabled="isView"
  61. >
  62. <el-option label="整单合格" :value="1" />
  63. <el-option label="整单不合格" :value="2" />
  64. <el-option label="部分合格" :value="3" />
  65. <el-option label="整单让步接收" :value="4" />
  66. </el-select>
  67. 合格数:
  68. <el-input
  69. v-model="basicInfoData.qualifiedNumber"
  70. placeholder="合格数"
  71. style="width: 110px"
  72. disabled
  73. ></el-input>
  74. 不合格数:
  75. <el-input
  76. v-model="basicInfoData.noQualifiedNumber"
  77. placeholder="不合格数"
  78. disabled
  79. style="width: 110px"
  80. ></el-input>
  81. 留样数(合格):
  82. <el-input
  83. v-model="basicInfoData.retainedSampleQuantity"
  84. placeholder=" "
  85. disabled
  86. style="width: 80px"
  87. ></el-input>
  88. 留样数(不合格):
  89. <el-input
  90. v-model="basicInfoData.retainedSampleUnqualified"
  91. placeholder=" "
  92. disabled
  93. style="width: 80px"
  94. ></el-input>
  95. 消耗数(合格):
  96. <el-input
  97. v-model="basicInfoData.lossNumber"
  98. placeholder=" "
  99. disabled
  100. style="width: 80px"
  101. ></el-input>
  102. 消耗数(不合格):
  103. <el-input
  104. v-model="basicInfoData.lossNumberUnqualified"
  105. placeholder=" "
  106. disabled
  107. style="width: 80px"
  108. ></el-input>
  109. </div>
  110. <bpmDetail
  111. v-if="activeComp === 'bpm' && processInstanceId"
  112. :id="processInstanceId"
  113. ></bpmDetail>
  114. <processSubmitDialog
  115. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  116. v-if="processSubmitDialogFlag"
  117. ref="processSubmitDialogRef"
  118. @reload="search"
  119. ></processSubmitDialog>
  120. </ele-modal>
  121. </template>
  122. <script>
  123. import inspection_report1 from '../template/inspection_report1.vue';
  124. import inspection_report2 from '../template/inspection_report2.vue';
  125. import inspection_report4 from '../template/inspection_report4.vue';
  126. import processSubmitDialog from '@/components/processSubmitDialog/processSubmitDialog.vue';
  127. import { getCategoryByCode, parameterGetByCode } from '@/api/main/index';
  128. import {
  129. queryInspectionReportData,
  130. queryInspectionReportList,
  131. generateReport,
  132. enterprisePage
  133. } from '@/api/inspectionReport';
  134. import bpmDetail from '@/views/bpm/processInstance/detail.vue';
  135. import unqualifiedProduct from '@/views/inspectionReport/components/unqualifiedProduct.vue';
  136. import { getList } from '@/api/unacceptedProduct/index';
  137. import { getCode } from '@/api/login';
  138. const defForm = {
  139. poList: [],
  140. unqualifiedProductsCode: '',
  141. sourceCode: '',
  142. batchNo: '',
  143. brandNum: '',
  144. categoryCode: '',
  145. categoryId: '',
  146. categoryName: '',
  147. specification: '',
  148. modelType: '',
  149. produceRoutingId: '',
  150. produceRoutingName: '',
  151. taskId: '',
  152. taskName: '',
  153. quantity: '',
  154. measureQuantity: '',
  155. measureUnit: '',
  156. weight: '',
  157. weightUnit: '',
  158. qualityType: ''
  159. };
  160. export default {
  161. name: 'ReportTemplateWrapper',
  162. components: {
  163. inspection_report1,
  164. inspection_report2,
  165. inspection_report4,
  166. unqualifiedProduct,
  167. bpmDetail,
  168. processSubmitDialog
  169. },
  170. data() {
  171. return {
  172. unqualifiedProducts: {
  173. ...defForm
  174. },
  175. isReportApproval: 0,
  176. isView: false,
  177. visible: false,
  178. loading: false,
  179. processSubmitDialogFlag: false,
  180. currentRow: {}, // 存储当前行数据
  181. templateItem: {}, // 存储当前模板项数据
  182. // 基本信息数据
  183. basicInfoData: {},
  184. componentName: '',
  185. // 检验项目
  186. inspectionItems: [],
  187. tabOptions: [],
  188. activeComp: 'main',
  189. processInstanceId: '',
  190. reportApprovalTaskVos: [],
  191. groupName: ''
  192. };
  193. },
  194. props: {
  195. type: {
  196. type: String,
  197. default: '0'
  198. }
  199. },
  200. methods: {
  201. /* 打开质检报告 */
  202. async open({ row, item }, isView) {
  203. parameterGetByCode({
  204. code: 'qms_report_approval'
  205. }).then((res) => {
  206. this.isReportApproval = res.value;
  207. });
  208. this.activeComp = 'main';
  209. this.isView = isView;
  210. this.componentName = row.reportTemplateCode;
  211. this.currentRow = row;
  212. this.templateItem = item?.id ? item : row;
  213. this.processInstanceId = row.reportProcessInstanceId;
  214. this.reportApprovalTaskVos = row.reportApprovalTaskVos;
  215. this.tabOptions = [{ key: 'main', name: '业务详情' }];
  216. if (isView) {
  217. this.tabOptions.push({
  218. key: 'unqualifiedList',
  219. name: '不合格品台账'
  220. });
  221. }
  222. if (this.processInstanceId) {
  223. this.tabOptions.push({ key: 'bpm', name: '流程详情' });
  224. }
  225. this.visible = true;
  226. if (this.currentRow.reportTemplateJson?.basicInfoData) {
  227. this.basicInfoData =
  228. this.currentRow.reportTemplateJson.basicInfoData || {};
  229. this.inspectionItems =
  230. this.currentRow.reportTemplateJson.inspectionItems || [];
  231. const reviewTime =
  232. this.reportApprovalTaskVos?.[
  233. this.reportApprovalTaskVos.length - 2
  234. ]?.endTime?.split(' ')[0] || '';
  235. const approvedDate =
  236. this.reportApprovalTaskVos?.[
  237. this.reportApprovalTaskVos.length - 3
  238. ]?.endTime?.split(' ')[0] || '';
  239. const reviewer =
  240. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 2]
  241. ?.approvalUserName || '';
  242. const checker =
  243. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 3]
  244. ?.approvalUserName || '';
  245. this.$set(
  246. this.basicInfoData,
  247. 'inspectionTime',
  248. this.basicInfoData.inspectionTime?.split(' ')[0] || ''
  249. );
  250. this.$set(
  251. this.basicInfoData,
  252. 'reviewTime',
  253. this.basicInfoData.reviewTime?.split(' ')[0] || reviewTime || ''
  254. );
  255. this.$set(
  256. this.basicInfoData,
  257. 'approvedDate',
  258. this.basicInfoData.approvedDate?.split(' ')[0] || approvedDate || ''
  259. );
  260. this.$set(
  261. this.basicInfoData,
  262. 'reviewer',
  263. this.basicInfoData.reviewer || reviewer || ''
  264. );
  265. this.$set(
  266. this.basicInfoData,
  267. 'checker',
  268. this.basicInfoData.checker || checker || ''
  269. );
  270. this.$set(
  271. this.basicInfoData,
  272. 'qualityResults',
  273. this.basicInfoData.qualityResults
  274. );
  275. this.$set(
  276. this.basicInfoData,
  277. 'qualifiedNumber',
  278. this.basicInfoData.qualifiedNumber
  279. );
  280. this.$set(
  281. this.basicInfoData,
  282. 'noQualifiedNumber',
  283. this.basicInfoData.noQualifiedNumber
  284. );
  285. this.$nextTick(() => {
  286. this.$refs.templateRef.init(
  287. this.basicInfoData,
  288. this.inspectionItems
  289. );
  290. });
  291. this.initUnqualifiedProduct();
  292. } else {
  293. await this.getBasicInfo();
  294. await this.getInspectionItems();
  295. await this.enterprisePage();
  296. this.$nextTick(() => {
  297. this.$refs.templateRef.init(
  298. this.basicInfoData,
  299. this.inspectionItems
  300. );
  301. });
  302. }
  303. },
  304. async initUnqualifiedProduct() {
  305. const data = await getList({
  306. sourceCode: this.currentRow.code
  307. });
  308. if (data.list[0]) {
  309. this.unqualifiedProducts = data.list[0];
  310. }
  311. this.$nextTick(() => {
  312. this.$refs.unqualifiedProductRef.init({
  313. id: this.unqualifiedProducts?.id,
  314. qualityType: this.basicInfoData.qualityType,
  315. workOrderCode: this.currentRow.code,
  316. qualityWorkerId: this.basicInfoData.qualityWorkerId,
  317. workOrderId: this.currentRow.workOrderId,
  318. qualityResults: this.basicInfoData.qualityResults
  319. });
  320. });
  321. },
  322. setQualifiedNumber(data) {
  323. this.basicInfoData.qualifiedNumber = data.qualifiedNumber;
  324. this.basicInfoData.noQualifiedNumber = data.noQualifiedNumber;
  325. if (!data.noQualifiedNumber) {
  326. if (data.isQualifiedNumber) {
  327. this.basicInfoData.qualityResults = 1;
  328. } else {
  329. this.basicInfoData.qualityResults = 4;
  330. }
  331. }
  332. if (!data.qualifiedNumber) {
  333. this.basicInfoData.qualityResults = 2;
  334. }
  335. if (data.qualifiedNumber && data.noQualifiedNumber) {
  336. this.basicInfoData.qualityResults = 3;
  337. }
  338. },
  339. selectResult() {
  340. this.$refs.unqualifiedProductRef.selectResult(
  341. this.basicInfoData.qualityResults
  342. );
  343. },
  344. getBasicInfo() {
  345. return queryInspectionReportData({
  346. id: this.currentRow.id,
  347. type: this.type || this.currentRow.type || 0
  348. }).then((res) => {
  349. this.basicInfoData = res;
  350. this.basicInfoData.reportCode = res.reportCode || '';
  351. const reviewTime =
  352. this.reportApprovalTaskVos?.[
  353. this.reportApprovalTaskVos.length - 2
  354. ]?.endTime?.split(' ')[0] || '';
  355. const approvedDate =
  356. this.reportApprovalTaskVos?.[
  357. this.reportApprovalTaskVos.length - 3
  358. ]?.endTime?.split(' ')[0] || '';
  359. const reviewer =
  360. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 2]
  361. ?.approvalUserName || '';
  362. const checker =
  363. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 3]
  364. ?.approvalUserName || '';
  365. this.$set(
  366. this.basicInfoData,
  367. 'version',
  368. this.templateItem.versionSymbol +
  369. this.templateItem.bigVersion +
  370. this.templateItem.versionMark +
  371. this.templateItem.smallVersion
  372. );
  373. this.$set(
  374. this.basicInfoData,
  375. 'inspectionTime',
  376. this.basicInfoData.inspectionTime?.split(' ')[0] || ''
  377. );
  378. this.$set(
  379. this.basicInfoData,
  380. 'reviewTime',
  381. this.basicInfoData.reviewTime?.split(' ')[0] || reviewTime || ''
  382. );
  383. this.$set(
  384. this.basicInfoData,
  385. 'approvedDate',
  386. this.basicInfoData.approvedDate?.split(' ')[0] || approvedDate || ''
  387. );
  388. this.$set(
  389. this.basicInfoData,
  390. 'reviewer',
  391. this.basicInfoData.reviewer || reviewer || ''
  392. );
  393. this.$set(
  394. this.basicInfoData,
  395. 'checker',
  396. this.basicInfoData.checker || checker || ''
  397. );
  398. this.$set(
  399. this.basicInfoData,
  400. 'qualityResults',
  401. this.currentRow.noQualifiedNumber == this.basicInfoData.total
  402. ? 2
  403. : this.currentRow.noQualifiedNumber == 0
  404. ? 1
  405. : 3
  406. );
  407. this.$set(
  408. this.basicInfoData,
  409. 'qualifiedNumber',
  410. this.currentRow.qualifiedNumber
  411. );
  412. this.$set(
  413. this.basicInfoData,
  414. 'noQualifiedNumber',
  415. this.currentRow.noQualifiedNumber
  416. );
  417. this.$set(
  418. this.basicInfoData,
  419. 'noQualifiedNumber',
  420. this.currentRow.noQualifiedNumber
  421. );
  422. this.$set(this.basicInfoData, 'qualityWorkerId', this.currentRow.id);
  423. this.$set(
  424. this.basicInfoData,
  425. 'workOrderId',
  426. this.currentRow.workOrderId
  427. );
  428. this.$set(this.basicInfoData, 'type', this.type || 0);
  429. this.$set(
  430. this.basicInfoData,
  431. 'qualityType',
  432. this.currentRow.qualityType
  433. );
  434. if (!this.basicInfoData.reportNumber) {
  435. getCode('quality_Inspection_report_number').then((res) => {
  436. this.$set(this.basicInfoData, 'reportNumber', res);
  437. });
  438. }
  439. this.initUnqualifiedProduct();
  440. });
  441. },
  442. getInspectionItems() {
  443. return queryInspectionReportList({
  444. id: this.currentRow.id,
  445. type: this.type || this.currentRow.type || 0
  446. }).then((res) => {
  447. this.inspectionItems = res;
  448. });
  449. },
  450. enterprisePage() {
  451. return enterprisePage({
  452. pageNum: 1,
  453. size: 200
  454. }).then((res) => {
  455. if (res.list?.length > 0) {
  456. this.$set(this.basicInfoData, 'groupName', res.list[0].name);
  457. }
  458. });
  459. },
  460. setLossNumber({
  461. lossNumber,
  462. lossNumberUnqualified,
  463. retainedSampleQuantity,
  464. retainedSampleUnqualified
  465. }) {
  466. this.$set(
  467. this.basicInfoData,
  468. 'retainedSampleQuantity',
  469. retainedSampleQuantity
  470. );
  471. this.$set(
  472. this.basicInfoData,
  473. 'retainedSampleUnqualified',
  474. retainedSampleUnqualified
  475. );
  476. this.$set(this.basicInfoData, 'lossNumber', lossNumber);
  477. this.$set(
  478. this.basicInfoData,
  479. 'lossNumberUnqualified',
  480. lossNumberUnqualified
  481. );
  482. },
  483. cancel() {
  484. this.visible = false;
  485. this.$emit('close');
  486. this.unqualifiedProducts = { ...defForm };
  487. this.basicInfoData = {};
  488. },
  489. /* 打印 */
  490. print() {
  491. const printSection = document.getElementById('printSection');
  492. console.log('printSection', printSection.innerHTML);
  493. // 创建打印任务
  494. const printWindow = window.open('', '_blank');
  495. printWindow.document.open();
  496. printWindow.document.write('<html><head><title>打印预览</title>');
  497. printWindow.document.write(
  498. '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
  499. );
  500. printWindow.document.write('</head><body>');
  501. printWindow.document.write(printSection.innerHTML);
  502. printWindow.document.write('</body></html>');
  503. printWindow.document.close();
  504. printWindow.onload = function () {
  505. printWindow.print();
  506. };
  507. },
  508. /* 保存编辑 */
  509. save(type) {
  510. this.loading = true;
  511. this.isView = true;
  512. this.$nextTick(() => {
  513. const printSection = document.getElementById('printSection');
  514. const params = {
  515. id: this.currentRow.id,
  516. type: this.type || this.basicInfoData.type || 0,
  517. reportTemplateId:
  518. this.templateItem.reportTemplateId || this.templateItem.id,
  519. reportTemplateCode:
  520. this.templateItem.reportTemplateCode || this.templateItem.code,
  521. reportTemplateName:
  522. this.templateItem.reportTemplateName || this.templateItem.name,
  523. unqualifiedProducts: this.$refs.unqualifiedProductRef.getValue(),
  524. reportTemplateJson: {
  525. template: printSection.innerHTML,
  526. basicInfoData: this.$refs.templateRef.getValue(),
  527. inspectionItems: this.inspectionItems
  528. }
  529. };
  530. generateReport(params)
  531. .then((res) => {
  532. this.loading = false;
  533. this.isView = false;
  534. this.$message({
  535. message: '保存成功',
  536. type: 'success'
  537. });
  538. if (type == 'submit') {
  539. this.approvalSubmit(this.currentRow.id);
  540. } else {
  541. this.cancel();
  542. this.$emit('reload');
  543. }
  544. })
  545. .catch((err) => {
  546. this.loading = false;
  547. this.isView = false;
  548. this.$message({
  549. message: err.message,
  550. type: 'error'
  551. });
  552. });
  553. });
  554. },
  555. approvalSubmit(id) {
  556. this.processSubmitDialogFlag = true;
  557. this.$nextTick(async () => {
  558. let params = {
  559. businessId: id,
  560. businessKey: 'qms_report_approval',
  561. // formCreateUserId: this.basicInfoData.createUserId,
  562. variables: {
  563. businessCode: this.basicInfoData.code,
  564. businessName: this.basicInfoData.reportNumber,
  565. businessType: '检测报告单'
  566. }
  567. };
  568. if (this.clientEnvironmentId == 5) {
  569. const data = await getCategoryByCode(res.productCode);
  570. if (data && data.categoryLevelCodePath?.includes('W3-209')) {
  571. params.businessKey = 'qms_report_approval1';
  572. } else {
  573. params.businessKey = 'qms_report_approval';
  574. }
  575. }
  576. this.$refs.processSubmitDialogRef.init(params);
  577. });
  578. },
  579. search() {
  580. this.$emit('reload');
  581. this.cancel();
  582. }
  583. },
  584. computed: {
  585. clientEnvironmentId() {
  586. return this.$store.state.user.info.clientEnvironmentId;
  587. },
  588. targetComponent() {
  589. return this.componentName;
  590. }
  591. }
  592. };
  593. </script>