Sfoglia il codice sorgente

feat: 库存台账表格新增合计行功能并优化供应商列显示逻辑

yusheng 9 mesi fa
parent
commit
bba3452e99

+ 54 - 15
src/views/warehouseManagement/stockLedger/components/item-list.vue

@@ -20,6 +20,8 @@
       @select-all="changeSelectAll"
       @select-all="changeSelectAll"
       @columns-change="handleColumnChange"
       @columns-change="handleColumnChange"
       :cache-key="cacheKeyUrl"
       :cache-key="cacheKeyUrl"
+      :summary-method="getSummaries"
+      show-summary
     >
     >
       <!-- 表头工具栏 -->
       <!-- 表头工具栏 -->
       <template v-slot:toolbar="{ row }">
       <template v-slot:toolbar="{ row }">
@@ -279,6 +281,7 @@
       return {
       return {
         params: {},
         params: {},
         moudleName: 'stock',
         moudleName: 'stock',
+        totalMoney: '',
         qualityStatus,
         qualityStatus,
         qualityResults,
         qualityResults,
         config: [],
         config: [],
@@ -391,15 +394,7 @@
             align: 'center',
             align: 'center',
             showOverflowTooltip: true
             showOverflowTooltip: true
           },
           },
-          this.selectedDime == 2
-            ? {
-                prop: 'supplierName',
-                label: '供应商',
-                showOverflowTooltip: true,
-                width: 130,
-                align: 'center'
-              }
-            : '',
+
           {
           {
             prop: 'level',
             prop: 'level',
             label: '级别',
             label: '级别',
@@ -565,12 +560,12 @@
                 showOverflowTooltip: true
                 showOverflowTooltip: true
               }
               }
             : '',
             : '',
-          // {
-          //   prop: 'supplierName',
-          //   label: '供应商',
-          //   width: 120,
-          //   showOverflowTooltip: true
-          // },
+          {
+            prop: 'supplierName',
+            label: '供应商',
+            width: 120,
+            showOverflowTooltip: true
+          },
           {
           {
             prop: 'supplierCode',
             prop: 'supplierCode',
             label: '供应商代号',
             label: '供应商代号',
@@ -708,6 +703,43 @@
         this.cacheKeyUrl = this.diffCacheKeyUrl + val;
         this.cacheKeyUrl = this.diffCacheKeyUrl + val;
         this.getTabColumns();
         this.getTabColumns();
       },
       },
+      getSummaries(param) {
+        let key = ['totalMoney'];
+        const { columns, data } = param;
+        const sums = [];
+        columns.forEach((column, index) => {
+          if (index === 0) {
+            sums[index] = '合计';
+            return;
+          }
+
+          if (key.includes(column.property)) {
+            const values = data.map((item) => Number(item[column.property]));
+            console.log(values);
+
+            if (!values.every((value) => isNaN(value))) {
+              sums[index] = values.reduce((prev, curr) => {
+                const value = Number(curr);
+                if (!isNaN(value)) {
+                  return prev + curr;
+                } else {
+                  return prev;
+                }
+              }, 0);
+              sums[index] = parseFloat(sums[index])
+                .toFixed(3)
+                .replace(/\.?0+$/, '');
+            } else {
+              sums[index] = '';
+            }
+          } else {
+            sums[index] = '';
+          }
+        });
+        console.log('sums', sums);
+
+        return sums;
+      },
       /* 表格数据源 */
       /* 表格数据源 */
       datasource({ page, limit, where, order }) {
       datasource({ page, limit, where, order }) {
         console.log('this.selectedDime-----------', this.selectedDime);
         console.log('this.selectedDime-----------', this.selectedDime);
@@ -781,6 +813,8 @@
             pageNum: page,
             pageNum: page,
             size: limit
             size: limit
           });
           });
+          console.log(data, 'data');
+          // this.totalMoney=data
           return data;
           return data;
         }
         }
       },
       },
@@ -900,4 +934,9 @@
     width: 100%;
     width: 100%;
     margin-left: 10px;
     margin-left: 10px;
   }
   }
+  .header_view {
+    display: flex;
+    flex: 1;
+    justify-content: flex-end;
+  }
 </style>
 </style>