| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608 | 'use strict';/** * 从cookie中读取缓存的列显示设置,没有则取默认 * @returns {*[]} */function customColDisplay () {    const defaultSetting = [        { title: '投资估算', fields: ['gu_dgn_qty', 'gu_dgn_price', 'gu_tp'], visible: true },        { title: '设计概算', fields: ['gai_dgn_qty', 'gai_dgn_price', 'gai_tp'], visible: true },        { title: '施工图预算', fields: ['yu_dgn_qty', 'yu_dgn_price', 'yu_tp'], visible: true },        { title: '招标预算', fields: ['zb_dgn_qty', 'zb_dgn_price', 'zb_tp'], visible: true },        { title: '台账', fields: ['dgn_qty', 'dgn_price', 'total_price'], visible: true },        { title: '预估决算', fields: ['final_dgn_qty', 'final_dgn_price', 'final_tp'], visible: true },    ];    const settingStr = Cookies.get(ckColSetting);    if (settingStr) {        const customSetting = JSON.parse(settingStr);        for (const ds of defaultSetting) {            const cs = customSetting.find(x => {return x.title === ds.title});            if (cs) ds.visible = cs.visible;        }    }    return defaultSetting;}/** * 根据列显示设置,调整setting中的列是否显示 * @param setting * @param customDisplay */function customizeTreeSetting(setting, customDisplay) {    for (const cd of customDisplay) {        for (const c of setting.cols) {            if (cd.fields.indexOf(c.field) !== -1) {                c.defaultVisible = cd.visible;            }        }    }}$(document).ready(() => {    const compareTypeKey = 'budget-compareType';    const stackedBarCoverKey = 'budget-stackedBarCover';    const stackedBarKey = 'budget-stackedBar';    const comparePhaseKey = 'budget-comparePhase';    autoFlashHeight();    const compareSpread = SpreadJsObj.createNewSpread($('#cost-compare')[0]);    const compareSheet = compareSpread.getActiveSheet();    const getStackedBarTip = function (data) {        return data.stackedBarTips.join('\n');    };    const comparePhase = [        { key: 'gu', name: '投资估算', dgn1: 'gu_dgn_qty1', dgn2: 'gu_dgn_qty2', tp: 'gu_tp'},        { key: 'gai', name: '设计概算', dgn1: 'gai_dgn_qty1', dgn2: 'gai_dgn_qty2', tp: 'gai_tp'},        { key: 'yu', name: '施工图预算', dgn1: 'yu_dgn_qty1', dgn2: 'yu_dgn_qty2', tp: 'yu_tp'},        { key: 'zb', name: '招标预算', dgn1: 'zb_dgn_qty1', dgn2: 'zb_dgn_qty2', tp: 'zb_tp'},        { key: 'tz', name: '台账', dgn1: 'dgn_qty1', dgn2: 'dgn_qty2', tp: 'total_price'},        { key: 'final', name: '预估决算', dgn1: 'final_dgn_qty1', dgn2: 'final_dgn_qty2', tp: 'final_tp'},    ];    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, bc_type: 'number'},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'gu_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gu_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '设计概算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'gai_dgn_qty', hAlign: 2, width: 80, bc_type: 'number'},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'gai_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gai_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '施工图预算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'yu_dgn_qty', hAlign: 2, width: 80, bc_type: 'number'},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'yu_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'yu_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '招标预算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'zb_dgn_qty', hAlign: 2, width: 80, bc_type: 'number'},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'zb_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'zb_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},            {title: '台账|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'dgn_qty', hAlign: 2, width: 80, bc_type: 'number', visible: false},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},            {title: '预估决算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'final_dgn_qty', hAlign: 2, width: 80, bc_type: 'number', visible: false},            {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'final_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'final_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},            {title: '数据对比', colSpan: '1', rowSpan: '2', field: 'stackedBar', hAlign: 0, width: 300, cellType: 'stackedBar', stackedBarCover: false, bc_type: 'grid', defaultVisible: true, visible: false, getTip: getStackedBarTip},            {title: '增幅%|数量1/数量2', colSpan: '2|1', rowSpan: '1|1', field: 'compare_dgn_qty', hAlign: 2, width: 80},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'compare_tp', hAlign: 2, width: 80, type: 'Number'},        ],        emptyRows: 0,        headRows: 2,        headRowHeight: [25, 25],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        readOnly: true,        frozenColCount: 3,        frozenLineColor: '#93b5e4',        localCache: { key: 'budget-compare', colWidth: true },    };    sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);    let sfSelect;    const compareObj = {        comparePhase1: 'gai',        comparePhase2: 'final',        getCompareSelectHtml() {            const html = [];            for (const cp of comparePhase) {                html.push(`<option value="${cp.key}">${cp.name}</option>`);            }            return html.join('');        },        initCompare() {            const selectHtml = this.getCompareSelectHtml();            $('#compare1').html(selectHtml);            $('#compare2').html(selectHtml);            const comparePhase = Cookies.get(comparePhaseKey).split(',');            this.setComparePhase(comparePhase[0] || this.comparePhase1, comparePhase[1] || this.comparePhase2);        },        getCompareHint(phase1, phase2) {            if (!phase1) phase1 = this.comparePhase1;            if (!phase2) phase2 = this.comparePhase2;            const cp1 = comparePhase.find(x => { return x.key === phase1; });            const cp2 = comparePhase.find(x => { return x.key === phase2; });            return `增减幅度=(${cp2.name}-${cp1.name})/${cp1.name}*100%`;        },        setComparePhase(phase1, phase2) {            compareObj.comparePhase1 = phase1;            compareObj.comparePhase2 = phase2;            $('#compare-hint').html(compareObj.getCompareHint());            compareObj.reCalculateCompareData();            $('#compare-set').modal('hide');            Cookies.set(comparePhaseKey, phase1 + ',' + phase2);        },        curFinalId() {            return this.finalInfo ? this.finalInfo.id : undefined;        },        initFinalCol() {            const finalColField = ['dgn_qty', 'dgn_price', 'total_price', 'final_dgn_qty', 'final_dgn_price', 'final_tp', 'grow_dgn_qty', 'grow_tp'];            const finalCol = spreadSetting.cols.filter(x => { return finalColField.indexOf(x.field) >= 0; });            if (finalCol.length > 0 && !finalCol[0].visible) {                finalCol.forEach(x => { x.visible = true; });                this.initShowType();                SpreadJsObj.refreshColumnVisible(compareSheet);            }        },        initShowType() {            this.reCalcColVisible();            const colIndex = spreadSetting.cols.findIndex(x => { return x.field === 'stackedBar'});            spreadSetting.cols[colIndex].stackedBarCover = parseInt(this.stackedBarCover);        },        expand(tree, tag) {            switch (tag) {                case "1":                case "2":                case "3":                case "4":                case "5":                    tree.expandByLevel(parseInt(tag));                    break;                case "last":                    tree.expandByCustom(() => { return true; });                    break;            }        },        calcStackedBar(tree) {            const calcField = this.stackedBarField;            const calcFieldColor = { 'gu_tp': '#657798', 'gai_tp': '#EE6666', 'yu_tp': '#74CBED', 'total_price': '#FAC858', 'final_tp': '#62DAAB' };            const calcFieldCaption = { 'gu_tp': '估算', 'gai_tp': '概算', 'yu_tp': '预算', 'total_price': '台账', 'final_tp': '决算' };            const calc = function(node, base){                // const parent = tree.getParent(node);                // if (!parent) {                //     base = 0;                //     for (const cf of calcField) {                //         base = Math.max(node[cf], base);                //     }                // }                node.stackedBar = [];                node.stackedBarTips = [];                for (const cf of calcField) {                    node.stackedBar.push({color: calcFieldColor[cf], percent: ZhCalc.div(node[cf], base), field: cf});                    node.stackedBarTips.push(`${calcFieldCaption[cf]}: ${node[cf] || 0}`);                }                if (node.children) {                    for (const child of node.children) {                        calc(child, base);                    }                }            };            let commonBase = 0;            tree.children.forEach(x => {                for (const cf of calcField) {                    commonBase = Math.max(x[cf] || 0, commonBase);                }            });            for (const child of tree.children) {                calc(child, commonBase);            }        },        loadBudgetData(result) {            const compareTree = createNewPathTree('final', {                id: 'id',                pid: 'pid',                order: 'order',                level: 'level',                rootId: -1,            });            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);            });            const zbTree = createNewPathTree('ledger', setting);            zbTree.loadDatas(result.zb);            treeCalc.calculateAll(zbTree);            compareTree.loadTree(zbTree, function (cur, source) {                cur.base = true;                cur.zb_dgn_qty1 = ZhCalc.add(cur.zb_dgn_qty1, source.dgn_qty1);                cur.zb_dgn_qty2 = ZhCalc.add(cur.zb_dgn_qty2, source.dgn_qty2);                cur.zb_tp = ZhCalc.add(cur.zb_tp, source.total_price);            });            compareTree.afterLoad(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 : '');                node.zb_dgn_price = ZhCalc.div(node.zb_tp, node.zb_dgn_qty1, 2);                node.zb_dgn_qty = node.zb_dgn_qty1                    ? (node.zb_dgn_qty2 ? node.zb_dgn_qty1 + '/' + node.zb_dgn_qty2 : node.zb_dgn_qty1)                    : (node.zb_dgn_qty2 ? '/' + node.zb_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);            });            const expandTag = getLocalCache('revise-compare-level');            if (expandTag) compareObj.expand(compareTree, expandTag);            this.calcStackedBar(compareTree);            this.reCalculateCompareData(compareTree);            SpreadJsObj.loadSheetData(compareSheet, SpreadJsObj.DataType.Tree, compareTree);        },        loadFinalData(result, msg) {            if (msg) toastr.warning(msg);            this.finalInfo = result.finalInfo;            $('#final-info').html(`${moment(result.finalInfo.update_time).format('YYYY-MM-DD HH:mm:ss')} ${result.finalInfo.u_name}(${result.finalInfo.u_role})`);            this.initFinalCol();            const finalTree = createNewPathTree('ledger', {                id: 'tree_id',                pid: 'tree_pid',                order: 'order',                level: 'level',                rootId: -1,            });            finalTree.loadDatas(result.final);            const expandTag = getLocalCache('revise-compare-level');            if (expandTag) compareObj.expand(finalTree, expandTag);            this.calcStackedBar(finalTree);            this.reCalculateCompareData(finalTree);            SpreadJsObj.loadSheetData(compareSheet, SpreadJsObj.DataType.Tree, finalTree);            if (sfSelect) sfSelect.reloadSelect(this.finalInfo.tender);        },        reCalculateCompareData(calcTree) {            const tree = calcTree || compareSheet.zh_tree;            if (!tree) return;            const cp1 = comparePhase.find(x => { return x.key === this.comparePhase1; });            const cp2 = comparePhase.find(x => { return x.key === this.comparePhase2; });            treeCalc.calculateAll(tree, function(node) {                node.compare_dgn_qty1 = node[cp1.dgn1] ? ZhCalc.mul(ZhCalc.div(ZhCalc.sub(node[cp2.dgn1], node[cp1.dgn1]), node[cp1.dgn1], 4), 100) : 0;                node.compare_dgn_qty2 = node[cp1.dgn2] ? ZhCalc.mul(ZhCalc.div(ZhCalc.sub(node[cp2.dgn1], node[cp1.dgn1]), node[cp1.dgn1], 4), 100) : 0;                node.compare_dgn_qty = node.compare_dgn_qty1                    ? (node.compare_dgn_qty2 ? node.compare_dgn_qty1 + '/' + node.compare_dgn_qty2 : node.compare_dgn_qty1)                    : (node.compare_dgn_qty2 ? '/' + node.compare_dgn_qty2 : '');                node.compare_tp = node[cp1.tp] ? ZhCalc.mul(ZhCalc.div(ZhCalc.sub(node[cp2.tp], node[cp1.tp]), node[cp1.tp], 4), 100) : 0;            });            const index = spreadSetting.cols.findIndex(x => { return x.field === 'compare_dgn_qty'});            SpreadJsObj.reloadColData(compareSheet, index, 2);        },        loadCacheData(){            let stackedBarCache = getLocalCache(stackedBarKey);            if (stackedBarCache === null) stackedBarCache = 'gai_tp,total_price,final_tp';            this.setStackedBarField(stackedBarCache ? stackedBarCache.split(',') : []);            this.setCompareType(getLocalCache(compareTypeKey));            this.setStackedBarCover(getLocalCache(stackedBarCoverKey));            this.initShowType();        },        setStackedBarField(field){            this.stackedBarField = field;            setLocalCache(stackedBarKey, field.join(','));            if (compareSheet.zh_tree) this.calcStackedBar(compareSheet.zh_tree);            const colIndex = spreadSetting.cols.findIndex(x => { return x.field === 'stackedBar'});            SpreadJsObj.reloadColData(compareSheet, colIndex);        },        reCalcColVisible() {            const type = this.compareType;            spreadSetting.cols.forEach(x => {                if (!x.bc_type) return;                x.visible = x.bc_type === type && x.defaultVisible;            });        },        setCompareType(type) {            this.compareType = type || 'number';            $('[name=showType]').removeClass('active');            $(`[tag=${this.compareType}]`).addClass('active');            if (this.compareType === 'grid') {                $('.ml-grid').show();                $('.ml-number').hide();            } else {                $('.ml-grid').hide();                $('.ml-number').show();            }            this.reCalcColVisible();            setLocalCache(compareTypeKey, this.compareType);        },        setStackedBarCover(cover){            this.stackedBarCover = '1'; //cover || '1';            const colIndex = spreadSetting.cols.findIndex(x => { return x.field === 'stackedBar'});            spreadSetting.cols[colIndex].stackedBarCover = parseInt(this.stackedBarCover);            SpreadJsObj.reloadColData(compareSheet, colIndex);            setLocalCache(stackedBarCoverKey, this.stackedBarCover);        }    };    customizeTreeSetting(spreadSetting, customColDisplay());    compareObj.loadCacheData();    compareObj.initCompare();    SpreadJsObj.initSheet(compareSheet, spreadSetting);    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, msg) {        if (result.final) {            compareObj.loadFinalData(result, msg);        } else {            compareObj.loadBudgetData(result);        }    });    $.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();                compareObj.expand(tree, tag);                SpreadJsObj.refreshTreeRowVisible(sheet);                setLocalCache('revise-compare-level', tag);                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;            });            if (compareObj.finalInfo) {                this.selectTree.datas.forEach(x => {                    x.selected = compareObj.finalInfo.tender.indexOf(x.tid + '') >= 0;                })            }            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', {final_id: compareObj.curFinalId(), id: rela}, function(result, msg) {                    compareObj.loadFinalData(result, msg);                    $('#select-final').modal('hide');                });            });        }        reloadSelect(select) {            if (compareObj.finalInfo) {                this.selectTree.datas.forEach(x => {                    x.selected = select.indexOf(x.tid + '') >= 0;                })            }            SpreadJsObj.reloadColData(this.sheet, 0);        }        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;        }    }    $('#select-final').on('shown.bs.modal', () => {        if (!sfSelect) sfSelect = new sfObject();    });    $('#stackedBar-ok').click(function() {        const checked = $('[name=stackedBar]:checked');        const field = [];        checked.each((i, x) => { field.push(x.value)});        compareObj.setStackedBarField(field);    });    $('#dp-stackedBar').click(function() {        const field = compareObj.stackedBarField;        const checked = $('[name=stackedBar]');        checked.each((i, x) => { x.checked = field.indexOf(x.value) >= 0; });    });    $('a[name=showType]').click(function () {        const type = this.getAttribute('tag');        compareObj.setCompareType(type);        SpreadJsObj.refreshColumnVisible(compareSheet);    });    $('a[name=stackedBarCover]').click(function() {        const cover = this.getAttribute('tag');        compareObj.setStackedBarCover(cover);    });    $('#dp-cover').click(function() {        const cover = compareObj.stackedBarCover;        const checked = $('a[name=stackedBarCover]');        checked.each((i, x) => {            if (x.getAttribute('tag') === cover) {                $('i', x).addClass('text-primary').removeClass('text-white');            } else {                $('i', x).removeClass('text-primary').addClass('text-white');            }        });    });    $('#row-view').on('show.bs.modal', function () {        const html = [], customDisplay = customColDisplay();        for (const cd of customDisplay) {            html.push('<tr>');            html.push('<td>', cd.title, '</td>');            html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');            html.push('</tr>');        }        $('#row-view-list').html(html.join(''));    });    $('#row-view-ok').click(function () {        const customDisplay = customColDisplay();        const cvl = $('#row-view-list').children();        for (const cv of cvl) {            const title = $(cv).children()[0].innerHTML;            const check = $('input', cv)[0].checked;            const cd = customDisplay.find(function (c) {                return c.title === title;            });            cd.visible = check;        }        customizeTreeSetting(spreadSetting, customDisplay);        compareObj.loadCacheData();        SpreadJsObj.refreshColumnVisible(compareSheet);        Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);        $('#row-view').modal('hide');    });    $('#compare-set').on('show.bs.modal', function() {        $('#compare1').val(compareObj.comparePhase1);        $('#compare2').val(compareObj.comparePhase2);        $('#compare-active-hint').html(compareObj.getCompareHint());    });    $('#compare1').change(() => {        const phase1 = $('#compare1').val();        const phase2 = $('#compare2').val();        $('#compare-active-hint').html(compareObj.getCompareHint(phase1, phase2));    });    $('#compare2').change(() => {        const phase1 = $('#compare1').val();        const phase2 = $('#compare2').val();        $('#compare-active-hint').html(compareObj.getCompareHint(phase1, phase2));    });    $('#compare-set-ok').click(() => {        compareObj.setComparePhase($('#compare1').val(), $('#compare2').val());    });    $('#export-excel').click(function() {        const excelSetting = JSON.parse(JSON.stringify(compareSheet.zh_setting));        const gridIndex = excelSetting.cols.findIndex(x => { return x.field === 'stackedBar'});        if (gridIndex >= 0) excelSetting.cols.splice(gridIndex, 1);        SpreadExcelObj.exportSimpleXlsxSheet(excelSetting, compareSheet.zh_tree.nodes, $('.sidebar-title').attr('data-original-title') + "-造价对比.xlsx");    });});
 |