Pārlūkot izejas kodu

台账分解,查找定位

MaiXinRong 6 gadi atpakaļ
vecāks
revīzija
eb38faac20
2 mainītis faili ar 87 papildinājumiem un 13 dzēšanām
  1. 74 12
      app/public/js/ledger.js
  2. 13 1
      app/view/ledger/explode.ejs

+ 74 - 12
app/public/js/ledger.js

@@ -492,6 +492,7 @@ $(document).ready(function() {
         selectionChanged: function (e, info) {
             if (info.newSelections[0].row !== info.oldSelections[0].row) {
                 posOperationObj.loadCurPosData();
+                posSearch.search($('#pos-keyword').val());
             }
         },
     };
@@ -659,6 +660,58 @@ $(document).ready(function() {
     }
     treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
 
+    const posSearch = (function () {
+        let resultArr = [];
+        const search = function (keyword) {
+            if (keyword && keyword !== '') {
+                resultArr = [];
+                const sortData = posSpread.getActiveSheet().zh_data;
+                if (sortData) {
+                    for (let i = 0, iLength = sortData.length; i < iLength; i++) {
+                        const sd = sortData[i];
+                        if (sd.name && sd.name.indexOf(keyword) > -1) {
+                            resultArr.push({index: i, data: sd});
+                        }
+                    }
+                }
+                $('#pos-search-hint').html(' ' + resultArr.length + '个匹配').show();
+            } else {
+                resultArr = [];
+                $('#pos-search-hint').hide();
+            }
+        };
+        const locateNext = function () {
+            if (resultArr.length > 0) {
+                const sheet = posSpread.getActiveSheet();
+                const sel = sheet.getSelections()[0];
+                const curRow = sel ? sel.row : 0;
+                let next = _.find(resultArr, function (d) {
+                    return d.index > curRow;
+                });
+                if (!next) next = resultArr[0];
+                if (next.index !== curRow) {
+                    sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
+                    sheet.showRow(next.index, spreadNS.VerticalPosition.center);
+                }
+            }
+        };
+        const locatePre = function () {
+            if (resultArr.length > 0) {
+                const sheet = posSpread.getActiveSheet();
+                const sel = sheet.getSelections()[0];
+                const curRow = sel ? sel.row : 0;
+                let next = _.find(resultArr, function (d) {
+                    return d.index < curRow;
+                });
+                if (!next) next = resultArr[resultArr.length - 1];
+                if (next.index !== curRow) {
+                    sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
+                    sheet.showRow(next.index, spreadNS.VerticalPosition.center);
+                }
+            }
+        };
+        return {search, locateNext, locatePre};
+    })();
     // 台账模式加载部位明细数据
     if (checkTzMeasureType()) {
         $.divResizer({
@@ -674,6 +727,15 @@ $(document).ready(function() {
         postData('/tender/' + getTenderId() + '/pos', null, function (data) {
             pos.loadDatas(data);
         });
+        $('#pos-keyword').bind('input propertychange', function () {
+            posSearch.search(this.value);
+        });
+        $('#search-pre-pos').click(function () {
+            posSearch.locatePre();
+        });
+        $('#search-next-pos').click(function () {
+            posSearch.locateNext();
+        });
     }
     // 绑定部位明细编辑事件
     const posOperationObj = {
@@ -1351,16 +1413,22 @@ $(document).ready(function() {
         constructor(obj, spreadSetting) {
             const self = this;
             this.obj = obj;
-            this.url = '/ledger/search';
             this.spreadSetting = spreadSetting;
             this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
             SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
 
             $('#searchLedger', this.obj).bind('click', function () {
-                const data = { keyword: $('input', self.obj).val() };
-                postData(preUrl + '/ledger/search', data, function (result) {
-                    SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', result);
-                });
+                const keyword = $('input', self.obj).val();
+                this.searchResult = [];
+                const sortData = SpreadJsObj.getSortData(ledgerSpread.getActiveSheet());
+                for (const node of sortData) {
+                    if ((node.code && node.code.indexOf(keyword) > -1) ||
+                        node.b_code && node.b_code.indexOf(keyword) > -1 ||
+                        node.name && node.name.indexOf(keyword) > -1) {
+                        this.searchResult.push(node);
+                    }
+                }
+                SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
             });
             this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
                 const sheet = info.sheet;
@@ -1370,13 +1438,7 @@ $(document).ready(function() {
                 const curBills = data[info.row];
                 if (!curBills) { return }
 
-                const mainSheet = ledgerSpread.getActiveSheet();
-                const mainTree = mainSheet.zh_tree;
-                mainTree.postData('locate', null, {id: curBills.ledger_id}, function (result) {
-                    treeOperationObj.refreshTree(mainSheet, result);
-                    treeOperationObj.refreshOperationValid(mainSheet);
-                    SpreadJsObj.locateTreeNode(mainSheet, curBills.ledger_id);
-                });
+                SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), curBills.ledger_id);
             });
         }
     }

+ 13 - 1
app/view/ledger/explode.ejs

@@ -66,6 +66,18 @@
                             <li class="nav-item">
                                 <a class="nav-link active" href="javascript:void(0)">部位明细</a>
                             </li>
+                            <li class="nav-item">
+                                <div class="mt-1 ml-2">
+                                    <div class="input-group input-group-sm">
+                                        <input type="text" class="form-control" placeholder="输入名称查找" id="pos-keyword">
+                                        <div class="input-group-append" id="button-addon3">
+                                            <button class="btn btn-outline-secondary" type="button" title="上一个" id="search-pre-pos"><i class="fa fa-angle-double-left"></i></button>
+                                            <button class="btn btn-outline-secondary" type="button" title="下一个" id="search-next-pos"><i class="fa fa-angle-double-right"></i></button>
+                                        </div>
+                                        <div class="small" id="pos-search-hint" style="vertical-align: bottom; display: none"></div>
+                                    </div>
+                                </div>
+                            </li>
                         </ul>
                     </div>
                     <div class="sp-wrap" id="pos-spread">
@@ -79,7 +91,7 @@
                     <div id="search" class="tab-pane">
                         <div class="sjs-bar-1">
                             <div class="input-group input-group-sm">
-                                <input id="searchKeyword" type="text" class="form-control" placeholder="项目节编号/清单编号/名称" aria-label="Recipient's username" aria-describedby="button-addon2">
+                                <input id="searchKeyword" type="text" class="form-control" placeholder="可查找 项目节编号/清单编号/名称" aria-label="Recipient's username" aria-describedby="button-addon2">
                                 <div class="input-group-append">
                                     <button class="btn btn-outline-secondary" type="button" id="searchLedger">搜索</button>
                                 </div>