浏览代码

标段列表折叠展开和不可用类别标段展示

laiguoran 5 年之前
父节点
当前提交
8b146f9471
共有 3 个文件被更改,包括 111 次插入34 次删除
  1. 20 11
      app/public/js/tender_list.js
  2. 90 22
      app/public/js/tender_list_manage.js
  3. 1 1
      app/view/tender/manage_modal.ejs

+ 20 - 11
app/public/js/tender_list.js

@@ -190,7 +190,7 @@ function initTenderTree () {
             }
             }
         }
         }
     }
     }
-    function getCategoryNode(category, value, parent) {
+    function getCategoryNode(category, value, parent, i = null) {
         const array = parent ?  parent.children : tenderTree;
         const array = parent ?  parent.children : tenderTree;
         let cate = findCategoryNode(category.id, value, array);
         let cate = findCategoryNode(category.id, value, array);
         if (!cate) {
         if (!cate) {
@@ -201,7 +201,7 @@ function initTenderTree () {
                 vid: value,
                 vid: value,
                 name: cateValue.value,
                 name: cateValue.value,
                 children: [],
                 children: [],
-                level: category.level,
+                level: i ? i : category.level,
                 sort_id: ++parentId,
                 sort_id: ++parentId,
             };
             };
             array.push(cate);
             array.push(cate);
@@ -210,11 +210,17 @@ function initTenderTree () {
     }
     }
     function loadTenderCategory (tender) {
     function loadTenderCategory (tender) {
         let tenderCategory = null;
         let tenderCategory = null;
-        for (const lc of levelCategory) {
+        for (const [index,lc] of levelCategory.entries()) {
             const tenderCate = findNode('cid', lc.id, tender.category);
             const tenderCate = findNode('cid', lc.id, tender.category);
             if (tenderCate) {
             if (tenderCate) {
                 tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
                 tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
             } else {
             } else {
+                if (index === 0 && tender.category) {
+                    for (const [i,c] of tender.category.entries()) {
+                        const cate = findNode('id', c.cid, category);
+                        tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
+                    }
+                }
                 return tenderCategory;
                 return tenderCategory;
             }
             }
         }
         }
@@ -235,6 +241,7 @@ function initTenderTree () {
     for (const t of tenders) {
     for (const t of tenders) {
         calculateTender(t);
         calculateTender(t);
         t.valid = true;
         t.valid = true;
+        delete t.level;
         if (t.category && levelCategory.length > 0) {
         if (t.category && levelCategory.length > 0) {
             const parent = loadTenderCategory(t);
             const parent = loadTenderCategory(t);
             if (parent) {
             if (parent) {
@@ -247,6 +254,7 @@ function initTenderTree () {
             tenderTree.push(t);
             tenderTree.push(t);
         }
         }
     }
     }
+    console.log(tenderTree);
 }
 }
 function recursiveGetTenderNodeHtml (node, arr, pid) {
 function recursiveGetTenderNodeHtml (node, arr, pid) {
     const html = [];
     const html = [];
@@ -254,7 +262,7 @@ function recursiveGetTenderNodeHtml (node, arr, pid) {
     // 名称
     // 名称
     html.push('<td class="in-' + node.level + '">');
     html.push('<td class="in-' + node.level + '">');
     if (node.cid) {
     if (node.cid) {
-        html.push('<span class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span></i> <i class="fa fa-folder-o"></i> ', node.name);
+        html.push('<span class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ', node.name);
     } else {
     } else {
         html.push('<span class="text-muted mr-2">');
         html.push('<span class="text-muted mr-2">');
         html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
         html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
@@ -337,7 +345,6 @@ $(document).ready(() => {
     $('.modal-body', '#add-bd').append(getCategoryHtml());
     $('.modal-body', '#add-bd').append(getCategoryHtml());
     // 初始化标段树结构
     // 初始化标段树结构
     initTenderTree();
     initTenderTree();
-    console.log(tenderTree);
     $('.c-body').html(getTenderTreeHtml());
     $('.c-body').html(getTenderTreeHtml());
     bindTenderUrl();
     bindTenderUrl();
     // 分类
     // 分类
@@ -380,13 +387,15 @@ $(document).ready(() => {
             return;
             return;
         }
         }
         for (const c of category) {
         for (const c of category) {
-            const cate = {cid: c.id};
-            // if (c.type === categoryType.key.dropDown) {
+            if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) {
+                const cate = {cid: c.id};
+                // if (c.type === categoryType.key.dropDown) {
                 cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
                 cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
-            // } else if (c.type === categoryType.key.radio) {
-            //     cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
-            // }
-            data.category.push(cate);
+                // } else if (c.type === categoryType.key.radio) {
+                //     cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
+                // }
+                data.category.push(cate);
+            }
         }
         }
         $('#hide-all').show();
         $('#hide-all').show();
         postData('/list/add', data, function (result) {
         postData('/list/add', data, function (result) {

+ 90 - 22
app/public/js/tender_list_manage.js

@@ -45,6 +45,7 @@ const levelTreeSetting = {
 };
 };
 const levelNodes =[];
 const levelNodes =[];
 const tenderTree = [];
 const tenderTree = [];
+let parentId = 0;
 function createTree() {
 function createTree() {
     const zTree = $.fn.zTree.getZTreeObj('treeLevel');
     const zTree = $.fn.zTree.getZTreeObj('treeLevel');
     if (zTree) {
     if (zTree) {
@@ -188,7 +189,7 @@ function initTenderTree () {
             }
             }
         }
         }
     }
     }
-    function getCategoryNode(category, value, parent) {
+    function getCategoryNode(category, value, parent, i = null) {
         const array = parent ?  parent.children : tenderTree;
         const array = parent ?  parent.children : tenderTree;
         let cate = findCategoryNode(category.id, value, array);
         let cate = findCategoryNode(category.id, value, array);
         if (!cate) {
         if (!cate) {
@@ -199,19 +200,27 @@ function initTenderTree () {
                 vid: value,
                 vid: value,
                 name: cateValue.value,
                 name: cateValue.value,
                 children: [],
                 children: [],
-                level: category.level,
+                level: i ? i : category.level,
+                sort_id: ++parentId,
             };
             };
             array.push(cate);
             array.push(cate);
         }
         }
         return cate;
         return cate;
     }
     }
+
     function loadTenderCategory (tender) {
     function loadTenderCategory (tender) {
         let tenderCategory = null;
         let tenderCategory = null;
-        for (const lc of levelCategory) {
+        for (const [index,lc] of levelCategory.entries()) {
             const tenderCate = findNode('cid', lc.id, tender.category);
             const tenderCate = findNode('cid', lc.id, tender.category);
             if (tenderCate) {
             if (tenderCate) {
                 tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
                 tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
             } else {
             } else {
+                if (index === 0 && tender.category) {
+                    for (const [i,c] of tender.category.entries()) {
+                        const cate = findNode('id', c.cid, category);
+                        tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
+                    }
+                }
                 return tenderCategory;
                 return tenderCategory;
             }
             }
         }
         }
@@ -220,6 +229,7 @@ function initTenderTree () {
     tenderTree.splice(0, tenderTree.length);
     tenderTree.splice(0, tenderTree.length);
     for (const t of tenders) {
     for (const t of tenders) {
         t.valid = true;
         t.valid = true;
+        delete t.level;
         if (t.category && levelCategory.length > 0) {
         if (t.category && levelCategory.length > 0) {
             const parent = loadTenderCategory(t);
             const parent = loadTenderCategory(t);
             if (parent) {
             if (parent) {
@@ -233,13 +243,13 @@ function initTenderTree () {
         }
         }
     }
     }
 }
 }
-function recursiveGetTenderNodeHtml (node, arr) {
+function recursiveGetTenderNodeHtml (node, arr, pid) {
     const html = [];
     const html = [];
-    html.push('<tr>');
+    html.push('<tr pid="' + pid + '">');
     // 名称
     // 名称
     html.push('<td class="in-' + node.level + '">');
     html.push('<td class="in-' + node.level + '">');
     if (node.cid) {
     if (node.cid) {
-        html.push('<i class="fa fa-folder-o"></i> ', node.name);
+        html.push('<span class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ', node.name);
     } else {
     } else {
         html.push('<span class="text-muted mr-2">');
         html.push('<span class="text-muted mr-2">');
         html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
         html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
@@ -260,7 +270,7 @@ function recursiveGetTenderNodeHtml (node, arr) {
     // 管理
     // 管理
     html.push('<td tid="' + node.id + '">');
     html.push('<td tid="' + node.id + '">');
     if (!node.cid) {
     if (!node.cid) {
-        html.push('<a href="#javascript: void(0)" name="edit" class="btn btn-outline-primary btn-sm">编辑</a>');
+        html.push('<a href="javascript: void(0)" name="edit" class="btn btn-outline-primary btn-sm">编辑</a>');
         if (node.lastStage === null || node.lastStage === undefined) {
         if (node.lastStage === null || node.lastStage === undefined) {
             html.push('<a href="javascript: void(0)" name="del" class="btn btn-outline-danger btn-sm ml-1">删除</a>');
             html.push('<a href="javascript: void(0)" name="del" class="btn btn-outline-danger btn-sm ml-1">删除</a>');
         } else {
         } else {
@@ -271,7 +281,7 @@ function recursiveGetTenderNodeHtml (node, arr) {
     html.push('</tr>');
     html.push('</tr>');
     if (node.children) {
     if (node.children) {
         for (const c of node.children) {
         for (const c of node.children) {
-            html.push(recursiveGetTenderNodeHtml(c, node.children));
+            html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
         }
         }
     }
     }
     return html.join('');
     return html.join('');
@@ -294,7 +304,7 @@ function getTenderTreeHtml () {
         html.push('<table class="table table-hover table-bordered">');
         html.push('<table class="table table-hover table-bordered">');
         html.push(getTenderTreeHeaderHtml());
         html.push(getTenderTreeHeaderHtml());
         for (const t of tenderTree) {
         for (const t of tenderTree) {
-            html.push(recursiveGetTenderNodeHtml(t, tenderTree));
+            html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
         }
         }
         html.push('</table>');
         html.push('</table>');
         return html.join('');
         return html.join('');
@@ -304,7 +314,7 @@ function getTenderTreeHtml () {
 }
 }
 function bindTenderUrl() {
 function bindTenderUrl() {
     // 打开标段
     // 打开标段
-    $('a[name=name]', '.c-body').bind('click', function () {
+    $('body').on('click', '.c-body a[name=name]', function () {
         const tenderId = parseInt($(this).attr('id'));
         const tenderId = parseInt($(this).attr('id'));
         const tender = _.find(tenders, function (t) {
         const tender = _.find(tenders, function (t) {
             return t.id === tenderId;
             return t.id === tenderId;
@@ -319,7 +329,7 @@ function bindTenderUrl() {
         }
         }
     });
     });
     // 编辑
     // 编辑
-    $('a[name=edit]', '.c-body').on('click', function () {
+    $('body').on('click', '.c-body a[name=edit]', function () {
         const tid = parseInt($(this).parent().attr('tid'));
         const tid = parseInt($(this).parent().attr('tid'));
         const tender = _.find(tenders, {id: tid});
         const tender = _.find(tenders, {id: tid});
         $('[name=name]', '#edit-bd').val(tender.name);
         $('[name=name]', '#edit-bd').val(tender.name);
@@ -332,7 +342,7 @@ function bindTenderUrl() {
         $('#edit-bd').modal('show');
         $('#edit-bd').modal('show');
     });
     });
     // 删除
     // 删除
-    $('a[name=del]', '.c-body').bind('click', function () {
+    $('body').on('click', '.c-body a[name=del]', function () {
         $('#del-bd-ok').attr('tid', $(this).parent().attr('tid'));
         $('#del-bd-ok').attr('tid', $(this).parent().attr('tid'));
         $('#del-bd').modal('show');
         $('#del-bd').modal('show');
     });
     });
@@ -349,6 +359,8 @@ $(document).ready(() => {
     initTenderTree();
     initTenderTree();
     $('.c-body').html(getTenderTreeHtml());
     $('.c-body').html(getTenderTreeHtml());
     bindTenderUrl();
     bindTenderUrl();
+    console.log(tenderTree);
+    console.log(category);
     // 分类
     // 分类
     $('#cate-set').on('show.bs.modal', function () {
     $('#cate-set').on('show.bs.modal', function () {
         createTree();
         createTree();
@@ -394,14 +406,18 @@ $(document).ready(() => {
             return;
             return;
         }
         }
         for (const c of category) {
         for (const c of category) {
-            const cate = {cid: c.id};
             const cateObj = $('[cate-id=' + c.id + ']', '#add-bd');
             const cateObj = $('[cate-id=' + c.id + ']', '#add-bd');
-            if (c.type === categoryType.key.dropDown) {
+            if (parseInt($('select', cateObj).val()) !== 0) {
+                const cate = {cid: c.id};
                 cate.value = parseInt($('select', cateObj).val());
                 cate.value = parseInt($('select', cateObj).val());
-            } else if (c.type === categoryType.key.radio) {
-                cate.value = parseInt($('input:checked', cateObj).val());
+                data.category.push(cate);
             }
             }
-            data.category.push(cate);
+            // if (c.type === categoryType.key.dropDown) {
+            //     cate.value = parseInt($('select', cateObj).val());
+            // } else if (c.type === categoryType.key.radio) {
+            //     cate.value = parseInt($('input:checked', cateObj).val());
+            // }
+
         }
         }
         postData('/list/add', data, function (result) {
         postData('/list/add', data, function (result) {
             tenders.push(result);
             tenders.push(result);
@@ -424,14 +440,18 @@ $(document).ready(() => {
             return;
             return;
         }
         }
         for (const c of category) {
         for (const c of category) {
-            const cate = {cid: c.id};
             const cateObj = $('[cate-id=' + c.id + ']', '#edit-bd');
             const cateObj = $('[cate-id=' + c.id + ']', '#edit-bd');
-            if (c.type === categoryType.key.dropDown) {
+            if (parseInt($('select', cateObj).val()) !== 0) {
+                const cate = {cid: c.id};
                 cate.value = parseInt($('select', cateObj).val());
                 cate.value = parseInt($('select', cateObj).val());
-            } else if (c.type === categoryType.key.radio) {
-                cate.value = parseInt($('input:checked', cateObj).val());
+                data.category.push(cate);
             }
             }
-            data.category.push(cate);
+            // if (c.type === categoryType.key.dropDown) {
+            //     cate.value = parseInt($('select', cateObj).val());
+            // } else if (c.type === categoryType.key.radio) {
+            //     cate.value = parseInt($('input:checked', cateObj).val());
+            // }
+            // data.category.push(cate);
         }
         }
         postData('/list/update', data, function (result) {
         postData('/list/update', data, function (result) {
             const tender = _.find(tenders, {id: result.id});
             const tender = _.find(tenders, {id: result.id});
@@ -484,4 +504,52 @@ $(document).ready(() => {
             $('#del-bd').modal('hide');
             $('#del-bd').modal('hide');
         }
         }
     });
     });
+
+    // 展开和收起
+    $('body').on('click', '.fold-switch', function () {
+        if ($(this).children('i').hasClass('fa-minus-square-o')) {
+            $(this).children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
+            $(this).attr('title', '展开');
+            const cid = $(this).attr('cid');
+            const node = findTenderTreeNode(parseInt(cid), tenderTree);
+            doTrStatus(returnItem, 'hide');
+        } else {
+            $(this).children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
+            $(this).attr('title', '收起');
+            const cid = $(this).attr('cid');
+            const node = findTenderTreeNode(parseInt(cid), tenderTree);
+            doTrStatus(returnItem, 'show');
+        }
+    })
 });
 });
+
+function doTrStatus(node, status) {
+    if (status === 'show') {
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '收起');
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-plus-square-o').removeClass('fa-minus-square-o').addClass('fa-minus-square-o');
+    } else {
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').hide();
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '展开');
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-minus-square-o').removeClass('fa-plus-square-o').addClass('fa-plus-square-o');
+
+    }
+    // 判断是否还有一层
+    if (node.children) {
+        for (const c of node.children) {
+            doTrStatus(c, status);
+        }
+    }
+}
+let returnItem;
+const findTenderTreeNode = function(sortId, tree) {
+    tree.forEach((item) => {
+        if (item.sort_id !== undefined && item.sort_id === sortId) {
+            returnItem = item;
+            return item;
+        } else if (item.children && item.children.length > 0) {
+            findTenderTreeNode(sortId, item.children);
+        }
+    });
+}
+

+ 1 - 1
app/view/tender/manage_modal.ejs

@@ -80,7 +80,7 @@
             </div>
             </div>
             <div class="modal-footer">
             <div class="modal-footer">
                 <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
                 <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
-                <button type="button" class="btn btn-primary btn-sm">确定添加</button>
+                <button type="button" class="btn btn-primary btn-sm" id="set-cate-ok">确定添加</button>
             </div>
             </div>
         </div>
         </div>
     </div>
     </div>