| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 | 'use strict';/** * * * @author Mai * @date 2018/10/11 * @version */const EmptyTenderHtml = [    '',];const tenderTree = [];let parentId = 0;// 查询方法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 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 + '">');    // 名称    if (node.cid) {        html.push('<td class="in-' + node.level + '">');        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);        html.push('</td><td></td><td></td>');    } else {        html.push('<td colspan="3" class="in-' + node.level + '">');        html.push('<div class="row">');        html.push('<span class="col-8">');        html.push('<span class="text-muted mr-2">');        html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');        html.push('</span>');        html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a></span>');        html.push('<span class="col-auto ml-auto"></span>');        html.push('</div>');        html.push('<div class="d-flex justify-content-between"><span>');        // 计量期数        if (!node.cid) {            html.push(node.lastStage ? '第' + node.lastStage.order + '期' : '台账');        }        html.push('</span><span>');        // 累计合同计量        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('</span></div>');        // 截止本期累计完成/本期完成/未完成        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 () {    const html = [];    html.push('<table class="table">');    html.push('<thead>', '<tr>');    html.push('<th>名称</th>');    html.push('<th width="120">计量期数</th>');    html.push('<th>总价</th>');    html.push('</tr>', '</thead>');    if (tenderTree.length > 0) {        parentId = 0;        for (const t of tenderTree) {            html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));        }    } else {        html.push(EmptyTenderHtml.join(''));    }    html.push('</table>');    return html.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 = '/wap/tender/' + tenderId;        } else {            // for (const a of $('a', '#jlms')) {            //     a.href = '/wap/tender/' + tenderId + '/type?type=' + $(a).attr('mst');            // }            // $('#jlms').modal('show');        }    });}$(document).ready(() => {    // 初始化标段树结构    sortCategory();    initTenderTree();    $('.c-body').html(getTenderTreeHtml());    bindTenderUrl();    localHideList(true);});
 |