|
@@ -0,0 +1,106 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 台账搜索相关(多个页面均使用:台账分解、台账审批、台账修订)
|
|
|
+ *
|
|
|
+ * 搜索基于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="mt-1 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.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.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.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;
|
|
|
+ }
|
|
|
+})(jQuery);
|