Jelajahi Sumber

部位台账,只显示第一层功能

MaiXinRong 4 tahun lalu
induk
melakukan
bbcca519ff

+ 27 - 3
app/public/js/ledger_bwtz.js

@@ -37,6 +37,19 @@ $(document).ready(() => {
             if (!filter || unitTree.nodes.length === 0) return unitTree;
             filterUnitTree.clearDatas();
             const filterPath = [];
+            const checkFullPath = function (checkPath, valuePath) {
+                if (valuePath.indexOf(checkPath + '-') >= 0) return true;
+
+                const pathArray = checkPath.split('-');
+                const tmpArray = [];
+                for (let i = 0, iLen = pathArray.length; i < iLen; i++) {
+                    tmpArray.push(pathArray.slice(0, i+1).join('-'));
+                }
+                for (const ta of tmpArray) {
+                    if (ta === valuePath) return true;
+                }
+                return false;
+            };
             for (const node of unitTree.nodes) {
                 if ((node.code && node.code.indexOf(filter) >= 0) || (node.b_code && node.b_code.indexOf(filter) >= 0)
                     || (node.name && node.name.indexOf(filter) >= 0) || (node.pos_name && node.pos_name.indexOf(filter) >= 0))
@@ -44,7 +57,7 @@ $(document).ready(() => {
             }
             for (const node of unitTree.nodes) {
                 for (const fp of filterPath) {
-                    if (fp.indexOf(node.full_path) >= 0 || node.full_path.indexOf(fp) >= 0) {
+                    if (checkFullPath(fp, node.full_path)) {
                         filterUnitTree.addData(node, ['id', 'ledger_id', 'ledger_pid', 'order', 'level', 'full_path', 'pos_name',
                             'code', 'b_code', 'name', 'unit', 'unit_price', 'quantity', 'total_price', 'drawing_code_merge', 'memo_merge']);
                         break;
@@ -58,7 +71,9 @@ $(document).ready(() => {
             const node = SpreadJsObj.getSelectObject(xmjSheet);
             SpreadJsObj.resetTopAndSelect(unitSheet);
             if (node && node.unitTree) {
-                SpreadJsObj.loadSheetData(unitSheet, SpreadJsObj.DataType.Tree, unitTreeObj.getFilterUnitTree(node.unitTree));
+                const relaTree = unitTreeObj.getFilterUnitTree(node.unitTree);
+                if ($('#unit-show-1')[0].checked) relaTree.expandByLevel(1);
+                SpreadJsObj.loadSheetData(unitSheet, SpreadJsObj.DataType.Tree, relaTree);
             } else {
                 SpreadJsObj.initSheet(unitSheet, unitSpreadSetting);
             }
@@ -203,7 +218,16 @@ $(document).ready(() => {
     $('#unit-filter').bind('keydown', function (e) {
         const evt = window.event || e;
         if (e.keyCode == 13) unitTreeObj.loadCurUnitData();
-    })
+    });
+    $('#unit-show-1').bind('change', function () {
+        if (this.checked) {
+            unitSheet.zh_tree.expandByLevel(1);
+            SpreadJsObj.refreshTreeRowVisible(unitSheet);
+        } else {
+            unitSheet.zh_tree.expandByCustom(() => { return true; });
+            SpreadJsObj.refreshTreeRowVisible(unitSheet);
+        }
+    });
 
     // 显示层次
     (function (select, sheet) {

+ 63 - 1
app/public/js/stage_bwtz.js

@@ -29,12 +29,58 @@ $(document).ready(() => {
     unitSheet.frozenColumnCount(5);
     unitSheet.options.frozenlineColor = '#93b5e4';
 
+    const filterUnitTree = createNewPathTree('filter', {
+        id: 'ledger_id',
+        pid: 'ledger_pid',
+        order: 'order',
+        level: 'level',
+        rootId: -1,
+        fullPath: 'full_path',
+    });
+
     const unitTreeObj = {
+        getFilterUnitTree: function (unitTree) {
+            const filter = $('#unit-filter').val();
+            if (!filter || unitTree.nodes.length === 0) return unitTree;
+            filterUnitTree.clearDatas();
+            const filterPath = [];
+            const checkFullPath = function (checkPath, valuePath) {
+                if (valuePath.indexOf(checkPath + '-') >= 0) return true;
+
+                const pathArray = checkPath.split('-');
+                const tmpArray = [];
+                for (let i = 0, iLen = pathArray.length; i < iLen; i++) {
+                    tmpArray.push(pathArray.slice(0, i+1).join('-'));
+                }
+                for (const ta of tmpArray) {
+                    if (ta === valuePath) return true;
+                }
+                return false;
+            };
+            for (const node of unitTree.nodes) {
+                if ((node.code && node.code.indexOf(filter) >= 0) || (node.b_code && node.b_code.indexOf(filter) >= 0)
+                    || (node.name && node.name.indexOf(filter) >= 0) || (node.pos_name && node.pos_name.indexOf(filter) >= 0))
+                    filterPath.push(node.full_path);
+            }
+            for (const node of unitTree.nodes) {
+                for (const fp of filterPath) {
+                    if (checkFullPath(fp, node.full_path)) {
+                        filterUnitTree.addData(node, ['id', 'ledger_id', 'ledger_pid', 'order', 'level', 'full_path', 'pos_name',
+                            'code', 'b_code', 'name', 'unit', 'unit_price', 'quantity', 'total_price', 'drawing_code_merge', 'memo_merge']);
+                        break;
+                    }
+                }
+            }
+            filterUnitTree.sortTreeNode();
+            return filterUnitTree;
+        },
         loadCurUnitData: function () {
             const node = SpreadJsObj.getSelectObject(xmjSheet);
             SpreadJsObj.resetTopAndSelect(unitSheet);
             if (node && node.unitTree) {
-                SpreadJsObj.loadSheetData(unitSheet, SpreadJsObj.DataType.Tree, node.unitTree);
+                const relaTree = unitTreeObj.getFilterUnitTree(node.unitTree);
+                if ($('#unit-show-1')[0].checked) relaTree.expandByLevel(1);
+                SpreadJsObj.loadSheetData(unitSheet, SpreadJsObj.DataType.Tree, relaTree);
             } else {
                 SpreadJsObj.initSheet(unitSheet, unitSpreadSetting);
             }
@@ -210,6 +256,22 @@ $(document).ready(() => {
         xmjSpread.refresh();
         unitSpread.refresh();
     });
+
+
+    $('#unit-filter').bind('keydown', function (e) {
+        const evt = window.event || e;
+        if (e.keyCode == 13) unitTreeObj.loadCurUnitData();
+    });
+    $('#unit-show-1').bind('change', function () {
+        if (!unitSheet.zh_tree) return;
+        if (this.checked) {
+            unitSheet.zh_tree.expandByLevel(1);
+            SpreadJsObj.refreshTreeRowVisible(unitSheet);
+        } else {
+            unitSheet.zh_tree.expandByCustom(() => { return true; });
+            SpreadJsObj.refreshTreeRowVisible(unitSheet);
+        }
+    });
     // 显示层次
     (function (select, sheet) {
         $(select).click(function () {

+ 10 - 2
app/view/ledger/bwtz.ejs

@@ -44,8 +44,16 @@
                             <li class="nav-item">
                                 <a class="nav-link active" data-toggle="tab" href="#jldyjlqd" role="tab">计量单元/计量清单</a>
                             </li>
-                            <% if (ctx.app.config.is_debug) {%>
                             <li class="nav-item">
+                                <div class="d-inline-block ml-2">
+                                    <a class="btn btn-sm btn-light">
+                                        <div class="custom-control custom-checkbox">
+                                            <input type="checkbox" class="custom-control-input" id="unit-show-1">
+                                            <label class="custom-control-label text-primary" for="unit-show-1">只显示第一层</label>
+                                        </div>
+                                    </a>
+                                </div>
+                                <% if (ctx.app.config.is_debug) {%>
                                 <div class="d-inline-block">
                                     <div class="input-group input-group-sm ml-2">
                                         <div class="input-group-prepend">
@@ -57,8 +65,8 @@
                                 <div class="d-inline-block ml-2">
                                     <div class="alert-warning p-1"><i class="fa Example of exclamation-circle fa-exclamation-circle "></i> 父项/子项任一符合,均显示</div>
                                 </div>
+                                <% } %>
                             </li>
-                            <% } %>
                         </ul>
                     </div>
                     <div class="sp-wrap" id="unit-spread">

+ 23 - 0
app/view/stage/bwtz.ejs

@@ -56,6 +56,29 @@
                             <li class="nav-item">
                                 <a class="nav-link active" data-toggle="tab" href="#jldyjlqd" role="tab">计量单元/计量清单</a>
                             </li>
+                            <li class="nav-item">
+                                <div class="d-inline-block ml-2">
+                                    <a class="btn btn-sm btn-light">
+                                        <div class="custom-control custom-checkbox">
+                                            <input type="checkbox" class="custom-control-input" id="unit-show-1">
+                                            <label class="custom-control-label text-primary" for="unit-show-1">只显示第一层</label>
+                                        </div>
+                                    </a>
+                                </div>
+                                <% if (ctx.app.config.is_debug) {%>
+                                <div class="d-inline-block">
+                                    <div class="input-group input-group-sm ml-2">
+                                        <div class="input-group-prepend">
+                                            <span class="input-group-text" id="basic-addon1">数据筛选</span>
+                                        </div>
+                                        <input type="text" class="form-control form-control-sm m-0" id="unit-filter" placeholder="可根据 计量单元/清单编号/名称 筛选数据" style="width: 300px">
+                                    </div>
+                                </div>
+                                <div class="d-inline-block ml-2">
+                                    <div class="alert-warning p-1"><i class="fa Example of exclamation-circle fa-exclamation-circle "></i> 父项/子项任一符合,均显示</div>
+                                </div>
+                                <% } %>
+                            </li>
                         </ul>
                     </div>
                     <div class="sp-wrap" id="unit-spread">