reportTemplateWrapper.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <template>
  2. <ele-modal
  3. :visible="visible"
  4. width="80%"
  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 inspection_report5 from '../template/inspection_report5.vue';
  127. import inspection_report6 from '../template/inspection_report6.vue';
  128. import processSubmitDialog from '@/components/processSubmitDialog/processSubmitDialog.vue';
  129. import { getCategoryByCode, parameterGetByCode } from '@/api/main/index';
  130. import {
  131. queryInspectionReportData,
  132. queryInspectionReportList,
  133. generateReport,
  134. enterprisePage
  135. } from '@/api/inspectionReport';
  136. import bpmDetail from '@/views/bpm/processInstance/detail.vue';
  137. import unqualifiedProduct from '@/views/inspectionReport/components/unqualifiedProduct.vue';
  138. import { getList } from '@/api/unacceptedProduct/index';
  139. import { getCode } from '@/api/login';
  140. import { getCurrentUserCompanyName } from '@/utils/org-util';
  141. const defForm = {
  142. poList: [],
  143. unqualifiedProductsCode: '',
  144. sourceCode: '',
  145. batchNo: '',
  146. brandNum: '',
  147. categoryCode: '',
  148. categoryId: '',
  149. categoryName: '',
  150. specification: '',
  151. modelType: '',
  152. produceRoutingId: '',
  153. produceRoutingName: '',
  154. taskId: '',
  155. taskName: '',
  156. quantity: '',
  157. measureQuantity: '',
  158. measureUnit: '',
  159. weight: '',
  160. weightUnit: '',
  161. qualityType: ''
  162. };
  163. export default {
  164. name: 'ReportTemplateWrapper',
  165. components: {
  166. inspection_report1,
  167. inspection_report2,
  168. inspection_report4,
  169. inspection_report5,
  170. inspection_report6,
  171. unqualifiedProduct,
  172. bpmDetail,
  173. processSubmitDialog
  174. },
  175. data() {
  176. return {
  177. unqualifiedProducts: {
  178. ...defForm
  179. },
  180. isReportApproval: 0,
  181. isView: false,
  182. visible: false,
  183. loading: false,
  184. processSubmitDialogFlag: false,
  185. currentRow: {}, // 存储当前行数据
  186. templateItem: {}, // 存储当前模板项数据
  187. // 基本信息数据
  188. basicInfoData: {},
  189. componentName: '',
  190. // 检验项目
  191. inspectionItems: [],
  192. tabOptions: [],
  193. activeComp: 'main',
  194. processInstanceId: '',
  195. reportApprovalTaskVos: [],
  196. groupName: ''
  197. };
  198. },
  199. props: {
  200. type: {
  201. type: String,
  202. default: '0'
  203. }
  204. },
  205. methods: {
  206. /* 打开质检报告 */
  207. async open({ row, item }, isView) {
  208. parameterGetByCode({
  209. code: 'qms_report_approval'
  210. }).then((res) => {
  211. this.isReportApproval = res.value;
  212. });
  213. this.activeComp = 'main';
  214. this.isView = isView;
  215. this.componentName = row.reportTemplateCode;
  216. this.currentRow = row;
  217. this.templateItem = item?.id ? item : row;
  218. this.processInstanceId = row.reportProcessInstanceId;
  219. this.reportApprovalTaskVos = row.reportApprovalTaskVos;
  220. this.tabOptions = [{ key: 'main', name: '业务详情' }];
  221. if (isView) {
  222. this.tabOptions.push({
  223. key: 'unqualifiedList',
  224. name: '不合格品台账'
  225. });
  226. }
  227. if (this.processInstanceId) {
  228. this.tabOptions.push({ key: 'bpm', name: '流程详情' });
  229. }
  230. this.visible = true;
  231. if (this.currentRow.reportTemplateJson?.basicInfoData) {
  232. this.basicInfoData =
  233. this.currentRow.reportTemplateJson.basicInfoData || {};
  234. this.inspectionItems =
  235. this.currentRow.reportTemplateJson.inspectionItems || [];
  236. const reviewTime =
  237. this.reportApprovalTaskVos?.[
  238. this.reportApprovalTaskVos.length - 2
  239. ]?.endTime?.split(' ')[0] || '';
  240. const approvedDate =
  241. this.reportApprovalTaskVos?.[
  242. this.reportApprovalTaskVos.length - 3
  243. ]?.endTime?.split(' ')[0] || '';
  244. const reviewer =
  245. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 2]
  246. ?.approvalUserName || '';
  247. const checker =
  248. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 3]
  249. ?.approvalUserName || '';
  250. this.$set(
  251. this.basicInfoData,
  252. 'inspectionTime',
  253. this.basicInfoData.inspectionTime?.split(' ')[0] || ''
  254. );
  255. this.$set(
  256. this.basicInfoData,
  257. 'reviewTime',
  258. this.basicInfoData.reviewTime?.split(' ')[0] || reviewTime || ''
  259. );
  260. this.$set(
  261. this.basicInfoData,
  262. 'approvedDate',
  263. this.basicInfoData.approvedDate?.split(' ')[0] || approvedDate || ''
  264. );
  265. this.$set(
  266. this.basicInfoData,
  267. 'reviewer',
  268. this.basicInfoData.reviewer || reviewer || ''
  269. );
  270. this.$set(
  271. this.basicInfoData,
  272. 'checker',
  273. this.basicInfoData.checker || checker || ''
  274. );
  275. this.$set(
  276. this.basicInfoData,
  277. 'qualityResults',
  278. this.basicInfoData.qualityResults
  279. );
  280. this.$set(
  281. this.basicInfoData,
  282. 'qualifiedNumber',
  283. this.basicInfoData.qualifiedNumber
  284. );
  285. this.$set(
  286. this.basicInfoData,
  287. 'noQualifiedNumber',
  288. this.basicInfoData.noQualifiedNumber
  289. );
  290. this.$nextTick(() => {
  291. this.$refs.templateRef.init(
  292. this.basicInfoData,
  293. this.inspectionItems
  294. );
  295. });
  296. this.initUnqualifiedProduct();
  297. } else {
  298. await this.getBasicInfo();
  299. await this.getInspectionItems();
  300. await this.enterprisePage();
  301. this.$nextTick(() => {
  302. this.$refs.templateRef.init(
  303. this.basicInfoData,
  304. this.inspectionItems
  305. );
  306. });
  307. }
  308. },
  309. async initUnqualifiedProduct() {
  310. const data = await getList({
  311. sourceCode: this.currentRow.code
  312. });
  313. if (data.list[0]) {
  314. this.unqualifiedProducts = data.list[0];
  315. }
  316. this.$nextTick(() => {
  317. this.$refs.unqualifiedProductRef.init({
  318. id: this.unqualifiedProducts?.id,
  319. qualityType: this.basicInfoData.qualityType,
  320. workOrderCode: this.currentRow.code,
  321. qualityWorkerId: this.basicInfoData.qualityWorkerId,
  322. workOrderId: this.currentRow.workOrderId,
  323. qualityResults: this.basicInfoData.qualityResults
  324. });
  325. });
  326. },
  327. setQualifiedNumber(data) {
  328. this.basicInfoData.qualifiedNumber = data.qualifiedNumber;
  329. this.basicInfoData.noQualifiedNumber = data.noQualifiedNumber;
  330. if (!data.noQualifiedNumber) {
  331. if (data.isQualifiedNumber) {
  332. this.basicInfoData.qualityResults = 1;
  333. } else {
  334. this.basicInfoData.qualityResults = 4;
  335. }
  336. }
  337. if (!data.qualifiedNumber) {
  338. this.basicInfoData.qualityResults = 2;
  339. }
  340. if (data.qualifiedNumber && data.noQualifiedNumber) {
  341. this.basicInfoData.qualityResults = 3;
  342. }
  343. },
  344. selectResult() {
  345. this.$refs.unqualifiedProductRef.selectResult(
  346. this.basicInfoData.qualityResults
  347. );
  348. },
  349. getBasicInfo() {
  350. return queryInspectionReportData({
  351. id: this.currentRow.id,
  352. type: this.type || this.currentRow.type || 0
  353. }).then((res) => {
  354. this.basicInfoData = res;
  355. this.basicInfoData.reportCode = res.reportCode || '';
  356. const reviewTime =
  357. this.reportApprovalTaskVos?.[
  358. this.reportApprovalTaskVos.length - 2
  359. ]?.endTime?.split(' ')[0] || '';
  360. const approvedDate =
  361. this.reportApprovalTaskVos?.[
  362. this.reportApprovalTaskVos.length - 3
  363. ]?.endTime?.split(' ')[0] || '';
  364. const reviewer =
  365. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 2]
  366. ?.approvalUserName || '';
  367. const checker =
  368. this.reportApprovalTaskVos?.[this.reportApprovalTaskVos.length - 3]
  369. ?.approvalUserName || '';
  370. this.$set(
  371. this.basicInfoData,
  372. 'version',
  373. this.templateItem.versionSymbol +
  374. this.templateItem.bigVersion +
  375. this.templateItem.versionMark +
  376. this.templateItem.smallVersion
  377. );
  378. this.$set(
  379. this.basicInfoData,
  380. 'inspectionTime',
  381. this.basicInfoData.inspectionTime?.split(' ')[0] || ''
  382. );
  383. this.$set(
  384. this.basicInfoData,
  385. 'reviewTime',
  386. this.basicInfoData.reviewTime?.split(' ')[0] || reviewTime || ''
  387. );
  388. this.$set(
  389. this.basicInfoData,
  390. 'approvedDate',
  391. this.basicInfoData.approvedDate?.split(' ')[0] || approvedDate || ''
  392. );
  393. this.$set(
  394. this.basicInfoData,
  395. 'reviewer',
  396. this.basicInfoData.reviewer || reviewer || ''
  397. );
  398. this.$set(
  399. this.basicInfoData,
  400. 'checker',
  401. this.basicInfoData.checker || checker || ''
  402. );
  403. this.$set(
  404. this.basicInfoData,
  405. 'qualityResults',
  406. this.currentRow.noQualifiedNumber == this.basicInfoData.total
  407. ? 2
  408. : this.currentRow.noQualifiedNumber == 0
  409. ? 1
  410. : 3
  411. );
  412. this.$set(
  413. this.basicInfoData,
  414. 'qualifiedNumber',
  415. this.currentRow.qualifiedNumber
  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. 'source',
  432. this.currentRow.workOrderCode
  433. );
  434. console.log(this.currentRow);
  435. this.$set(
  436. this.basicInfoData,
  437. 'qualityType',
  438. this.currentRow.qualityType
  439. );
  440. if (!this.basicInfoData.reportNumber) {
  441. getCode('quality_Inspection_report_number').then((res) => {
  442. this.$set(this.basicInfoData, 'reportNumber', res);
  443. });
  444. }
  445. this.initUnqualifiedProduct();
  446. });
  447. },
  448. getInspectionItems() {
  449. return queryInspectionReportList({
  450. id: this.currentRow.id,
  451. type: this.type || this.currentRow.type || 0
  452. }).then((res) => {
  453. this.inspectionItems = res;
  454. });
  455. },
  456. enterprisePage() {
  457. return enterprisePage({
  458. pageNum: 1,
  459. size: 200
  460. })
  461. .then((res) => {
  462. if (res.list?.length > 0) {
  463. this.$set(this.basicInfoData, 'groupName', res.list[0].name);
  464. }
  465. })
  466. .catch(() => {
  467. // 企业列表取不到不影响报告
  468. })
  469. .then(() => {
  470. // 报告抬头默认取当前登录用户所属公司, 取不到时沿用企业列表第一个
  471. return this.setDefaultGroupName();
  472. });
  473. },
  474. /* 报告抬头公司: 当前登录用户所属公司 */
  475. async setDefaultGroupName() {
  476. const userInfo = this.$store?.state?.user?.info;
  477. if (!userInfo) {
  478. return;
  479. }
  480. const companyName = await getCurrentUserCompanyName(userInfo);
  481. if (companyName) {
  482. this.$set(this.basicInfoData, 'groupName', companyName);
  483. }
  484. },
  485. setLossNumber({
  486. lossNumber,
  487. lossNumberUnqualified,
  488. retainedSampleQuantity,
  489. retainedSampleUnqualified
  490. }) {
  491. this.$set(
  492. this.basicInfoData,
  493. 'retainedSampleQuantity',
  494. retainedSampleQuantity
  495. );
  496. this.$set(
  497. this.basicInfoData,
  498. 'retainedSampleUnqualified',
  499. retainedSampleUnqualified
  500. );
  501. this.$set(this.basicInfoData, 'lossNumber', lossNumber);
  502. this.$set(
  503. this.basicInfoData,
  504. 'lossNumberUnqualified',
  505. lossNumberUnqualified
  506. );
  507. },
  508. cancel() {
  509. this.visible = false;
  510. this.$emit('close');
  511. this.unqualifiedProducts = { ...defForm };
  512. this.basicInfoData = {};
  513. },
  514. /* 打印 */
  515. print() {
  516. const printSection = document.getElementById('printSection');
  517. console.log('printSection', printSection.innerHTML);
  518. // 创建打印任务
  519. const printWindow = window.open('', '_blank');
  520. printWindow.document.open();
  521. printWindow.document.write('<html><head><title>打印预览</title>');
  522. printWindow.document.write(
  523. '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
  524. );
  525. printWindow.document.write('</head><body>');
  526. printWindow.document.write(printSection.innerHTML);
  527. printWindow.document.write('</body></html>');
  528. printWindow.document.close();
  529. printWindow.onload = function () {
  530. printWindow.print();
  531. };
  532. },
  533. /* 保存编辑 */
  534. save(type) {
  535. this.loading = true;
  536. this.isView = true;
  537. this.$nextTick(() => {
  538. const printSection = document.getElementById('printSection');
  539. const params = {
  540. id: this.currentRow.id,
  541. type: this.type || this.basicInfoData.type || 0,
  542. reportTemplateId:
  543. this.templateItem.reportTemplateId || this.templateItem.id,
  544. reportTemplateCode:
  545. this.templateItem.reportTemplateCode || this.templateItem.code,
  546. reportTemplateName:
  547. this.templateItem.reportTemplateName || this.templateItem.name,
  548. unqualifiedProducts: this.$refs.unqualifiedProductRef.getValue(),
  549. reportTemplateJson: {
  550. template: printSection.innerHTML,
  551. basicInfoData: this.$refs.templateRef.getValue(),
  552. inspectionItems: this.inspectionItems
  553. }
  554. };
  555. generateReport(params)
  556. .then((res) => {
  557. this.loading = false;
  558. this.isView = false;
  559. this.$message({
  560. message: '保存成功',
  561. type: 'success'
  562. });
  563. if (type == 'submit') {
  564. this.approvalSubmit(this.currentRow.id);
  565. } else {
  566. this.cancel();
  567. this.$emit('reload');
  568. }
  569. })
  570. .catch((err) => {
  571. this.loading = false;
  572. this.isView = false;
  573. this.$message({
  574. message: err.message,
  575. type: 'error'
  576. });
  577. });
  578. });
  579. },
  580. approvalSubmit(id) {
  581. this.processSubmitDialogFlag = true;
  582. this.$nextTick(async () => {
  583. let params = {
  584. businessId: id,
  585. businessKey: 'qms_report_approval',
  586. // formCreateUserId: this.basicInfoData.createUserId,
  587. variables: {
  588. businessCode: this.basicInfoData.code,
  589. businessName: this.basicInfoData.reportNumber,
  590. businessType: '检测报告单'
  591. }
  592. };
  593. if (this.clientEnvironmentId == 5) {
  594. const data = await getCategoryByCode(res.productCode);
  595. if (data && data.categoryLevelCodePath?.includes('W3-209')) {
  596. params.businessKey = 'qms_report_approval1';
  597. } else {
  598. params.businessKey = 'qms_report_approval';
  599. }
  600. }
  601. this.$refs.processSubmitDialogRef.init(params);
  602. });
  603. },
  604. search() {
  605. this.$emit('reload');
  606. this.cancel();
  607. }
  608. },
  609. computed: {
  610. clientEnvironmentId() {
  611. return this.$store.state.user.info.clientEnvironmentId;
  612. },
  613. targetComponent() {
  614. return this.componentName;
  615. }
  616. }
  617. };
  618. </script>