Browse Source

变更清单选择增加全选功能

laiguoran 3 years ago
parent
commit
e7d8bcc32a
2 changed files with 76 additions and 3 deletions
  1. 65 0
      app/public/js/change_information_set.js
  2. 11 3
      app/view/change/information_modal.ejs

+ 65 - 0
app/public/js/change_information_set.js

@@ -664,6 +664,7 @@ $(document).ready(() => {
         $('#code-input').val('');
         $('#code-input').siblings('a').hide();
         $('#code-list').html(codeHtml);
+        checkSelectAll();
     });
 
     // 右边项目节选择
@@ -721,6 +722,7 @@ $(document).ready(() => {
                 $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
             }
         }
+        checkSelectAll();
     });
 
     // 添加空白清单or签约清单
@@ -776,6 +778,7 @@ $(document).ready(() => {
         $('#code-input').val('');
         $('#code-input').siblings('a').hide();
         $('#code-list').html('');
+        $('#code-select-all').prop('checked', false);
     });
 
     $('#code-input').on('valuechange', function (e, previous) {
@@ -786,6 +789,7 @@ $(document).ready(() => {
             $(this).siblings('a').hide();
         }
         makeCodeTable($(this).val());
+        checkSelectAll();
     });
 
     $('.remove-btn').on('click', function () {
@@ -798,6 +802,53 @@ $(document).ready(() => {
         } else {
             makeCodeTable();
         }
+        checkSelectAll();
+    });
+    // 全选及取消
+    $('#code-select-all').click(function () {
+        // 全选checkbox
+        let index = $('#code-list').attr('data-index');
+        if (index) {
+            if ($(this).is(':checked')){
+                $('#code-list tr').each(function () {
+                    if ($(this).css('display') !== 'none') {
+                        $(this).find('input').prop('checked', true);
+                    }
+                })
+            } else {
+                $('#code-list tr').each(function () {
+                    if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
+                        $(this).find('input').prop('checked', false);
+                    }
+                });
+            }
+            // 判断还有无选中项目节编号
+            if ($('#code-list input').is(':checked')) {
+                // 去除部分data-detail值
+                let data_bwmx = [];
+                $('#code-list input:checked').each(function () {
+                    const tr = $(this).parents('tr');
+                    const length = tr.children('td').length;
+                    const gcl_id = tr.attr('gcl_id');
+                    const bwmx = length === 8 ?
+                        tr.children('td').eq(0).text() + '!_!' +
+                        tr.children('td').eq(1).text() + '!_!' +
+                        tr.children('td').eq(2).text() + '!_!' +
+                        tr.children('td').eq(3).text() + '!_!' +
+                        tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
+                        (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
+                    const quantity = tr.attr('quantity');
+                    const de_qu = bwmx + '*;*' + quantity;
+                    data_bwmx.push(de_qu);
+                });
+                data_bwmx = data_bwmx.join('$#$');
+                $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
+                $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
+            } else {
+                $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
+                $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
+            }
+        }
     });
 
     // 记录变更信息操作
@@ -869,6 +920,16 @@ $(document).ready(() => {
         toastr.success('已还原到上次保存状态');
     });
 });
+function checkSelectAll() {
+    let check = $('#code-list tr').length > 0 ? true : false;
+    $('#code-list tr').each(function () {
+        if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
+            check = false;
+        }
+    });
+    $('#code-select-all').prop('checked', check);
+}
+
 function checkChangeFrom() {
     let returnFlag = false;
     // 表单判断
@@ -920,6 +981,10 @@ function tableDataRemake(changeListData) {
     $('#table-list-select tr').removeClass('table-success');
     $('#table-list-select tr').attr('data-bwmx', '');
     $('#code-list').html('');
+    $('#code-list').attr('data-index', '');
+    $('#code-input').val('');
+    $('#code-select-all').prop('checked', false);
+    $('#code-input').siblings('a').hide();
     // 根据已添加的清单显示
     if (changeList.length > 0 && changeList[0]) {
         const removeList = [];

+ 11 - 3
app/view/change/information_modal.ejs

@@ -128,9 +128,17 @@
                         </div>
                     </div>
                     <div class="col-12">
-                        <div class="mb-2 col-6 p-0 search-group mt-2">
-                            <input class="form-control form-control-sm" id="code-input" placeholder="输入 项目节编号、名称、计量单元 检索">
-                            <a href="javascript:void(0);" style="display: none" data-btn="code" class="text-danger remove-btn" title="移除关键词"><i class="fa fa-times-circle "></i></a>
+                        <div class="row mb-2 mt-2 mx-0 p-0">
+                            <div class="col-6 pl-0 p-0 search-group mt-2">
+                                <input class="form-control form-control-sm" id="code-input" placeholder="输入 项目节编号、名称、计量单元 检索">
+                                <a href="javascript:void(0);" style="display: none" data-btn="code" class="text-danger remove-btn" title="移除关键词"><i class="fa fa-times-circle "></i></a>
+                            </div>
+                            <div class="ml-auto mt-2">
+                                <div class="custom-control custom-checkbox mt-1">
+                                    <input type="checkbox" id="code-select-all" class="custom-control-input">
+                                    <label class="custom-control-label" for="code-select-all">全选</label>
+                                </div>
+                            </div>
                         </div>
                         <div style="overflow-y:auto" class="sjs-biangeng-height">
                             <table class="table table-striped table-bordered table-hover table-sm fixed_headers2">