| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 | 'use strict';/** * * * @author Mai * @date 2018/10/11 * @version */const EmptyTenderHtml = [    '<div class="jumbotron">',    '<h3 class="display-6">还没有标段数据</h3>',    '</div>'];// levelTree - settingconst levelTreeSetting = {    view: {        selectedMulti: false    },    data: {        simpleData: {            idKey: 'lid',            pIdKey: 'lpId',            rootPId: 0,            enable: true,        }    },    edit: {        enable: true,        showRemoveBtn: false,        showRenameBtn: false,        drag: {            autoExpandTrigger: true,            isCopy: false,            isMove:  true,            prev: false,            next: false,            inner: true,        }    },    callback: {        beforeDrop: beforeDropNode,        onDrop: onDropNode,    }};const levelNodes =[];const tenderTree = [];let parentId = 0;function createTree() {    const zTree = $.fn.zTree.getZTreeObj('treeLevel');    if (zTree) {        zTree.destroy();    }    $.fn.zTree.init($("#treeLevel"), levelTreeSetting, levelNodes);}function beforeDropNode(treeId, treeNodes, targetNode, moveType, isCopy) {    if (targetNode !== null && targetNode.lid !== 1) {        const parent = targetNode.getParentNode();        if (parent && parent.lid === 1) {            return false;        }    }    for (var i=0,l=treeNodes.length; i<l; i++) {        if (treeNodes[i].drag === false) {            return false;        }        if (!targetNode && treeNodes[i].dropRoot === false) {            return false;        }        if(treeNodes[i].isParent === true && targetNode.lid !== 1){            return false;        }    }    return true;}function onDropNode(event, treeId, treeNodes, targetNode, moveType) {    const zTree = $.fn.zTree.getZTreeObj(treeId);    function resetFixNode(id) {        const node = zTree.getNodeByParam('lid', id);        node.isParent = true;        zTree.updateNode(node, false);        zTree.expandNode(node, true);    }    function moveChildren(children, node) {        if (!children || children.length === 0) { return }        for (const c of children) {            moveChildren(c.children, node);            zTree.moveNode(node, c, 'inner');        }    }    resetFixNode(1);    resetFixNode(2);    if (targetNode !== null && targetNode.lid === 1 && treeNodes[0].children && treeNodes[0].children.length !== 0) {        moveChildren(treeNodes[0].children, zTree.getNodeByParam('lid', 1));    } else if (targetNode !== null && targetNode.lid !== 1) {        if (targetNode.children.length >= 2) {            for (const c of targetNode.children) {                if (c.lid !== treeNodes[0].lid) {                    zTree.moveNode(treeNodes[0], c, 'inner');                }            }        }    }}// 查询方法function findNode (key, value, arr) {    for (const a of arr) {        if (a[key] && a[key] === value) {            return a;        }    }}function getPId(level) {    if (level !== 1) {        const p = findNode('level', level - 1, levelNodes);        if (p) {            return p.lid        } else {            return 1;        }    } else {        return 2;    }}// 分类数据排序function sortCategory() {    category.sort(function (a, b) {        return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;    });}// 初始化分类树结构数据function initCategoryLevelNode() {    levelNodes.splice(0, levelNodes.length);    levelNodes.push(        { lid:1, lpId:0, name:"可用类别", open:true, isParent: true, drag: false},        { lid:2, lpId:0, name:"已用类别", open:true, isParent: true, drag: false}    );    for (const c of category) {        const cate = JSON.parse(JSON.stringify(c));        cate.lid = levelNodes.length + 1;        cate.open = true;        cate.dropRoot = false;        if (!cate.level) {            cate.lpId = 1;            levelNodes.push(cate);        } else {            cate.lpId = getPId(cate.level);            levelNodes.push(cate);        }    }}// 新建标段 -- 分类属性选择function getCategoryHtml() {    function getSelectCategoryHtml (cate) {        const html = [];        html.push('<div class="form-group" cate-id="' + cate.id + '">');        html.push('<lable>', cate.name, '</lable>');        html.push('<select class="form-control form-control-sm">');        for (const v of cate.value) {            html.push('<option value="' + v.id + '">', v.value, '</option>');        }        html.push('<option value="0">不选</option>');        html.push('</select>');        html.push('</div>');        return html.join('');    }    function getRadioCategoryHtml (cate) {        const html = [];        html.push('<div class="form-group" cate-id="' + cate.id + '">');        html.push('<lable>', cate.name, '</lable>');        html.push('<div>');        for (const iV in cate.value) {            const v = cate.value[iV];            html.push('<div class="form-check-inline">');            html.push('<input class="form-check-input" type="radio"', 'name="' + cate.name + '" ', 'value="' , v.id, (iV == 0 ? '" checked="' : ''),  '">');            html.push('<label class="form-check-label">', v.value, '</label>');            html.push('</div>');        }        html.push('</div>');        html.push('</div>');        return html.join('');    }    const html = [];    for (const c of category) {        // if (c.type === categoryType.key.dropDown) {            html.push(getSelectCategoryHtml(c));        // } else if (c.type === categoryType.key.radio) {        //     html.push(getRadioCategoryHtml(c));        // }    }    return html.join('');}function calculateParent(node) {    if (node.children && node.cid) {        node.end_qc_tp = 0;        node.pre_gather_tp = 0;        node.gather_tp = 0;        node.sum_tp = 0;        node.lastStage = 0;        for (const c of node.children) {            calculateParent(c);            node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);            node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);            node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);            node.sum_tp = ZhCalc.add(node.sum_tp, c.sum_tp);            node.lastStage = c.cid                ? Math.max(node.lastStage, c.lastStage)                : (c.lastStage ? Math.max(node.lastStage, c.lastStage.order) : node.lastStage);        }    }}// 初始化TenderTree数据function initTenderTree () {    const levelCategory = category.filter(function (c) {        return c.level && c.level > 0;    });    function findCategoryNode(cid, value, array) {        for (const a of array) {            if (a.cid === cid && a.vid === value) {                return a;            }        }    }    function getCategoryNode(category, value, parent, i = null) {        const array = parent ?  parent.children : tenderTree;        let cate = findCategoryNode(category.id, value, array);        if (!cate) {            const cateValue = findNode('id', value, category.value);            if (!cateValue) return null;            cate = {                cid: category.id,                vid: value,                name: cateValue.value,                children: [],                level: i ? i : category.level,                sort_id: ++parentId,            };            array.push(cate);        }        return cate;    }    function loadTenderCategory (tender) {        let tenderCategory = null;        for (const [index, lc] of levelCategory.entries()) {            const tenderCate = findNode('cid', lc.id, tender.category);            if (tenderCate) {                tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);            } 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;    }    function calculateTender(tender) {        if (tender.lastStage) {            tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);            tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);            tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);            tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);        } else {            tender.sum_tp = tender.total_price;        }    }    tenderTree.splice(0, tenderTree.length);    for (const t of tenders) {        calculateTender(t);        t.valid = true;        delete t.level;        if (t.category && levelCategory.length > 0) {            const parent = loadTenderCategory(t);            if (parent) {                t.level = parent.level + 1;                parent.children.push(t);            } else {                tenderTree.push(t);            }        } else {            tenderTree.push(t);        }    }    for (const t of tenderTree) {        calculateParent(t);    }}function getProgressHtml(total, pre, cur) {    if (total !== 0) {        let preP = ZhCalc.mul(ZhCalc.div(pre, total, 2), 100, 0);        let curP = ZhCalc.mul(ZhCalc.div(cur, total, 2), 100, 0);        let other = Math.max(ZhCalc.sub(ZhCalc.sub(total, pre), cur), 0);        let otherP = Math.max(100 - preP - curP, 0);        const html = '<div class="progress">' +            '<div class="progress-bar bg-success" style="width: ' + preP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="截止上期完成:¥' + pre + '">' + preP + '%</div>' +            '<div class="progress-bar bg-info" style="width: ' + curP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成:¥' + cur + '">' + curP + '%</div>' +            '<div class="progress-bar bg-gray" style="width: ' + otherP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' + other + '">' + otherP + '%</div>' +            '</div>';        return html;    } else {        return '';    }}function recursiveGetTenderNodeHtml (node, arr, pid) {    const html = [];    html.push('<tr pid="' + pid + '">');    // 名称    html.push('<td width="30%" class="in-' + node.level + '">');    if (node.cid) {        html.push('<span onselectstart="return false" style="{-moz-user-select:none}" 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 {        html.push('<span class="text-muted mr-2">');        html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');        html.push('</span>');        //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');        html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');    }    html.push('</td>');    // 计量期数    html.push('<td width="120" class="text-center">');    if (!node.cid) {        html.push(node.lastStage ? '第' + node.lastStage.order + '期' : '台账');    }    html.push('</td>');    // 审批状态    html.push('<td style="width: 10%">');    html.push(node.lastStage ? auditConst.stage.statusString[node.lastStage.status] : auditConst.ledger.statusString[node.ledger_status]);    html.push(node.status_users ? '(' + node.status_users + ')' : '');    html.push('</td>');    // 累计合同计量    html.push('<td width="15%" class="text-right">');    const sum = node.lastStage ? ZhCalc.add(node.total_price, node.lastStage.end_qc_tp) : node.total_price;    html.push(node.sum_tp ? node.sum_tp : '');    html.push('</td>');    // 截止本期累计完成/本期完成/未完成    html.push('<td>');    if (node.lastStage) {        html.push(getProgressHtml(node.sum_tp, node.pre_gather_tp, node.gather_tp));    } else {        html.push('');    }    html.push('</td>');    html.push('</tr>');    if (node.children) {        for (const c of node.children) {            html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));        }    }    return html.join('');}// 根据TenderTree数据获取Html代码function getTenderTreeHtml () {    if (tenderTree.length > 0) {        const html = [];        html.push('<table class="table table-hover table-bordered">');        html.push('<thead style="position: fixed;left:56px;top: 34px;">', '<tr>');        html.push('<th style="width: 30%" class="text-center">', '标段名称', '</th>');        html.push('<th style="width: 10%" class="text-center">', '计量期数', '</th>');        html.push('<th style="width: 10%" class="text-center">','审批状态','</th>');        html.push('<th style="width: 10%" class="text-center">', '总价 <i class="fa fa-question-circle text-primary"  data-placement="bottom" data-toggle="tooltip" data-original-title="0号台账+截止本期数量变更"></i>', '</th>');        html.push('<th style="width: 40%" class="text-center">', '截止上期完成/本期完成/未完成', '</th>');        html.push('</tr>', '</thead>');        parentId = 0;        for (const t of tenderTree) {            html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));        }        html.push('</table>');        return html.join('');    } else {        return EmptyTenderHtml.join('');    }}function bindTenderUrl() {    $('.c-body').on('click', 'a', function () {        const tenderId = parseInt($(this).attr('id'));        const tender = _.find(tenders, function (t) {            return t.id === tenderId;        });        if (tender.measure_type) {            // window.location.href = '/tender/' + tenderId;            window.open('/tender/' + tenderId, '_blank');        } else {            for (const a of $('a', '#jlms')) {                a.href = '/tender/' + tenderId + '/type?type=' + $(a).attr('mst');            }            $('#jlms').modal('show');        }    });}$(document).ready(() => {    autoFlashHeight();    sortCategory();    // 初始化分类数据    initCategoryLevelNode();    $('.modal-body', '#add-bd').append(getCategoryHtml());    // 初始化标段树结构    initTenderTree();    $('.c-body').html(getTenderTreeHtml());    bindTenderUrl();    localHideList();    // 分类    $('#cate-set').on('show.bs.modal', function () {        createTree();    });    $('#set-cate-ok').click(function () {        const data = [];        const zTree = $.fn.zTree.getZTreeObj('treeLevel');        for (const c of category) {            const node = zTree.getNodeByParam('id', c.id);            const parent = node.getParentNode();            if (parent.lid === 1) {                data.push({id: c.id, level: 0});            } else {                data.push({id: c.id, level: node.getPath().length - 1});            }        }        postData('/setting/category/level', data, function (rst) {            for (const d of data) {                const c = findNode('id', d.id, category);                c.level = d.level;            }            sortCategory();            initCategoryLevelNode();            initTenderTree();            $('.c-body').html(getTenderTreeHtml());            localHideList();            $('#cate-set').modal('hide');        });    });    // 新增标段    $('#add-bd-ok').click(function () {        const data = {            name: cleanSymbols($('[name=name]', '#add-bd').val()),            valuation: $('[name=valuation]:checked').val(),            category: [],        };        if (!data.name || data.name === '') {            // TODO 提示用户            return;        }        for (const c of category) {            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());                // } else if (c.type === categoryType.key.radio) {                //     cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());                // }                data.category.push(cate);            }        }        postData('/list/add', data, function (result) {            tenders.push(result);            initTenderTree();            $('.c-body').html(getTenderTreeHtml());            bindTenderUrl();            localHideList();            $('#add-bd').modal('hide');            $('[name=name]', '#add-bd').val('');        });    });});
 |