فهرست منبع

新增打印接口

695593266@qq.com 1 هفته پیش
والد
کامیت
fc8ccfa55c

+ 60 - 9
src/views/batchRecord/components/tables/pendingBatchRecordTable.vue

@@ -22,6 +22,7 @@
 
     <unqualified-product-review ref="unqualifiedProductReviewRef" />
     <product-release-approval ref="productReleaseApproval" />
+    <sampling-form ref="samplingForm" />
   </div>
 </template>
 
@@ -29,11 +30,15 @@
   import printSelector from '../printSelector.vue';
   import unqualifiedProductReview from '../../print/electrodeBatchRecord/unqualifiedProductReview.vue';
   import productReleaseApproval from '../../print/electrodeBatchRecord/productReleaseApproval.vue';
+  import samplingForm from '../../print/electrodeBatchRecord/samplingForm.vue';
   import {
     checklistrecordPage,
     checklistrecordQueryPrint
   } from '@/api/checklistrecord/index';
-  import { samplingRecordsPage } from '@/api/samplingRecords';
+  import {
+    samplingRecordsPage,
+    querySamplingPrint
+  } from '@/api/samplingRecords';
   import {
     getList as unacceptedProductPage,
     queryPrint as queryUnacceptedProductPrint
@@ -43,6 +48,10 @@
   import { recordingMethodList } from '@/utils/util.js';
   import dictMixins from '@/mixins/dictMixins';
   import { buildReleaseOrderPrintData } from '../../utils/releaseOrderPrint';
+  import {
+    buildSamplingFormPrintData,
+    getSamplingPrintIds
+  } from '../../utils/samplingFormPrint';
 
   export default {
     name: 'pendingBatchRecordTable',
@@ -50,7 +59,8 @@
     components: {
       printSelector,
       unqualifiedProductReview,
-      productReleaseApproval
+      productReleaseApproval,
+      samplingForm
     },
     props: {
       tableQuery: {
@@ -81,6 +91,13 @@
             code: 'ZL-065'
           }
         ],
+        samplePrintOptions: [
+          {
+            key: 'samplingForm',
+            label: '取样单',
+            code: 'ZL-041'
+          }
+        ],
         disposeList: []
       };
     },
@@ -98,6 +115,9 @@
         return `batchRecord-${this.tableType || 'pending'}-table`;
       },
       printOptions() {
+        if (this.isSample) {
+          return this.samplePrintOptions;
+        }
         if (this.isReleaseOrder) {
           return this.releaseOrderPrintOptions;
         }
@@ -333,6 +353,13 @@
 
         if (this.isSample) {
           return [
+            {
+              width: 45,
+              type: 'selection',
+              columnKey: 'selection',
+              align: 'center',
+              fixed: 'left'
+            },
             {
               width: 50,
               type: 'index',
@@ -668,6 +695,28 @@
         }
         if (key === 'productReleaseApproval') {
           await this.openReleaseOrderPrint();
+          return;
+        }
+        if (key === 'samplingForm') {
+          await this.openSamplingFormPrint();
+        }
+      },
+      async openSamplingFormPrint() {
+        try {
+          const ids = getSamplingPrintIds(this.selection);
+          if (!ids.length) {
+            this.$message.warning('未获取到可打印数据的ID');
+            return;
+          }
+          const res = await querySamplingPrint(ids);
+          const data = buildSamplingFormPrintData(res, this.selection);
+          if (!data) {
+            this.$message.warning('未查询到可打印的取样单数据');
+            return;
+          }
+          this.$refs.samplingForm.open(data);
+        } catch (error) {
+          this.$message.error(error.message || '查询打印数据失败');
         }
       },
       async openReleaseOrderPrint() {
@@ -747,7 +796,10 @@
             first.unqualifiedProductsCode,
             selected.unqualifiedProductsCode
           ),
-          categoryName: this.getValue(first.categoryName, selected.categoryName),
+          categoryName: this.getValue(
+            first.categoryName,
+            selected.categoryName
+          ),
           specification,
           modelType: this.getValue(first.modelType, selected.modelType),
           batchNo: this.getValue(first.batchNo, selected.batchNo),
@@ -757,12 +809,11 @@
             first.unqualifiedProductsCode,
             selected.unqualifiedProductsCode
           ),
-          unqualifiedDescription:
-            this.getValue(
-              first.unqualifiedReason,
-              selected.unqualifiedDescription,
-              selected.unqualifiedReason
-            ),
+          unqualifiedDescription: this.getValue(
+            first.unqualifiedReason,
+            selected.unqualifiedDescription,
+            selected.unqualifiedReason
+          ),
           unqualifiedReason: this.getValue(
             first.unqualifiedReason,
             selected.unqualifiedReason

+ 13 - 42
src/views/batchRecord/components/tables/qualityWorkOrderTable.vue

@@ -48,6 +48,10 @@
   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],
@@ -271,7 +275,10 @@
           return;
         }
         try {
-          const ids = this.getPrintIds(key);
+          const ids =
+            key == 'samplingForm'
+              ? getSamplingPrintIds(this.selection)
+              : this.getPrintIds(key);
           if (!ids.length) {
             this.$message.warning('未获取到可打印数据的ID');
             return;
@@ -280,7 +287,10 @@
             key == 'samplingForm'
               ? await querySamplingPrint(ids)
               : await queryPrint({ ids, printType });
-          const data = this.buildPrintData(res, key);
+          const data =
+            key == 'samplingForm'
+              ? buildSamplingFormPrintData(res, this.selection)
+              : this.buildPrintData(res, key);
           if (!data) {
             this.$message.warning('未查询到可打印的质检工单数据');
             return;
@@ -328,32 +338,6 @@
           };
         }
 
-        if (key == 'samplingForm') {
-          return {
-            ...base,
-            date,
-            sampleDate: date,
-            batchNo:
-              first.batchNo ||
-              first.produceBatch ||
-              first.batch ||
-              selected.batchNo ||
-              '',
-            batchQuantity: this.buildQuantityText(
-              first.batchQuantity || first.batch || first.quantity,
-              first.batchUnit
-            ),
-            sampleQuantity: this.buildQuantityText(
-              first.sampleQuantity || first.quantity || selected.sampleQuantity,
-              first.sampleUnit
-            ),
-            sampleLocation: first.samplePlace || selected.sampleLocation || '',
-            sampleSource: first.sourceTypeDesc || selected.sampleSource || '',
-            sampler: selected.qualityName || selected.createUserName || '',
-            checker: selected.checkerName || selected.reviewerName || ''
-          };
-        }
-
         return {
           ...base,
           date,
@@ -388,20 +372,7 @@
         return [];
       },
       getPrintIds(key) {
-        return this.selection
-          .map((item) => {
-            if (key == 'samplingForm') {
-              return (
-                item.samplingRecordId ||
-                item.samplingrecordId ||
-                item.sampleRecordId ||
-                item.sampleId ||
-                item.id
-              );
-            }
-            return item.id;
-          })
-          .filter(Boolean);
+        return this.selection.map((item) => item.id).filter(Boolean);
       },
       buildPrintItem(item, selected = {}, index = 0) {
         return {

+ 58 - 16
src/views/batchRecord/print/electrodeBatchRecord/samplingForm.vue

@@ -1,12 +1,24 @@
 <template>
-  <ele-modal title="取样单 ZL-041" :visible.sync="visible" v-if="visible" width="70%" :maxable="true">
+  <ele-modal
+    title="取样单 ZL-041"
+    :visible.sync="visible"
+    v-if="visible"
+    width="70%"
+    :maxable="true"
+  >
     <div id="printSection_samplingForm">
-      <div class="report-container">
+      <div
+        v-for="(form, index) in formList"
+        :key="index"
+        class="report-container"
+      >
         <div class="report-header">
           <div class="header-left">
             <img src="" alt="特瑞精密医疗" class="logo" />
           </div>
-          <div class="header-center">湖 南 特 瑞 精 密 医 疗 器 械 有 限 公 司</div>
+          <div class="header-center"
+            >湖 南 特 瑞 精 密 医 疗 器 械 有 限 公 司</div
+          >
         </div>
         <div class="report-title">取 样 单</div>
         <div class="form-code">表单编号:TR.D-041/ZL &nbsp; 版本:B/0</div>
@@ -79,12 +91,14 @@
     data() {
       return {
         visible: false,
-        form: {}
+        form: {},
+        formList: []
       };
     },
     methods: {
       open(data) {
-        this.form = data || {};
+        this.formList = Array.isArray(data) ? data : data ? [data] : [];
+        this.form = this.formList[0] || {};
         this.visible = true;
       },
       print() {
@@ -93,29 +107,54 @@
         win.document.open();
         win.document.write('<html><head><title>取样单</title>');
         win.document.write('<style>');
-        win.document.write('body{margin:0;padding:20px;font-family:SimSun,serif;font-size:12px;}');
+        win.document.write(
+          'body{margin:0;padding:20px;font-family:SimSun,serif;font-size:12px;}'
+        );
         win.document.write('.report-container{padding:20px;background:#fff;}');
-        win.document.write('.report-header{display:flex;align-items:center;justify-content:center;position:relative;margin-bottom:5px;}');
-        win.document.write('.header-center{font-size:22px;letter-spacing:4px;}');
-        win.document.write('.report-title{text-align:center;font-size:20px;font-weight:bold;margin-bottom:5px;letter-spacing:8px;}');
-        win.document.write('.form-code{text-align:right;font-size:12px;margin-bottom:5px;}');
+        win.document.write(
+          '.report-container + .report-container{page-break-before:always;}'
+        );
+        win.document.write(
+          '.report-header{display:flex;align-items:center;justify-content:center;position:relative;margin-bottom:5px;}'
+        );
+        win.document.write(
+          '.header-center{font-size:22px;letter-spacing:4px;}'
+        );
+        win.document.write(
+          '.report-title{text-align:center;font-size:20px;font-weight:bold;margin-bottom:5px;letter-spacing:8px;}'
+        );
+        win.document.write(
+          '.form-code{text-align:right;font-size:12px;margin-bottom:5px;}'
+        );
         win.document.write('.main-content{display:flex;}');
         win.document.write('.info-table{flex:1;border-collapse:collapse;}');
-        win.document.write('.info-table td{border:1px solid #000;padding:8px 10px;font-size:12px;}');
-        win.document.write('.info-table .label-cell{width:12%;text-align:center;font-weight:bold;}');
+        win.document.write(
+          '.info-table td{border:1px solid #000;padding:8px 10px;font-size:12px;}'
+        );
+        win.document.write(
+          '.info-table .label-cell{width:12%;text-align:center;font-weight:bold;}'
+        );
         win.document.write('.info-table .value-cell{width:38%;}');
-        win.document.write('.side-labels{writing-mode:vertical-rl;display:flex;font-size:12px;padding-left:5px;gap:10px;}');
+        win.document.write(
+          '.side-labels{writing-mode:vertical-rl;display:flex;font-size:12px;padding-left:5px;gap:10px;}'
+        );
         win.document.write('.purpose-section{margin-top:10px;padding:8px 0;}');
         win.document.write('.purpose-title{font-weight:bold;}');
-        win.document.write('.purpose-options{display:flex;justify-content:space-between;margin-top:8px;padding:0 20px;}');
-        win.document.write('.remark-section{margin-top:10px;padding:8px 0;border-top:1px solid #000;}');
+        win.document.write(
+          '.purpose-options{display:flex;justify-content:space-between;margin-top:8px;padding:0 20px;}'
+        );
+        win.document.write(
+          '.remark-section{margin-top:10px;padding:8px 0;border-top:1px solid #000;}'
+        );
         win.document.write('.remark-title{font-weight:bold;}');
         win.document.write('</style>');
         win.document.write('</head><body>');
         win.document.write(el.innerHTML);
         win.document.write('</body></html>');
         win.document.close();
-        win.onload = function() { win.print(); };
+        win.onload = function () {
+          win.print();
+        };
       }
     }
   };
@@ -128,6 +167,9 @@
     background: #fff;
     font-size: 12px;
   }
+  .report-container + .report-container {
+    page-break-before: always;
+  }
   .report-header {
     display: flex;
     align-items: center;

+ 145 - 0
src/views/batchRecord/utils/samplingFormPrint.js

@@ -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;
+}

+ 2 - 1
vue.config.js

@@ -33,7 +33,7 @@ module.exports = {
       '/api': {
         // target: 'http://124.71.68.31:50001',
         // target: 'http://192.168.1.125:18086',
-        target: 'http://192.168.1.251:18086',
+        // target: 'http://192.168.1.251:18086',
         // target: 'http://192.168.1.251:18186',
         // target: 'http://192.168.1.251:18086', // 开发环境
         // target: 'http://192.168.1.103:18086',192.168.1.116
@@ -42,6 +42,7 @@ module.exports = {
         // target: 'http://192.168.1.211:18086',
         // target: 'http://192.168.1.33:18086',
         // target: 'http://192.168.1.116:18086',
+        target: 'http://192.168.1.19:18086',
         // target: 'http://192.168.1.251:18186', // 测试环境
         // target: 'http://192.168.1.251:18087',
         // target: 'http://116.163.22.90:86/api', // 嘉实生产