| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 | 'use strict';/** * * * @author EllisRan * @date 2020/03/06 * @version */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 sortTenderTree(teTree = tenderTree) {    for (const tender of teTree) {        if (tender.sort) {            // 当前层排序            teTree.sort(function (a, b) {                if (a.sort && b.sort) {                    return a.sort - b.sort;                } else if (a.sort && !b.sort) {                    return -1;                } else if (b.sort && !a.sort) {                    return 1;                } else {                    return 0;                }            });        }    }    for (const tender of teTree) {        if (tender.children) {            sortTenderTree(tender.children);        }    }}function localHideList(wap = false) {    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);    }    if (!wap)        setTopTr();}$(window).resize(setTopTr);// 设置表头固定并动态调整宽度高度function setTopTr() {    for(let item = 0; item < $(".c-body table>thead>tr>th").length; item ++) {        $(".c-body table>thead>tr>th").eq(item).outerWidth($(".c-body table>tbody>tr:first").children('td').eq(item).outerWidth());    }    $('.c-body table').css('margin-top', $(".c-body table>thead").height() - 4);    // $('.c-body table').css('margin-top', -2);}function doTrStatus(node, status, all = '') {    if (node) {        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));        }        setTopTr();    });    // 一键展开和收起    $('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');                }            }        }        setTopTr();    })});
 |