reportTemplateWrapper.vue 18 KB

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