Browse Source

台账分解,工程量清单汇总

MaiXinRong 2 years ago
parent
commit
056ddf491c
4 changed files with 105 additions and 1 deletions
  1. 10 1
      app/public/js/ledger.js
  2. 89 0
      app/public/js/shares/cs_gcl_gather.js
  3. 5 0
      app/view/ledger/explode.ejs
  4. 1 0
      config/web.js

+ 10 - 1
app/public/js/ledger.js

@@ -140,6 +140,12 @@ $(document).ready(function() {
         },
     });
 
+    const gclGather = $.cs_gclGather({
+        selector: '#gcl-gather',
+        id: 'gcl-gather',
+        relaSheet: ledgerSpread.getActiveSheet(),
+    });
+
     $.subMenu({
         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
         toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
@@ -176,6 +182,7 @@ $(document).ready(function() {
             if (checkList) {
                 checkList.spread.refresh();
             }
+            if (gclGather) gclGather.spread.refresh();
         }
     });
 
@@ -1070,7 +1077,6 @@ $(document).ready(function() {
     ledgerSpread.bind(spreadNS.Events.SelectionChanged, treeOperationObj.selectionChanged);
     ledgerSpread.bind(spreadNS.Events.TopRowChanged, treeOperationObj.topRowChanged);
 
-    console.log(ledgerSpread.options);
     ledgerSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
         const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
         SpreadJsObj.Clipboard.setCopyData(copyText);
@@ -2267,6 +2273,7 @@ $(document).ready(function() {
             if (checkList) {
                 checkList.spread.refresh();
             }
+            if (gclGather) gclGather.spread.refresh();
         }
     });
     const stdLibCellDoubleClick = function (e, info) {
@@ -2469,6 +2476,8 @@ $(document).ready(function() {
               const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
               getNodeList(node.id);
               getAllList();
+            } else if (tab.attr('content') === '#gcl-gather') {
+                gclGather.spread.refresh();
             }
         } else { // 收起工具栏
             tab.removeClass('active');

+ 89 - 0
app/public/js/shares/cs_gcl_gather.js

@@ -0,0 +1,89 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+(function($){
+    $.cs_gclGather = function (setting) {
+        if (!setting.selector) return;
+
+        if (!setting.spreadSetting) {
+            setting.spreadSetting = {
+                cols: [
+                    {title: '清单编号', field: 'b_code', width: 80, formatter: '@'},
+                    {title: '名称', field: 'name', width: 150, formatter: '@'},
+                    {title: '单位', field: 'unit', width: 50, formatter: '@'},
+                    {title: '单价', field: 'unit_price', width: 60, formatter: '@'},
+                    {title: '数量', field: 'quantity', width: 60, },
+                    {title: '数量', field: 'total_price', width: 60, },
+                ],
+                emptyRows: 0,
+                headRows: 1,
+                headRowHeight: [32],
+                defaultRowHeight: 21,
+                headerFont: '12px 微软雅黑',
+                font: '12px 微软雅黑',
+                selectedBackColor: '#fffacd',
+                readOnly: true,
+            };
+        }
+        if (!setting.gatherFields) setting.gatherFields = ['quantity', 'total_price'];
+
+        const resultId = setting.id + '-spread';
+        const obj = $(setting.selector);
+        obj.html(
+            '<div class="sjs-bar">\n' +
+            `    <div class="pb-1 d-flex"><button class="btn btn-primary btn-sm" id="gcl-gather-refresh">汇总</button>\n` +
+            '        <span class="pl-2" id="' + setting.id + '-info"></span>\n' +
+            '    </div>\n' +
+            '</div>' +
+            '<div id="' + resultId + '" class="sjs-sh">\n' +
+            '</div>'
+        );
+        autoFlashHeight();
+
+        const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
+        const sheet = spread.getActiveSheet();
+        const result = [];
+        SpreadJsObj.initSheet(sheet, setting.spreadSetting);
+        SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, result);
+
+        const recursiveGather = function(nodes) {
+            for (const node of nodes) {
+                if (node.children && node.children.length > 0) {
+                    recursiveGather(node.children);
+                } else {
+                    if (!node.b_code) continue;
+                    let gcl = result.find(x => {
+                        return x.b_code === node.b_code && x.name === node.name && x.unit === node.unit && x.unit_price === node.unit_price;
+                    });
+                    if (!gcl) {
+                        gcl = { b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price };
+                        result.push(gcl);
+                    }
+                    for (const f of setting.gatherFields) {
+                        gcl[f] = ZhCalc.add(gcl[f], node[f]);
+                    }
+                }
+            }
+        };
+
+        const gather = function (node) {
+            $(`#${setting.id}-info`).html(`${node.code || ''}${node.b_code || ''} ${node.name || ''} - ${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}`);
+            recursiveGather([node]);
+            SpreadJsObj.reLoadSheetData(sheet);
+        };
+
+        $('#gcl-gather-refresh').click(() => {
+            gather(SpreadJsObj.getSelectObject(setting.relaSheet));
+        });
+
+        return { spread, sheet, gather}
+    };
+
+})(jQuery);

+ 5 - 0
app/view/ledger/explode.ejs

@@ -275,6 +275,8 @@
                           </div>
                       </div>
                   </div>
+                    <div id="gcl-gather" class="tab-pane tab-select-show">
+                    </div>
                 </div>
             </div>
         </div>
@@ -305,6 +307,9 @@
                 <li class="nav-item">
                     <a class="nav-link" content="#check-list" id="check-list-tab" href="javascript: void(0);" style="display: none;">数据检查</a>
                 </li>
+                <li class="nav-item">
+                    <a class="nav-link" content="#gcl-gather" id="gcl-gather-tab" href="javascript: void(0);">清单汇总</a>
+                </li>
             </ul>
         </div>
     </div>

+ 1 - 0
config/web.js

@@ -152,6 +152,7 @@ const JsFiles = {
                     '/public/js/shares/sjs_setting.js',
                     '/public/js/shares/export_excel.js',
                     '/public/js/shares/cs_tools.js',
+                    '/public/js/shares/cs_gcl_gather.js',
                     '/public/js/shares/merge_peg.js',
                     '/public/js/shares/new_tag.js',
                     '/public/js/zh_calc.js',