ソースを参照

1.展开收起记忆功能
2.整合几个页面的展开收起js

laiguoran 5 年 前
コミット
0bb7960ab8

+ 2 - 0
app/controller/tender_controller.js

@@ -104,6 +104,8 @@ module.exports = app => {
                 renderData.measureType = tenderConst.measureType;
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.jsFiles);
                 renderData.auditConst = auditConst;
+                renderData.uid = this.ctx.session.sessionUser.accountId;
+                renderData.pid = this.ctx.session.sessionProject.id;
                 await this.layout(view, renderData, modal);
             } catch (err) {
                 this.log(err);

+ 124 - 77
app/public/js/tender_list.js

@@ -47,6 +47,7 @@ const levelTreeSetting = {
 const levelNodes =[];
 const tenderTree = [];
 let parentId = 0;
+// let hideList = [];
 function createTree() {
     const zTree = $.fn.zTree.getZTreeObj('treeLevel');
     if (zTree) {
@@ -351,6 +352,37 @@ function bindTenderUrl() {
     });
 }
 
+// function removeValueToCate(cate) {
+//     const changeCate = JSON.parse(JSON.stringify(cate));
+//     const newCate = [];
+//     for (const c of changeCate) {
+//         delete c.value;
+//         newCate.push(c);
+//     }
+//     return newCate;
+// }
+//
+// function localHideList() {
+//     const pro_cate = getLocalCache('pro_'+ pid + '_category_list');
+//     const cate = JSON.stringify(removeValueToCate(category));
+//     if (pro_cate && cate === pro_cate) {
+//         const userTenderHideList = getLocalCache(uphlname);
+//         if (userTenderHideList) {
+//             hideList = JSON.parse(userTenderHideList);
+//             for (const h of hideList) {
+//                 const cid = h.sort_id;
+//                 const node = findTenderTreeNode(parseInt(cid), tenderTree);
+//                 $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
+//                 $('.c-body tr td span[cid="' + cid + '"]').attr('title', '展开');
+//                 doTrStatus(returnItem, 'hide');
+//             }
+//         }
+//     } else {
+//         removeLocalCache(uphlname);
+//         setLocalCache('pro_'+ pid + '_category_list', cate);
+//     }
+// }
+
 $(document).ready(() => {
     autoFlashHeight();
     sortCategory();
@@ -361,6 +393,8 @@ $(document).ready(() => {
     initTenderTree();
     $('.c-body').html(getTenderTreeHtml());
     bindTenderUrl();
+    localHideList();
+
     // 分类
     $('#cate-set').on('show.bs.modal', function () {
         createTree();
@@ -423,82 +457,95 @@ $(document).ready(() => {
         });
     });
 
-    // 展开和收起
-    $('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');
-        }
-    });
-    
-    // 一键展开和收起
-    $('body').on('click', '.tree-toggle', function () {
-        const item = $(this).attr('data-item');
-        for (const tree of tenderTree) {
-            if (tree && tree.sort_id !== undefined) {
-                const cid = tree.sort_id;
-                const node = findTenderTreeNode(parseInt(cid), tenderTree);
-                console.log(node);
-                console.log(returnItem);
-                if (item === 'open') {
-                    $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
-                    $('.c-body tr td span[cid="' + cid + '"]').attr('title', '收起');
-                    doTrStatus(returnItem, 'show', 'all');
-                } else if (item === 'hide') {
-                    $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
-                    $('.c-body tr td span[cid="' + cid + '"]').attr('title', '展开');
-                    doTrStatus(returnItem, 'hide', 'all')
-                }
-            }
-        }
-    })
+    // // 展开和收起
+    // $('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');
+    //         hideList.push({sort_id: cid});
+    //         setLocalCache(uphlname, JSON.stringify(hideList));
+    //     } 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');
+    //         const index = hideList.findIndex(function(item) {
+    //             return parseInt(item.sort_id) === parseInt(cid);
+    //         });
+    //         hideList.splice(index, 1);
+    //         setLocalCache(uphlname, JSON.stringify(hideList));
+    //     }
+    // });
+    //
+    // // 一键展开和收起
+    // $('body').on('click', '.tree-toggle', function () {
+    //     const item = $(this).attr('data-item');
+    //     hideList = [];
+    //     if (item === 'open') {
+    //         setLocalCache(uphlname, JSON.stringify(hideList));
+    //     }
+    //     for (const tree of tenderTree) {
+    //         if (tree && tree.sort_id !== undefined) {
+    //             const cid = tree.sort_id;
+    //             const node = findTenderTreeNode(parseInt(cid), tenderTree);
+    //             if (item === 'open') {
+    //                 $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
+    //                 $('.c-body tr td span[cid="' + cid + '"]').attr('title', '收起');
+    //                 doTrStatus(returnItem, 'show', 'all');
+    //             } else if (item === 'hide') {
+    //                 $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
+    //                 $('.c-body tr td span[cid="' + cid + '"]').attr('title', '展开');
+    //                 doTrStatus(returnItem, 'hide', 'all');
+    //             }
+    //         }
+    //     }
+    // })
 });
 
-function doTrStatus(node, status, all = '') {
-    if (status === 'show') {
-        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
-        if (all === 'all') {
-            $('.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();
-        if (all === 'all') {
-            $('.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 && all === '') {
-        for (const [index,c] of node.children.entries()) {
-            const title = $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').eq(index).attr('title');
-            if (title === '收起') {
-                doTrStatus(c, status);
-            }
-        }
-    } else if (node.children && all === 'all') {
-        for (const c of node.children) {
-            doTrStatus(c, status, 'all');
-        }
-    }
-}
-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);
-        }
-    });
-}
+// function doTrStatus(node, status, all = '') {
+//     if (status === 'show') {
+//         $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
+//         if (all === 'all') {
+//             $('.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();
+//         if (all === 'all') {
+//             if (node.children) {
+//                 hideList.push({sort_id: node.sort_id});
+//                 setLocalCache(uphlname, JSON.stringify(hideList));
+//             }
+//             $('.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 && all === '') {
+//         for (const [index,c] of node.children.entries()) {
+//             const title = $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').eq(index).attr('title');
+//             if (title === '收起') {
+//                 doTrStatus(c, status);
+//             }
+//         }
+//     } else if (node.children && all === 'all') {
+//         for (const c of node.children) {
+//             doTrStatus(c, status, 'all');
+//         }
+//     }
+// }
+// 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);
+//         }
+//     });
+// }

+ 130 - 0
app/public/js/tender_showhide.js

@@ -0,0 +1,130 @@
+'use strict';
+
+let hideList = [];
+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);
+        }
+    });
+}
+
+function removeValueToCate(cate) {
+    const changeCate = JSON.parse(JSON.stringify(cate));
+    const newCate = [];
+    for (const c of changeCate) {
+        delete c.value;
+        newCate.push(c);
+    }
+    return newCate;
+}
+
+function localHideList() {
+    const pro_cate = getLocalCache('pro_'+ pid + '_category_list');
+    const cate = JSON.stringify(removeValueToCate(category));
+    if (pro_cate && cate === pro_cate) {
+        const userTenderHideList = getLocalCache(uphlname);
+        if (userTenderHideList) {
+            hideList = JSON.parse(userTenderHideList);
+            for (const h of hideList) {
+                const cid = h.sort_id;
+                const node = findTenderTreeNode(parseInt(cid), tenderTree);
+                $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
+                $('.c-body tr td span[cid="' + cid + '"]').attr('title', '展开');
+                doTrStatus(returnItem, 'hide');
+            }
+        }
+    } else {
+        removeLocalCache(uphlname);
+        setLocalCache('pro_'+ pid + '_category_list', cate);
+    }
+}
+
+function doTrStatus(node, status, all = '') {
+    if (status === 'show') {
+        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
+        if (all === 'all') {
+            $('.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();
+        if (all === 'all') {
+            if (node.children) {
+                hideList.push({sort_id: node.sort_id});
+                setLocalCache(uphlname, JSON.stringify(hideList));
+            }
+            $('.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 && all === '') {
+        for (const [index,c] of node.children.entries()) {
+            const title = $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').eq(index).attr('title');
+            if (title === '收起') {
+                doTrStatus(c, status);
+            }
+        }
+    } else if (node.children && all === 'all') {
+        for (const c of node.children) {
+            doTrStatus(c, status, 'all');
+        }
+    }
+}
+
+$(document).ready(() => {
+    // 展开和收起
+    $('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');
+            hideList.push({sort_id: cid});
+            setLocalCache(uphlname, JSON.stringify(hideList));
+        } 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');
+            const index = hideList.findIndex(function(item) {
+                return parseInt(item.sort_id) === parseInt(cid);
+            });
+            hideList.splice(index, 1);
+            setLocalCache(uphlname, JSON.stringify(hideList));
+        }
+    });
+
+    // 一键展开和收起
+    $('body').on('click', '.tree-toggle', function () {
+        const item = $(this).attr('data-item');
+        hideList = [];
+        if (item === 'open') {
+            setLocalCache(uphlname, JSON.stringify(hideList));
+        }
+        for (const tree of tenderTree) {
+            if (tree && tree.sort_id !== undefined) {
+                const cid = tree.sort_id;
+                const node = findTenderTreeNode(parseInt(cid), tenderTree);
+                if (item === 'open') {
+                    $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
+                    $('.c-body tr td span[cid="' + cid + '"]').attr('title', '收起');
+                    doTrStatus(returnItem, 'show', 'all');
+                } else if (item === 'hide') {
+                    $('.c-body tr td span[cid="' + cid + '"]').children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
+                    $('.c-body tr td span[cid="' + cid + '"]').attr('title', '展开');
+                    doTrStatus(returnItem, 'hide', 'all');
+                }
+            }
+        }
+    })
+});
+
+

+ 4 - 1
app/view/tender/index.ejs

@@ -13,4 +13,7 @@
     const category = JSON.parse('<%- JSON.stringify(categoryData) %>');
     const auditConst = JSON.parse('<%- JSON.stringify(auditConst) %>');
     const measureType = JSON.parse('<%- JSON.stringify(measureType) %>');
-</script>
+    const uid = '<%- uid %>';
+    const pid = '<%- pid %>';
+    const uphlname = 'user_' + uid + '_pro_' + pid + '_category_hide_list_index';
+</script>

+ 7 - 6
config/web.js

@@ -62,6 +62,7 @@ const JsFiles = {
                 ],
                 mergeFiles: [
                     "/public/js/zh_calc.js",
+                    "/public/js/tender_showhide.js",
                     "/public/js/tender_list.js"
                 ],
                 mergeFile: 'tender_list',
@@ -362,7 +363,7 @@ const JsFiles = {
             jgcl: {
                 files: [
                     "/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js",
-                    "/public/js/decimal.min.js",                    
+                    "/public/js/decimal.min.js",
                 ],
                 mergeFiles: [
                     "/public/js/sub_menu.js",
@@ -371,12 +372,12 @@ const JsFiles = {
                     "/public/js/path_tree.js",
                     "/public/js/se_jgcl.js",
                 ],
-                mergeFile: 'se_jgcl',                
+                mergeFile: 'se_jgcl',
             },
             bonus: {
                 files: [
                     "/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js",
-                    "/public/js/decimal.min.js",                    
+                    "/public/js/decimal.min.js",
                 ],
                 mergeFiles: [
                     "/public/js/sub_menu.js",
@@ -385,12 +386,12 @@ const JsFiles = {
                     "/public/js/path_tree.js",
                     "/public/js/se_bonus.js",
                 ],
-                mergeFile: 'se_bonus',                
+                mergeFile: 'se_bonus',
             },
             other: {
                 files: [
                     "/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js",
-                    "/public/js/decimal.min.js",                    
+                    "/public/js/decimal.min.js",
                 ],
                 mergeFiles: [
                     "/public/js/sub_menu.js",
@@ -400,7 +401,7 @@ const JsFiles = {
                     "/public/js/path_tree.js",
                     "/public/js/se_other.js",
                 ],
-                mergeFile: 'se_other',                
+                mergeFile: 'se_other',
             },
         },
         measure: {