|
|
@@ -0,0 +1,145 @@
|
|
|
+function hasValue(value) {
|
|
|
+ return value !== undefined && value !== null && value !== '';
|
|
|
+}
|
|
|
+
|
|
|
+function getValue(...values) {
|
|
|
+ const value = values.find(hasValue);
|
|
|
+ return value === undefined ? '' : value;
|
|
|
+}
|
|
|
+
|
|
|
+function joinText(values) {
|
|
|
+ return [...new Set((values || []).filter(hasValue))].join('/');
|
|
|
+}
|
|
|
+
|
|
|
+function formatDate(value) {
|
|
|
+ if (!hasValue(value)) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ return value.slice(0, 10);
|
|
|
+ }
|
|
|
+ const date = new Date(value);
|
|
|
+ if (Number.isNaN(date.getTime())) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ const year = date.getFullYear();
|
|
|
+ const month = `${date.getMonth() + 1}`.padStart(2, '0');
|
|
|
+ const day = `${date.getDate()}`.padStart(2, '0');
|
|
|
+ return `${year}-${month}-${day}`;
|
|
|
+}
|
|
|
+
|
|
|
+function buildQuantityText(quantity, unit) {
|
|
|
+ return hasValue(quantity) ? `${quantity}${unit || ''}` : '';
|
|
|
+}
|
|
|
+
|
|
|
+function getSelectedRecord(item = {}, index, selectedList = []) {
|
|
|
+ return (
|
|
|
+ selectedList.find(
|
|
|
+ (row) =>
|
|
|
+ (hasValue(item.id) && row.id == item.id) ||
|
|
|
+ (hasValue(item.samplingRecordId) && row.id == item.samplingRecordId) ||
|
|
|
+ (hasValue(item.samplingrecordId) && row.id == item.samplingrecordId) ||
|
|
|
+ (hasValue(item.code) && row.code == item.code) ||
|
|
|
+ (hasValue(item.batchNo) && row.batchNo == item.batchNo)
|
|
|
+ ) ||
|
|
|
+ selectedList[index] ||
|
|
|
+ selectedList[0] ||
|
|
|
+ {}
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function buildSamplingFormPrintItem(item = {}, selected = {}) {
|
|
|
+ return {
|
|
|
+ ...selected,
|
|
|
+ ...item,
|
|
|
+ productName: getValue(
|
|
|
+ item.productName,
|
|
|
+ item.materialName,
|
|
|
+ selected.productName,
|
|
|
+ selected.materialName
|
|
|
+ ),
|
|
|
+ specification: joinText([
|
|
|
+ getValue(item.specification, selected.specification),
|
|
|
+ getValue(item.modelType, selected.modelType, selected.productModel)
|
|
|
+ ]),
|
|
|
+ batchNo: getValue(
|
|
|
+ item.batchNo,
|
|
|
+ item.produceBatch,
|
|
|
+ item.batch,
|
|
|
+ selected.batchNo
|
|
|
+ ),
|
|
|
+ sampleSource: getValue(
|
|
|
+ item.sourceTypeDesc,
|
|
|
+ item.sampleSource,
|
|
|
+ selected.sampleSource,
|
|
|
+ selected.sourceTypeDesc,
|
|
|
+ selected.sourceCode
|
|
|
+ ),
|
|
|
+ sampleLocation: getValue(
|
|
|
+ item.samplePlace,
|
|
|
+ item.sampleLocation,
|
|
|
+ selected.samplePlace,
|
|
|
+ selected.sampleLocation
|
|
|
+ ),
|
|
|
+ sampleDate: formatDate(
|
|
|
+ getValue(item.sampleDate, selected.sampleDate, selected.createTime)
|
|
|
+ ),
|
|
|
+ batchQuantity: buildQuantityText(
|
|
|
+ getValue(item.batchQuantity, selected.batchQuantity),
|
|
|
+ getValue(item.batchUnit, selected.batchUnit, selected.measureUnit)
|
|
|
+ ),
|
|
|
+ sampleQuantity: buildQuantityText(
|
|
|
+ getValue(item.sampleQuantity, selected.sampleQuantity),
|
|
|
+ getValue(item.sampleUnit, selected.sampleUnit, selected.measureUnit)
|
|
|
+ ),
|
|
|
+ sampler: getValue(
|
|
|
+ item.sampler,
|
|
|
+ item.sampleUserName,
|
|
|
+ selected.sampler,
|
|
|
+ selected.sampleUserName,
|
|
|
+ selected.createUserName,
|
|
|
+ selected.qualityName
|
|
|
+ ),
|
|
|
+ checker: getValue(
|
|
|
+ item.checker,
|
|
|
+ item.checkerName,
|
|
|
+ selected.checker,
|
|
|
+ selected.checkerName,
|
|
|
+ selected.approvalUserName,
|
|
|
+ selected.reviewerName
|
|
|
+ ),
|
|
|
+ remark: getValue(item.remark, selected.remark)
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+export function getSamplingPrintIds(selectedList = []) {
|
|
|
+ return [
|
|
|
+ ...new Set(
|
|
|
+ selectedList
|
|
|
+ .map((item) =>
|
|
|
+ getValue(
|
|
|
+ item.samplingRecordId,
|
|
|
+ item.samplingrecordId,
|
|
|
+ item.sampleRecordId,
|
|
|
+ item.sampleId,
|
|
|
+ item.id
|
|
|
+ )
|
|
|
+ )
|
|
|
+ .filter(hasValue)
|
|
|
+ )
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
+export function buildSamplingFormPrintData(list, selectedList = []) {
|
|
|
+ const records = Array.isArray(list) ? list : [];
|
|
|
+ if (!records.length) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ const result = records.map((item, index) =>
|
|
|
+ buildSamplingFormPrintItem(
|
|
|
+ item,
|
|
|
+ getSelectedRecord(item, index, selectedList)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ return result.length === 1 ? result[0] : result;
|
|
|
+}
|