| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 | 
							- 'use strict';
 
- /**
 
-  * 台账搜索相关
 
-  * 多个页面均使用:
 
-  * 0好台账:台账分解、台账审批、台账修订、部位台账
 
-  * 期计量:计量台账、部位台账
 
-  *
 
-  * 搜索基于spreadjs,请放在gc.spread.sheets.all.10.0.1.min.js/spreadjs_zh.js之后
 
-  *
 
-  * @author Mai
 
-  * @date
 
-  * @version
 
-  */
 
- (function($){
 
-     $.posSearch = function (setting) {
 
-         if (!setting.selector || !setting.searchSpread) return;
 
-         const searchHtml =
 
-             '                                <div class="ml-2">\n' +
 
-             '                                    <div class="input-group input-group-sm">\n' +
 
-             '                                        <input type="text" class="form-control" placeholder="输入名称查找" id="pos-keyword">\n' +
 
-             '                                        <div class="input-group-append">\n' +
 
-             '                                            <span class="input-group-text" id="pos-search-hint">结果:0</span>\n' +
 
-             '                                        </div>\n' +
 
-             '                                        <div class="input-group-append" >\n' +
 
-             '                                            <button class="btn btn-outline-secondary" type="button" title="上一个" id="search-pre-pos"><i class="fa fa-angle-double-left"></i></button>\n' +
 
-             '                                            <button class="btn btn-outline-secondary" type="button" title="下一个" id="search-next-pos"><i class="fa fa-angle-double-right"></i></button>\n' +
 
-             '                                        </div>\n' +
 
-             '                                    </div>\n' +
 
-             '                                </div>\n';
 
-         $(setting.selector).html(searchHtml);
 
-         const sheet = setting.searchSpread.getActiveSheet();
 
-         const searchObj = (function () {
 
-             let resultArr = [];
 
-             const search = function (keyword) {
 
-                 if (keyword && keyword !== '') {
 
-                     resultArr = [];
 
-                     const sortData = sheet.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});
 
-                             }
 
-                         }
 
-                     }
 
-                 } else {
 
-                     resultArr = [];
 
-                 }
 
-                 $('#pos-search-hint').html('结果:' + resultArr.length);
 
-             };
 
-             const searchAndLocate = function (keyword) {
 
-                 search(keyword);
 
-                 if (resultArr.length > 0) {
 
-                     const sel = sheet.getSelections()[0];
 
-                     const curRow = sel ? sel.row : 0;
 
-                     const pos = resultArr[0];
 
-                     if (pos.index !== curRow) {
 
-                         sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
 
-                         sheet.getParent().focus();
 
-                         sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
 
-                     }
 
-                 }
 
-             };
 
-             const locateNext = function () {
 
-                 if (resultArr.length > 0) {
 
-                     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.getParent().focus();
 
-                         sheet.showRow(next.index, spreadNS.VerticalPosition.center);
 
-                     }
 
-                 }
 
-             };
 
-             const locatePre = function () {
 
-                 if (resultArr.length > 0) {
 
-                     const sel = sheet.getSelections()[0];
 
-                     const curRow = sel ? sel.row : 0;
 
-                     let next = _.findLast(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.getParent().focus();
 
-                         sheet.showRow(next.index, spreadNS.VerticalPosition.center);
 
-                     }
 
-                 }
 
-             };
 
-             return {search, searchAndLocate, locateNext, locatePre};
 
-         })();
 
-         // $('#pos-keyword').bind('input propertychange', function () {
 
-         //     posSearch.search(this.value);
 
-         // });
 
-         $('#pos-keyword').bind('keydown', function(e){
 
-             if (e.keyCode == 13) searchObj.searchAndLocate(this.value);
 
-         });
 
-         $('#search-pre-pos').click(function () {
 
-             searchObj.locatePre();
 
-         });
 
-         $('#search-next-pos').click(function () {
 
-             searchObj.locateNext();
 
-         });
 
-         return searchObj;
 
-     };
 
-     $.billsSearch = function (setting) {
 
-         if (!setting.selector || !setting.searchSpread || !setting.resultSpreadSetting) return;
 
-         if (!setting.searchRangeStr) setting.searchRangeStr = '项目节编号/清单编号/名称';
 
-         const resultId = setting.id + '-search-result';
 
-         const obj = $(setting.selector);
 
-         obj.html(
 
-             '                        <div class="sjs-bar">\n' +
 
-             '                            <div class="input-group input-group-sm pb-1">\n' +
 
-             '                                <div class="input-group-prepend">\n' +
 
-             (setting.searchOver ? '                                    <div class="input-group-text"><input type="radio" name="searchType" id="over"> 超计</div>\n' : '') +
 
-             (setting.searchEmpty ? '                                    <div class="input-group-text"><input type="radio" name="searchType" id="empty"> 漏计</div>\n' : '') +
 
-             '                                </div>' +
 
-             '                                <input id="searchKeyword" type="text" class="form-control" placeholder="可查找 ' + setting.searchRangeStr + '" aria-label="Recipient\'s username" aria-describedby="button-addon2">\n' +
 
-             '                                <div class="input-group-append">\n' +
 
-             '                                    <button class="btn btn-outline-secondary" type="button"">搜索</button>\n' +
 
-             '                                </div>\n' +
 
-             '                            </div>\n' +
 
-             '                        </div>\n' +
 
-             '                        <div id="' + resultId + '" class="sjs-sh">\n' +
 
-             '                        </div>'
 
-         );
 
-         autoFlashHeight();
 
-         const resultSpread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
 
-         SpreadJsObj.initSheet(resultSpread.getActiveSheet(), setting.resultSpreadSetting);
 
-         SpreadJsObj.forbiddenSpreadContextMenu('#' + resultId, resultSpread);
 
-         const searchSheet = setting.searchSpread.getActiveSheet();
 
-         let searchResult = [];
 
-         const searchBills = function () {
 
-             const keyword = $('#searchKeyword', obj).val();
 
-             searchResult = [];
 
-             const sortData = SpreadJsObj.getSortData(searchSheet);
 
-             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) {
 
-                     const data = JSON.parse(JSON.stringify(node));
 
-                     data.visible = true;
 
-                     searchResult.push(data);
 
-                 }
 
-             }
 
-             SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
 
-         };
 
-         const calculateCompletePercent = function (searchResult) {
 
-             if (!searchResult) return;
 
-             for (const sr of searchResult) {
 
-                 const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
 
-                 sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
 
-             }
 
-         };
 
-         const searchOver = function () {
 
-             searchResult = [];
 
-             const sortData = SpreadJsObj.getSortData(searchSheet);
 
-             for (const node of sortData) {
 
-                 if (node.children && node.children.length > 0) continue;
 
-                 if (setting.checkOver && setting.checkOver(node)) {
 
-                     const data = JSON.parse(JSON.stringify(node));
 
-                     data.visible = true;
 
-                     searchResult.push(data);
 
-                 }
 
-             }
 
-             calculateCompletePercent(searchResult);
 
-             SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
 
-         };
 
-         const searchEmpty = function () {
 
-             searchResult = [];
 
-             const sortData = SpreadJsObj.getSortData(searchSheet);
 
-             for (const node of sortData) {
 
-                 if (node.children && node.children.length > 0) continue;
 
-                 if (setting.checkEmpty && setting.checkEmpty(node)) {
 
-                     const data = JSON.parse(JSON.stringify(node));
 
-                     data.visible = true;
 
-                     searchResult.push(data);
 
-                 }
 
-             }
 
-             calculateCompletePercent(searchResult);
 
-             SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
 
-         };
 
-         const searchLess = function () {
 
-             searchResult = [];
 
-             const sortData = SpreadJsObj.getSortData(searchSheet);
 
-             for (const node of sortData) {
 
-                 if (node.children && node.children.length > 0) continue;
 
-                 if (setting.checkLess && setting.checkLess(node)) {
 
-                     const data = JSON.parse(JSON.stringify(node));
 
-                     data.visible = true;
 
-                     searchResult.push(data);
 
-                 }
 
-             }
 
-             calculateCompletePercent(searchResult);
 
-             SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
 
-         };
 
-         $('input', this.obj).bind('keydown', function (e) {
 
-             if (e.keyCode == 13) searchBills();
 
-         });
 
-         $('button', this.obj).bind('click', () => {searchBills()});
 
-         $('#over', this.obj).bind('change', () => {searchOver()});
 
-         $('#empty', this.obj).bind('change', () => {searchLess()});
 
-         resultSpread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
 
-             const sheet = info.sheet;
 
-             const data = sheet.zh_data;
 
-             if (!data) { return }
 
-             const curBills = data[info.row];
 
-             if (!curBills) { return }
 
-             SpreadJsObj.locateTreeNode(searchSheet, curBills.ledger_id, true);
 
-             if (setting.afterLocated) {
 
-                 setting.afterLocated();
 
-             }
 
-         });
 
-         return {spread: resultSpread};
 
-     };
 
- })(jQuery);
 
 
  |