|
|
@@ -42,16 +42,11 @@
|
|
|
import dictMixins from '@/mixins/dictMixins';
|
|
|
import tableColumnsMixin from '@/mixins/tableColumnsMixin';
|
|
|
import { batchRecordPage, queryPrint } from '@/api/qualityWorkOrder/index.js';
|
|
|
- import { querySamplingPrint } from '@/api/samplingRecords/index.js';
|
|
|
import exportButton from '@/components/upload/exportButton.vue';
|
|
|
import printSelector from '../printSelector.vue';
|
|
|
import productInspectionReport from '../../print/electrodeBatchRecord/productInspectionReport.vue';
|
|
|
import samplingForm from '../../print/electrodeBatchRecord/samplingForm.vue';
|
|
|
import finishedProductOriginalRecord from '../../print/electrodeBatchRecord/finishedProductOriginalRecord.vue';
|
|
|
- import {
|
|
|
- buildSamplingFormPrintData,
|
|
|
- getSamplingPrintIds
|
|
|
- } from '../../utils/samplingFormPrint';
|
|
|
|
|
|
export default {
|
|
|
mixins: [dictMixins, tableColumnsMixin],
|
|
|
@@ -275,22 +270,13 @@
|
|
|
return;
|
|
|
}
|
|
|
try {
|
|
|
- const ids =
|
|
|
- key == 'samplingForm'
|
|
|
- ? getSamplingPrintIds(this.selection)
|
|
|
- : this.getPrintIds(key);
|
|
|
+ const ids = this.getPrintIds();
|
|
|
if (!ids.length) {
|
|
|
this.$message.warning('未获取到可打印数据的ID');
|
|
|
return;
|
|
|
}
|
|
|
- const res =
|
|
|
- key == 'samplingForm'
|
|
|
- ? await querySamplingPrint(ids)
|
|
|
- : await queryPrint({ ids, printType });
|
|
|
- const data =
|
|
|
- key == 'samplingForm'
|
|
|
- ? buildSamplingFormPrintData(res, this.selection)
|
|
|
- : this.buildPrintData(res, key);
|
|
|
+ const res = await queryPrint({ ids, printType });
|
|
|
+ const data = this.buildPrintData(res, key);
|
|
|
if (!data) {
|
|
|
this.$message.warning('未查询到可打印的质检工单数据');
|
|
|
return;
|
|
|
@@ -304,57 +290,47 @@
|
|
|
},
|
|
|
buildPrintData(res, key) {
|
|
|
const list = this.getPrintList(res, key);
|
|
|
- const first = list[0];
|
|
|
- if (!first) {
|
|
|
+ if (!list.length) {
|
|
|
return null;
|
|
|
}
|
|
|
- const selected =
|
|
|
- this.selection.find((item) => item.id == first.id) ||
|
|
|
- this.selection[0] ||
|
|
|
- {};
|
|
|
- const date = this.formatPrintDate(
|
|
|
- first.sampleDate ||
|
|
|
- first.createTime ||
|
|
|
- selected.qualityTime ||
|
|
|
- selected.createTime
|
|
|
- );
|
|
|
- const base = this.buildPrintItem(first, selected);
|
|
|
|
|
|
if (key == 'productInspectionReport') {
|
|
|
+ const first = list[0];
|
|
|
+ const selected = this.getSelectedItem(first, 0);
|
|
|
+ const base = this.buildPrintItem(first, selected);
|
|
|
return {
|
|
|
...base,
|
|
|
code: selected.code || first.workOrderCode || '',
|
|
|
- date,
|
|
|
+ date: this.formatPrintDate(
|
|
|
+ this.getValue(
|
|
|
+ first.createTime,
|
|
|
+ selected.qualityTime,
|
|
|
+ selected.createTime
|
|
|
+ )
|
|
|
+ ),
|
|
|
reporter: selected.qualityName || selected.createUserName || '',
|
|
|
receiver: selected.reviewerName || selected.checkerName || '',
|
|
|
department: selected.departmentName || selected.workshopName || '',
|
|
|
items: list.map((item, index) =>
|
|
|
this.buildPrintItem(
|
|
|
item,
|
|
|
- this.selection.find((row) => row.id == item.id) || selected,
|
|
|
+ this.getSelectedItem(item, index),
|
|
|
index
|
|
|
)
|
|
|
)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- return {
|
|
|
- ...base,
|
|
|
- date,
|
|
|
- inspectionDate: date,
|
|
|
- batchNo: first.produceBatch || first.batch || selected.batchNo || '',
|
|
|
- submitQuantity:
|
|
|
- first.quantityVerified ||
|
|
|
- selected.submitQuantity ||
|
|
|
- first.quantity ||
|
|
|
- '',
|
|
|
- sampleQuantity: first.quantity || selected.sampleQuantity || '',
|
|
|
- inspectionBasis: selected.inspectionBasis || '',
|
|
|
- inspector: selected.qualityName || selected.createUserName || '',
|
|
|
- checker: selected.checkerName || selected.reviewerName || '',
|
|
|
- conclusion: selected.status === 1 ? '合格' : '',
|
|
|
- remark: selected.remark || ''
|
|
|
- };
|
|
|
+ const data = list.map((item, index) => {
|
|
|
+ const selected = this.getSelectedItem(
|
|
|
+ item.basicInfo || item,
|
|
|
+ index
|
|
|
+ );
|
|
|
+ return key == 'samplingForm'
|
|
|
+ ? this.buildSamplingFormData(item, selected)
|
|
|
+ : this.buildFinishedProductRecordData(item, selected);
|
|
|
+ });
|
|
|
+ return data.length == 1 ? data[0] : data;
|
|
|
},
|
|
|
getPrintList(res, key) {
|
|
|
const listMap = {
|
|
|
@@ -371,8 +347,159 @@
|
|
|
}
|
|
|
return [];
|
|
|
},
|
|
|
- getPrintIds(key) {
|
|
|
- return this.selection.map((item) => item.id).filter(Boolean);
|
|
|
+ getPrintIds() {
|
|
|
+ return [
|
|
|
+ ...new Set(
|
|
|
+ this.selection
|
|
|
+ .map((item) => item.id)
|
|
|
+ .filter((id) => this.hasValue(id))
|
|
|
+ )
|
|
|
+ ];
|
|
|
+ },
|
|
|
+ getSelectedItem(item = {}, index = 0) {
|
|
|
+ return (
|
|
|
+ this.selection.find(
|
|
|
+ (row) =>
|
|
|
+ (this.hasValue(item.id) && row.id == item.id) ||
|
|
|
+ (this.hasValue(item.workOrderCode) &&
|
|
|
+ row.workOrderCode == item.workOrderCode) ||
|
|
|
+ (this.hasValue(item.produceBatch) &&
|
|
|
+ row.batchNo == item.produceBatch)
|
|
|
+ ) ||
|
|
|
+ this.selection[index] ||
|
|
|
+ this.selection[0] ||
|
|
|
+ {}
|
|
|
+ );
|
|
|
+ },
|
|
|
+ buildSamplingFormData(item, selected) {
|
|
|
+ return {
|
|
|
+ ...selected,
|
|
|
+ ...item,
|
|
|
+ productName: this.getValue(
|
|
|
+ item.materialName,
|
|
|
+ selected.productName,
|
|
|
+ selected.materialName,
|
|
|
+ selected.name
|
|
|
+ ),
|
|
|
+ specification: this.getValue(
|
|
|
+ item.specModel,
|
|
|
+ selected.specification,
|
|
|
+ selected.productModel
|
|
|
+ ),
|
|
|
+ batchNo: this.getValue(
|
|
|
+ item.produceBatch,
|
|
|
+ item.batch,
|
|
|
+ selected.batchNo
|
|
|
+ ),
|
|
|
+ sampleSource: this.getValue(
|
|
|
+ selected.sampleSource,
|
|
|
+ selected.sourceTypeDesc,
|
|
|
+ selected.sourceCode,
|
|
|
+ selected.workOrderCode
|
|
|
+ ),
|
|
|
+ sampleLocation: this.getValue(
|
|
|
+ selected.samplePlace,
|
|
|
+ selected.sampleLocation
|
|
|
+ ),
|
|
|
+ sampleDate: this.formatPrintDate(
|
|
|
+ this.getValue(
|
|
|
+ item.createTime,
|
|
|
+ selected.qualityTime,
|
|
|
+ selected.createTime
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ batchQuantity: this.hasValue(item.batch)
|
|
|
+ ? item.batch
|
|
|
+ : this.buildQuantityText(item.quantityVerified, item.unit),
|
|
|
+ sampleQuantity: this.buildQuantityText(
|
|
|
+ this.getValue(item.quantity, selected.sampleQuantity),
|
|
|
+ item.unit
|
|
|
+ ),
|
|
|
+ sampler: this.getValue(
|
|
|
+ selected.sampleUserName,
|
|
|
+ selected.qualityName,
|
|
|
+ selected.createUserName
|
|
|
+ ),
|
|
|
+ checker: this.getValue(
|
|
|
+ selected.checkerName,
|
|
|
+ selected.reviewerName,
|
|
|
+ selected.approvalUserName
|
|
|
+ ),
|
|
|
+ remark: this.getValue(item.remark, selected.remark)
|
|
|
+ };
|
|
|
+ },
|
|
|
+ buildFinishedProductRecordData(item, selected) {
|
|
|
+ const basicInfo = item.basicInfo || {};
|
|
|
+ const detailList = Array.isArray(item.detailList)
|
|
|
+ ? item.detailList
|
|
|
+ : [];
|
|
|
+ const inspectionItems = detailList.map((detail) => ({
|
|
|
+ ...detail,
|
|
|
+ name: detail.inspectionItem || '',
|
|
|
+ standard: detail.standardRequirement || '',
|
|
|
+ result: detail.inspectionResult || '',
|
|
|
+ conclusion: ''
|
|
|
+ }));
|
|
|
+ return {
|
|
|
+ ...selected,
|
|
|
+ ...basicInfo,
|
|
|
+ productName: this.getValue(
|
|
|
+ basicInfo.productName,
|
|
|
+ selected.productName,
|
|
|
+ selected.name
|
|
|
+ ),
|
|
|
+ productCode: this.getValue(
|
|
|
+ selected.productCode,
|
|
|
+ selected.materialCode
|
|
|
+ ),
|
|
|
+ specification: this.getValue(
|
|
|
+ basicInfo.specModel,
|
|
|
+ selected.specification,
|
|
|
+ selected.productModel
|
|
|
+ ),
|
|
|
+ packageSpec: basicInfo.packageSpec || '',
|
|
|
+ batchNo: this.getValue(
|
|
|
+ basicInfo.produceBatch,
|
|
|
+ selected.batchNo
|
|
|
+ ),
|
|
|
+ sterilizationBatchNo: basicInfo.sterilizationBatch || '',
|
|
|
+ submitQuantity: this.getValue(
|
|
|
+ basicInfo.productQuantity,
|
|
|
+ selected.submitQuantity
|
|
|
+ ),
|
|
|
+ sampleQuantity: this.getValue(
|
|
|
+ basicInfo.samplingQuantity,
|
|
|
+ selected.sampleQuantity
|
|
|
+ ),
|
|
|
+ inspectionBasis: this.getValue(
|
|
|
+ basicInfo.inspectionBasis,
|
|
|
+ selected.inspectionBasis
|
|
|
+ ),
|
|
|
+ inspectionDate: this.formatPrintDate(
|
|
|
+ this.getValue(
|
|
|
+ basicInfo.reportDate,
|
|
|
+ basicInfo.productionDate,
|
|
|
+ basicInfo.createTime,
|
|
|
+ selected.qualityTime
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ appearanceItems: inspectionItems,
|
|
|
+ performanceItems: [],
|
|
|
+ packagingItems: [],
|
|
|
+ conclusion: this.getValue(
|
|
|
+ selected.conclusion,
|
|
|
+ selected.inspectionResult
|
|
|
+ ),
|
|
|
+ inspector: this.getValue(
|
|
|
+ selected.qualityName,
|
|
|
+ selected.createUserName
|
|
|
+ ),
|
|
|
+ checker: this.getValue(
|
|
|
+ selected.checkerName,
|
|
|
+ selected.reviewerName
|
|
|
+ ),
|
|
|
+ remark: selected.remark || ''
|
|
|
+ };
|
|
|
},
|
|
|
buildPrintItem(item, selected = {}, index = 0) {
|
|
|
return {
|
|
|
@@ -397,7 +524,7 @@
|
|
|
productionBatchNo: item.produceBatch || selected.batchNo || '',
|
|
|
batchNo: item.produceBatch || item.batch || selected.batchNo || '',
|
|
|
unit: item.unit || selected.unit || '',
|
|
|
- quantity: item.quantity || selected.quantity || '',
|
|
|
+ quantity: this.getValue(item.quantity, selected.quantity),
|
|
|
processOrderCode:
|
|
|
item.workOrderCode ||
|
|
|
selected.workOrderCode ||
|
|
|
@@ -407,13 +534,23 @@
|
|
|
};
|
|
|
},
|
|
|
buildQuantityText(quantity, unit) {
|
|
|
- if (quantity === undefined || quantity === null || quantity === '') {
|
|
|
+ if (!this.hasValue(quantity)) {
|
|
|
return '';
|
|
|
}
|
|
|
return `${quantity}${unit || ''}`;
|
|
|
},
|
|
|
+ hasValue(value) {
|
|
|
+ return value !== undefined && value !== null && value !== '';
|
|
|
+ },
|
|
|
+ getValue(...values) {
|
|
|
+ const value = values.find((item) => this.hasValue(item));
|
|
|
+ return value === undefined ? '' : value;
|
|
|
+ },
|
|
|
formatPrintDate(value) {
|
|
|
- const source = value || new Date();
|
|
|
+ if (!this.hasValue(value)) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ const source = value;
|
|
|
if (typeof source == 'string') {
|
|
|
return source.slice(0, 10);
|
|
|
}
|