|
|
@@ -46,7 +46,10 @@
|
|
|
<script>
|
|
|
import dictMixins from '@/mixins/dictMixins';
|
|
|
import tableColumnsMixin from '@/mixins/tableColumnsMixin';
|
|
|
- import { producetaskrulerecordPage } from '@/api/producetaskrulerecord/index';
|
|
|
+ import {
|
|
|
+ producetaskrulerecordPage,
|
|
|
+ queryPrint
|
|
|
+ } from '@/api/producetaskrulerecord/index';
|
|
|
import editModal from '../editModal.vue';
|
|
|
import batchPecordPrint from './batchPecordPrint.vue';
|
|
|
import exportButton from '@/components/upload/exportButton.vue';
|
|
|
@@ -185,11 +188,22 @@
|
|
|
params: {},
|
|
|
tableData: [],
|
|
|
selection: [],
|
|
|
+ printTypeMap: {
|
|
|
+ cleaningRecord: 'CLEANING_RECORD',
|
|
|
+ labelPrintRecord: 'LABEL_PRINT_RECORD',
|
|
|
+ productLabelRecord: 'PRODUCT_LABELING_RECORD',
|
|
|
+ packagingRecord: 'PACKAGING_PROCESS_RECORD',
|
|
|
+ processInspectionRecord: 'PROCESS_INSPECTION_RECORD'
|
|
|
+ },
|
|
|
printOptions: [
|
|
|
{ key: 'cleaningRecord', label: '清场清洁记录表', code: 'SC-033' },
|
|
|
{ key: 'labelPrintRecord', label: '标签打印记录', code: 'SC-102' },
|
|
|
{ key: 'productLabelRecord', label: '产品贴标记录', code: 'SC-050' },
|
|
|
- { key: 'packagingRecord', label: '产品中外包装工序记录', code: 'SC-019' },
|
|
|
+ {
|
|
|
+ key: 'packagingRecord',
|
|
|
+ label: '产品中外包装工序记录',
|
|
|
+ code: 'SC-019'
|
|
|
+ },
|
|
|
{ key: 'processInspectionRecord', label: '过程检验记录', code: 'A0' }
|
|
|
]
|
|
|
};
|
|
|
@@ -277,45 +291,193 @@
|
|
|
openPrint(row) {
|
|
|
this.$refs.batchPecordPrintRef.open(row);
|
|
|
},
|
|
|
- handlePrint(key) {
|
|
|
+ async handlePrint(key) {
|
|
|
if (!this.selection.length) {
|
|
|
this.$message.warning('请先勾选要打印的生产记录');
|
|
|
return;
|
|
|
}
|
|
|
- const r = this.selection[0];
|
|
|
- const today = this.$util?.toDateString
|
|
|
- ? this.$util.toDateString(new Date(), 'yyyy-MM-dd')
|
|
|
- : new Date().toISOString().slice(0, 10);
|
|
|
- const data = {
|
|
|
- batchNo: this.tableQuery.batchNo,
|
|
|
- productCode: this.tableQuery.productCode,
|
|
|
- productName: r.productName || '',
|
|
|
- specification: r.specification || '',
|
|
|
- processOrderCode: r.workOrderCode || '',
|
|
|
- processOrderNo: r.workOrderCode || '',
|
|
|
- moCode: r.workOrderCode || '',
|
|
|
- code: r.code || '',
|
|
|
- recorder: r.createUserName || '',
|
|
|
- checker: r.checkerName || '',
|
|
|
- reviewer: r.reviewerName || '',
|
|
|
- inspector: r.inspectorName || '',
|
|
|
- operator: r.createUserName || '',
|
|
|
- date: r.createTime || today,
|
|
|
- createDate: r.createTime || today,
|
|
|
- operateYear: today.slice(0, 4),
|
|
|
- operateMonth: today.slice(5, 7),
|
|
|
- operateDay: today.slice(8, 10),
|
|
|
- startHour: '08',
|
|
|
- startMinute: '00',
|
|
|
- endHour: '17',
|
|
|
- endMinute: '30',
|
|
|
- equipmentCode: r.equipmentCode || '',
|
|
|
- equipmentName: r.equipmentName || '',
|
|
|
- remark: r.remark || ''
|
|
|
+ const printType = this.printTypeMap[key];
|
|
|
+ if (!printType) {
|
|
|
+ this.$message.warning('暂不支持该打印单据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const ids = this.selection.map((item) => item.id).filter(Boolean);
|
|
|
+ if (!ids.length) {
|
|
|
+ this.$message.warning('未获取到可打印数据的ID');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const res = await queryPrint({ ids, printType });
|
|
|
+ const data = this.buildPrintData(key, res);
|
|
|
+ if (!data) {
|
|
|
+ this.$message.warning('未查询到可打印的生产记录数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.$refs[key]) {
|
|
|
+ this.$refs[key].open(data);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error.message || '查询打印数据失败');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ buildPrintData(key, res) {
|
|
|
+ const list = this.getPrintList(key, res);
|
|
|
+ const first = list[0];
|
|
|
+ if (!first) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ const fallback = this.selection[0] || {};
|
|
|
+ const today = this.formatPrintDate(new Date());
|
|
|
+ const base = this.buildBasePrintData(first, fallback, today);
|
|
|
+
|
|
|
+ if (key == 'cleaningRecord') {
|
|
|
+ return {
|
|
|
+ ...base,
|
|
|
+ area: first.workshopArea || fallback.workshopArea || '',
|
|
|
+ processName: first.processName || fallback.ruleName || '',
|
|
|
+ productModel: first.productModel || fallback.productModel || '',
|
|
|
+ completionTime:
|
|
|
+ first.cleaningFinishTime ||
|
|
|
+ fallback.createTime ||
|
|
|
+ `${today} 00:00`,
|
|
|
+ checkItems: this.buildCleaningDetails(first.cleaningDetails)
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (key == 'labelPrintRecord') {
|
|
|
+ return {
|
|
|
+ ...base,
|
|
|
+ productionDate: this.formatPrintDate(first.productionDate),
|
|
|
+ expiryDate: this.formatPrintDate(first.expiryDate),
|
|
|
+ printTargets: this.uniqueList(list.map((item) => item.printTarget)),
|
|
|
+ specs: this.uniqueList(list.map((item) => item.specification)),
|
|
|
+ records: list.map((item) => ({
|
|
|
+ ...item,
|
|
|
+ productModel: item.productModel || '',
|
|
|
+ printQuantity: item.printQuantity || ''
|
|
|
+ }))
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (key == 'productLabelRecord') {
|
|
|
+ const operateDate = this.formatPrintDate(
|
|
|
+ first.operateTime ||
|
|
|
+ first.createTime ||
|
|
|
+ fallback.createTime ||
|
|
|
+ today
|
|
|
+ );
|
|
|
+ return {
|
|
|
+ ...base,
|
|
|
+ specification: first.specModel || first.specification || '',
|
|
|
+ productQuantity: first.productQuantity || '',
|
|
|
+ equipmentCode: first.deviceCode || fallback.equipmentCode || '',
|
|
|
+ equipmentName: first.deviceName || fallback.equipmentName || '',
|
|
|
+ operateYear: operateDate.slice(0, 4),
|
|
|
+ operateMonth: operateDate.slice(5, 7),
|
|
|
+ operateDay: operateDate.slice(8, 10),
|
|
|
+ startHour: '08',
|
|
|
+ startMinute: '00',
|
|
|
+ endHour: '17',
|
|
|
+ endMinute: '30'
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (key == 'packagingRecord') {
|
|
|
+ return {
|
|
|
+ ...base,
|
|
|
+ batchNo: first.produceBatch || base.batchNo,
|
|
|
+ specification: first.specModel || first.specification || '',
|
|
|
+ batchQuantity: first.quantity || '',
|
|
|
+ startTime:
|
|
|
+ first.startTime || fallback.createTime || `${today} 08:00`,
|
|
|
+ endTime: first.endTime || fallback.updateTime || `${today} 17:30`
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (key == 'processInspectionRecord') {
|
|
|
+ return {
|
|
|
+ ...base,
|
|
|
+ batchNo: first.produceBatch || base.batchNo,
|
|
|
+ productionDate: this.formatPrintDate(first.productionDate),
|
|
|
+ specification: first.modelSpec || first.specification || ''
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return base;
|
|
|
+ },
|
|
|
+ getPrintList(key, res) {
|
|
|
+ const listMap = {
|
|
|
+ cleaningRecord: 'cleaningRecordList',
|
|
|
+ labelPrintRecord: 'labelPrintRecordList',
|
|
|
+ productLabelRecord: 'productLabelingRecordList',
|
|
|
+ packagingRecord: 'packagingProcessRecordList',
|
|
|
+ processInspectionRecord: 'processInspectionRecordList'
|
|
|
};
|
|
|
- if (this.$refs[key]) {
|
|
|
- this.$refs[key].open(data);
|
|
|
+ const listKey = listMap[key];
|
|
|
+ if (Array.isArray(res?.[listKey])) {
|
|
|
+ return res[listKey];
|
|
|
+ }
|
|
|
+ if (Array.isArray(res)) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ },
|
|
|
+ buildBasePrintData(row, fallback, today) {
|
|
|
+ return {
|
|
|
+ ...row,
|
|
|
+ batchNo:
|
|
|
+ row.batchNo || row.produceBatch || this.tableQuery.batchNo || '',
|
|
|
+ productCode:
|
|
|
+ row.productCode ||
|
|
|
+ this.tableQuery.productCode ||
|
|
|
+ fallback.productCode ||
|
|
|
+ '',
|
|
|
+ productName: row.productName || fallback.productName || '',
|
|
|
+ specification:
|
|
|
+ row.specification ||
|
|
|
+ row.specModel ||
|
|
|
+ row.modelSpec ||
|
|
|
+ fallback.specification ||
|
|
|
+ '',
|
|
|
+ processOrderCode: row.workOrderCode || fallback.workOrderCode || '',
|
|
|
+ processOrderNo: row.workOrderCode || fallback.workOrderCode || '',
|
|
|
+ moCode: row.workOrderCode || fallback.workOrderCode || '',
|
|
|
+ code: row.code || fallback.code || '',
|
|
|
+ recorder: row.createUserName || fallback.createUserName || '',
|
|
|
+ checker: row.checkerName || fallback.checkerName || '',
|
|
|
+ reviewer: row.reviewerName || fallback.reviewerName || '',
|
|
|
+ inspector: row.inspectorName || fallback.inspectorName || '',
|
|
|
+ operator: row.createUserName || fallback.createUserName || '',
|
|
|
+ date: row.createTime || fallback.createTime || today,
|
|
|
+ createDate: row.createTime || fallback.createTime || today,
|
|
|
+ remark: row.remark || fallback.remark || ''
|
|
|
+ };
|
|
|
+ },
|
|
|
+ buildCleaningDetails(details) {
|
|
|
+ const list = Array.isArray(details) ? details : [];
|
|
|
+ return list.map((item) => ({
|
|
|
+ ...item,
|
|
|
+ name: item.cleaningItem || '',
|
|
|
+ cleaner: item.cleaningPerson || '',
|
|
|
+ abnormalDesc: item.errorMsg || '',
|
|
|
+ cleaningStatus: item.cleaningStatus || '',
|
|
|
+ checkResult: item.checkResult || ''
|
|
|
+ }));
|
|
|
+ },
|
|
|
+ uniqueList(list) {
|
|
|
+ return [...new Set((list || []).filter(Boolean))];
|
|
|
+ },
|
|
|
+ formatPrintDate(value) {
|
|
|
+ if (!value) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ if (typeof value == 'string') {
|
|
|
+ return value.slice(0, 10);
|
|
|
+ }
|
|
|
+ if (this.$util?.toDateString) {
|
|
|
+ return this.$util.toDateString(value, 'yyyy-MM-dd');
|
|
|
}
|
|
|
+ return new Date(value).toISOString().slice(0, 10);
|
|
|
}
|
|
|
}
|
|
|
};
|