reportTemplateWrapper.vue 16 KB

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