| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 | 'use strict';/** * * * @author Mai * @date * @version */$(document).ready(() => {    autoFlashHeight();    const compareSpread = SpreadJsObj.createNewSpread($('#cost-compare')[0]);    const compareSheet = compareSpread.getActiveSheet();    const spreadSetting = {        cols: [            {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},            {title: '投资估算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'gu_dgn_qty', hAlign: 2, width: 80},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'gu_dgn_price', hAlign: 2, width: 80, type: 'Number'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gu_tp', hAlign: 2, width: 80, type: 'Number'},            {title: '初步概算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'gai_dgn_qty', hAlign: 2, width: 80},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'gai_dgn_price', hAlign: 2, width: 80, type: 'Number'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gai_tp', hAlign: 2, width: 80, type: 'Number'},            {title: '施工图预算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'yu_dgn_qty', hAlign: 2, width: 80},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'yu_dgn_price', hAlign: 2, width: 80, type: 'Number'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'yu_tp', hAlign: 2, width: 80, type: 'Number'},        ],        emptyRows: 0,        headRows: 2,        headRowHeight: [25, 25],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        readOnly: true,    };    sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);    SpreadJsObj.initSheet(compareSheet, spreadSetting);    const compareTree = createNewPathTree('final', {        id: 'id',        pid: 'pid',        order: 'order',        level: 'level',        rootId: -1,    });    function compareCode(str1, str2, symbol = '-') {        if (!str1) {            return 1;        } else if (!str2) {            return -1;        }        function compareSubCode(code1, code2) {            if (numReg.test(code1)) {                if (numReg.test(code2)) {                    return parseInt(code1) - parseInt(code2);                } else {                    return -1                }            } else {                if (numReg.test(code2)) {                    return 1;                } else {                    return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1); //code1.localeCompare(code2);                }            }        }        const numReg = /^[0-9]+$/;        const aCodes = str1.split(symbol), bCodes = str2.split(symbol);        for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) {            const iCompare = compareSubCode(aCodes[i], bCodes[i]);            if (iCompare !== 0) {                return iCompare;            }        }        return aCodes.length - bCodes.length;    }    postData(window.location.pathname + '/load', {}, function (result) {        const setting = { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] };        const guTree = createNewPathTree('ledger', setting);        guTree.loadDatas(result.gu);        treeCalc.calculateAll(guTree);        compareTree.loadTree(guTree, function (cur, source) {            cur.base = true;            cur.gu_dgn_qty1 = ZhCalc.add(cur.gu_dgn_qty1, source.dgn_qty1);            cur.gu_dgn_qty2 = ZhCalc.add(cur.gu_dgn_qty2, source.dgn_qty2);            cur.gu_tp = ZhCalc.add(cur.gu_tp, source.total_price);        });        const gaiTree = createNewPathTree('ledger', setting);        gaiTree.loadDatas(result.gai);        treeCalc.calculateAll(gaiTree);        compareTree.loadTree(gaiTree, function (cur, source) {            cur.base = true;            cur.gai_dgn_qty1 = ZhCalc.add(cur.gai_dgn_qty1, source.dgn_qty1);            cur.gai_dgn_qty2 = ZhCalc.add(cur.gai_dgn_qty2, source.dgn_qty2);            cur.gai_tp = ZhCalc.add(cur.gai_tp, source.total_price);        });        const yuTree = createNewPathTree('ledger', setting);        yuTree.loadDatas(result.yu);        treeCalc.calculateAll(yuTree);        compareTree.loadTree(yuTree, function (cur, source) {            cur.base = true;            cur.yu_dgn_qty1 = ZhCalc.add(cur.yu_dgn_qty1, source.dgn_qty1);            cur.yu_dgn_qty2 = ZhCalc.add(cur.yu_dgn_qty2, source.dgn_qty2);            cur.yu_tp = ZhCalc.add(cur.yu_tp, source.total_price);        });        compareTree.afterLoad(node => {            if (node.code === '1')console.log(node);            node.gu_dgn_price = ZhCalc.div(node.gu_tp, node.gu_dgn_qty1, 2);            node.gu_dgn_qty = node.gu_dgn_qty1                ? (node.gu_dgn_qty2 ? node.gu_dgn_qty1 + '/' + node.gu_dgn_qty2 : node.gu_dgn_qty1)                : (node.gu_dgn_qty2 ? '/' + node.gu_dgn_qty2 : '');            node.gai_dgn_price = ZhCalc.div(node.gai_tp, node.gai_dgn_qty1, 2);            node.gai_dgn_qty = node.gai_dgn_qty1                ? (node.gai_dgn_qty2 ? node.gai_dgn_qty1 + '/' + node.gai_dgn_qty2 : node.gai_dgn_qty1)                : (node.gai_dgn_qty2 ? '/' + node.gai_dgn_qty2 : '');            node.yu_dgn_price = ZhCalc.div(node.yu_tp, node.yu_dgn_qty1, 2);            node.yu_dgn_qty = node.yu_dgn_qty1                ? (node.yu_dgn_qty2 ? node.yu_dgn_qty1 + '/' + node.yu_dgn_qty2 : node.yu_dgn_qty1)                : (node.yu_dgn_qty2 ? '/' + node.yu_dgn_qty2 : '');        });        compareTree.resortChildrenByCustom(function (x, y) {            const iCode = compareCode(x.code, y.code);            if (iCode) return iCode;            if (!x.name) return -1;            if (!y.name) return 1;            return x.name.localeCompare(y.name)        });        SpreadJsObj.loadSheetData(compareSheet, SpreadJsObj.DataType.Tree, compareTree);    });    $.subMenu({        menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',        toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',        key: 'menu.1.0.0',        miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',        callback: function (info) {            if (info.mini) {                $('.panel-title').addClass('fluid');                $('#sub-menu').removeClass('panel-sidebar');            } else {                $('.panel-title').removeClass('fluid');                $('#sub-menu').addClass('panel-sidebar');            }            autoFlashHeight();            compareSpread.refresh();        }    });    // 显示层次    (function (select, sheet) {        $(select).click(function () {            if (!sheet.zh_tree) return;            const tag = $(this).attr('tag');            const tree = sheet.zh_tree;            setTimeout(() => {                showWaitingView();                switch (tag) {                    case "1":                    case "2":                    case "3":                    case "4":                    case "5":                        tree.expandByLevel(parseInt(tag));                        SpreadJsObj.refreshTreeRowVisible(sheet);                        break;                    case "last":                        tree.expandByCustom(() => { return true; });                        SpreadJsObj.refreshTreeRowVisible(sheet);                        break;                }                closeWaitingView();            }, 100);        });    })('a[name=showLevel]', compareSheet);    class sfObject {        constructor() {            const self = this;            this.selectTree = Tender2Tree.convert(category, tenderList, null, null, function (node, source) {                node.lastStageOrder =`第${source.lastStageOrder}期`;                node.lastStageStatus = source.lastStageStatus;            });            const sfSpreadSetting = {                cols: [                    {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},                    {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@', cellType: 'tree'},                    {title: '期数', field: 'lastStageOrder', hAlign: 1, width: 60, formatter: '@'},                    {title: '审批状态', field: 'lastStageStatus', hAlign: 1, width: 60, formatter: '@'},                ],                emptyRows: 0,                headRows: 1,                headRowHeight: [32],                defaultRowHeight: 21,                headerFont: '12px 微软雅黑',                font: '12px 微软雅黑',                headColWidth: [30],                selectedBackColor: '#fffacd',                readOnly: true,            };            this.spread = SpreadJsObj.createNewSpread($('#sf-spread')[0]);            this.sheet = this.spread.getActiveSheet();            SpreadJsObj.initSheet(this.sheet, sfSpreadSetting);            SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.selectTree);            this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {                if (!info.sheet.zh_setting) return;                const col = info.sheet.zh_setting.cols[info.col];                if (col.field !== 'selected') return;                const node = SpreadJsObj.getSelectObject(info.sheet);                self.selectNode(node, !node[col.field]);                SpreadJsObj.reloadColData(info.sheet, 0);            });            $('#sf-select-all').click(function() {                for (const n of self.selectTree.nodes) {                    n.selected = this.checked;                }                SpreadJsObj.reloadColData(self.sheet, 0);            });            $('#select-final-ok').click(() => {                const rela = self.getSelects();                if (rela.length === 0) return;                postData(window.location.pathname + '/final', {id: rela}, function(result) {                    if (spreadSetting.cols.length < 13) {                        spreadSetting.cols.push(...[                            {title: '台账|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'dgn_qty', hAlign: 2, width: 80},                            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'dgn_price', hAlign: 2, width: 80, type: 'Number'},                            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},                            {title: '决算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'final_dgn_qty', hAlign: 2, width: 80},                            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'final_dgn_price', hAlign: 2, width: 80, type: 'Number'},                            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'final_tp', hAlign: 2, width: 80, type: 'Number'},                            {title: '增幅%|数量1/数量2', colSpan: '2|1', rowSpan: '1|1', field: 'grow_dgn_qty', hAlign: 2, width: 80},                            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'grow_tp', hAlign: 2, width: 80, type: 'Number'},                        ]);                    }                    const setting = { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price', 'end_gather_tp'] };                    compareTree.clearFinal();                    for (const r of result) {                        const tree = createNewPathTree('ledger', setting);                        tree.loadDatas(r);                        treeCalc.calculateAll(tree);                        compareTree.loadTree(tree, function (cur, source) {                            cur.total_price = ZhCalc.add(cur.total_price, source.total_price);                            cur.dgn_qty1 = ZhCalc.add(cur.dgn_qty1, source.dgn_qty1);                            cur.dgn_qty2 = ZhCalc.add(cur.dgn_qty2, source.dgn_qty2);                            cur.final_dgn_qty1 = ZhCalc.sum([cur.final_dgn_qty1, source.deal_dgn_qty1, source.c_dgn_qty1]);                            cur.final_dgn_qty2 = ZhCalc.sum([cur.final_dgn_qty2, source.deal_dgn_qty2, source.c_dgn_qty2]);                            cur.final_tp = ZhCalc.add(cur.final_tp, source.end_gather_tp);                        });                    }                    compareTree.afterLoad(node => {                        node.dgn_price = ZhCalc.div(node.total_price, node.dgn_qty1, 2);                        node.dgn_qty = node.dgn_qty1                            ? (node.dgn_qty2 ? node.dgn_qty1 + '/' + node.dgn_qty2 : node.dgn_qty1)                            : (node.dgn_qty2 ? '/' + node.dgn_qty2 : '');                        node.final_dgn_price = ZhCalc.div(node.final_tp, node.final_dgn_qty1, 2);                        node.final_dgn_qty = node.final_dgn_qty1                            ? (node.final_dgn_qty2 ? node.final_dgn_qty1 + '/' + node.final_dgn_qty2 : node.final_dgn_qty1)                            : (node.final_dgn_qty2 ? '/' + node.final_dgn_qty2 : '');                        node.grow_dgn_qty1 = ZhCalc.mul(ZhCalc.div(ZhCalc.sub(node.final_dgn_qty1, node.gai_dgn_qty1), node.gai_dgn_qty1, 4), 100);                        node.grow_dgn_qty2 = ZhCalc.mul(ZhCalc.div(ZhCalc.sub(node.final_dgn_qty2, node.gai_dgn_qty2), node.gai_dgn_qty2, 4), 100);                        node.grow_dgn_qty = node.grow_dgn_qty1                            ? (node.grow_dgn_qty2 ? node.grow_dgn_qty1 + '/' + node.grow_dgn_qty2 : node.grow_dgn_qty1)                            : (node.grow_dgn_qty2 ? '/' + node.grow_dgn_qty2 : '');                        node.grow_tp = ZhCalc.mul(ZhCalc.div(ZhCalc.sub(node.final_tp, node.gai_tp), node.gai_tp, 4), 100);                    });                    SpreadJsObj.reLoadSheetHeader(compareSheet);                    SpreadJsObj.reLoadSheetData(compareSheet);                    $('#select-final').modal('hide');                });            });        }        selectNode(node, select) {            const posterity = this.selectTree.getPosterity(node);            posterity.unshift(node);            for (const p of posterity) {                p.selected = select;            }        }        getSelects() {            const select = [];            for (const n of this.selectTree.nodes) {                if ((!n.children || n.children.length === 0) && n.selected) select.push(n.tid);            }            return select;        }    }    let sfSelect;    $('#select-final').on('shown.bs.modal', () => {        if (!sfSelect) sfSelect = new sfObject();    });});
 |