Bläddra i källkod

优化搜素速度

laiguoran 3 år sedan
förälder
incheckning
335ec9ebaf
1 ändrade filer med 24 tillägg och 15 borttagningar
  1. 24 15
      app/public/js/change_information_set.js

+ 24 - 15
app/public/js/change_information_set.js

@@ -90,7 +90,7 @@ function getPasteHint (str, row = '') {
     }
     return returnObj;
 }
-
+let searchCodeList = [];
 $(document).ready(() => {
     const changeSpreadSetting = {
         cols: [
@@ -632,6 +632,7 @@ $(document).ready(() => {
 
     // 清单选中和移除
     $('body').on('click', '#table-list-select tr', function () {
+        searchCodeList = [];
         $('#table-list-select tr').removeClass('table-warning');
         $(this).addClass('table-warning');
         const isCheck = $(this).hasClass('table-success') ? true : false;
@@ -671,6 +672,7 @@ $(document).ready(() => {
                     '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
                     '<td class="text-center"><input type="checkbox" ' + isDisabled + isChecked +
                     '></td></tr>';
+                searchCodeList.push(leaf.code + '|!|' + (leaf.jldy ? leaf.jldy: '') + '|!|' + (bwmx !== undefined ? bwmx : ''));
             }
         } else if (!isDeal && isCheck) {
             codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id="" mx_id=""><td class="text-center">1</td><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
@@ -1245,22 +1247,29 @@ function makeCodeTable(search = '') {
         $('#code-list tr').css('display', 'table-row');
         return;
     }
-    $('#code-list tr').css('display', 'table-row');
-    for(let i = 0; i < $('#code-list tr').length; i++) {
-        const length = $('#code-list tr').eq(i).children('td').length;
-        if (length === 9) {
-            const code = $('#code-list tr').eq(i).children('td').eq(1).text();
-            const name = $('#code-list tr').eq(i).children('td').eq(2).text();
-            const jldy = $('#code-list tr').eq(i).children('td').eq(6).text();
-            const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
-            if (isShow) {
-                $('#code-list tr').eq(i).css('display', 'none');
+    $('#code-list tr').css('display', 'none');
+    if (searchCodeList.length > 0) {
+        for (const [index,list] of searchCodeList.entries()) {
+            if (list.indexOf(search) !== -1) {
+                $('#code-list tr').eq(index).css('display', 'table-row');
+            }
+        }
+    } else {
+        for(let i = 0; i < $('#code-list tr').length; i++) {
+            const length = $('#code-list tr').eq(i).children('td').length;
+            if (length === 9) {
+                const code = $('#code-list tr').eq(i).children('td').eq(1).text();
+                const name = $('#code-list tr').eq(i).children('td').eq(2).text();
+                const jldy = $('#code-list tr').eq(i).children('td').eq(6).text();
+                const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
+                if (isShow) {
+                    $('#code-list tr').eq(i).css('display', 'table-row');
+                }
+                // $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
+            } else {
+                return;
             }
-            // $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
         }
-        // else {
-        //     return;
-        // }
     }
 }