| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030 | 'use strict';/** * * * @author Mai * @date * @version */const showSideTools = function (show) {    const left = $('#left-view'), right = $('#right-view'), parent = left.parent();    if (show) {        right.show();        autoFlashHeight();        const percent = 100 - right.outerWidth() /parent.width() * 100;        left.css('width', percent + '%');    } else {        left.width(parent.width());        right.hide();    }};const setPriceHint = function (show) {    const hinticon = show ? 'fa-bell' : undefined;    subMiniMenu.$children[2].hinticon = hinticon;    subMenu.$children[2].hinticon = hinticon;};$(document).ready(() => {    const ledgerGclSpreadSetting = {        cols: [            { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@' },            { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 200, formatter: '@' },            { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@' },            { title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number' },        ],        emptyRows: 0,        headRows: 1,        headRowHeight: [32],        headColWidth: [30],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        readOnly: true,    };    const ledgerXmjSpreadSetting = {        cols: [            {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},            {title: '单位工程', colSpan: '1', rowSpan: '1', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},            {title: '分部工程', colSpan: '1', rowSpan: '1', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},            {title: '分项工程', colSpan: '1', rowSpan: '1', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},            {title: '细目', colSpan: '1', rowSpan: '1', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},            {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},        ],        emptyRows: 0,        headRows: 1,        headRowHeight: [32],        headColWidth: [30],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        readOnly: true,    };    const priceSpreadSetting = {        cols: [            { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 100, formatter: '@', readOnly: true },            { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 210, formatter: '@', readOnly: true },            { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true },            { title: '当前单价', colSpan: '1', rowSpan: '2', field: 'org_price', hAlign: 2, width: 80, type: 'Number', readOnly: true },            { title: '调整后单价', colSpan: '1', rowSpan: '2', field: 'new_price', hAlign: 2, width: 80, type: 'Number' },            { title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 2, width: 150, formatter: '@' },        ],        emptyRows: 0,        headRows: 1,        headRowHeight: [32],        headColWidth: [30],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        readOnly,        getColor: function (sheet, data, row, col, defaultColor) {            if (!data || (data.rela_lid && data.rela_cid)) return defaultColor;            const samePrice = sheet.zh_data.find(x => {                return x.b_code === data.b_code && x.name === data.name && x.unit === data.unit && x.org_price === data.org_price;            });            return samePrice ? '#f5deb3' : defaultColor;        }    };    const priceBwSpreadSetting = {        cols: [            {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},            {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},            {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},            {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},            {title: '原单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},        ],        headRows: 1,        emptyRows: 0,        headRowHeight: [25],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        readOnly: true,    };    sjsSettingObj.setFxTreeStyle(priceBwSpreadSetting, sjsSettingObj.FxTreeStyle.jz);    const priceChangeSpreadSetting = {        cols: [            {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},            {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},            {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 1, width: 80, formatter: '@'},        ],        headRows: 1,        emptyRows: 0,        headRowHeight: [25],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        readOnly: true,    };    autoFlashHeight();    const bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;    $(".sp-wrap").height(bcontent-30);    const priceSpread = SpreadJsObj.createNewSpread($('#price-spread')[0]);    const priceSheet = priceSpread.getActiveSheet();    const priceBwSpread = SpreadJsObj.createNewSpread($('#price-bw-spread')[0]);    const priceBwSheet = priceBwSpread.getActiveSheet();    const priceChangeSpread = SpreadJsObj.createNewSpread($('#price-change-spread')[0]);    const priceChangeSheet = priceChangeSpread.getActiveSheet();    SpreadJsObj.initSheet(priceSheet, priceSpreadSetting);    SpreadJsObj.initSheet(priceBwSheet, priceBwSpreadSetting);    SpreadJsObj.initSheet(priceChangeSheet, priceChangeSpreadSetting);    class RevisePrice {        constructor () {            this.data = [];            this.tree = createNewPathTree('filter', {                id: 'ledger_id',                pid: 'ledger_pid',                order: 'order',                level: 'level',                rootId: -1,                fullPath: 'full_path',                keys: ['id', 'tender_id', 'ledger_id'],            });        }        resortData() {            this.data.sort(function (a, b) {                return a.order - b.order;            });        }        loadDatas(datas, treeData, changeData) {            this.data = datas;            this.tree.loadDatas(treeData);            this.resortData();            this.change = changeData;            this.relaChange = [];            if (this.data.length > 0) this.refreshRela(this.data[0]);        }        loadUpdateData(updateData) {            if (updateData.add) {                for (const a of updateData.add) {                    this.data.push(a);                }            }            if (updateData.update) {                for (const u of updateData.update) {                    const d = this.data.find(function (x) {                        return u.id === x.id;                    });                    if (d) {                        _.assign(d, u);                    } else {                        this.data.push(d);                    }                }            }            if (updateData.del) {                _.remove(this.data, function (d) {                    return updateData.del.indexOf(d.id) >= 0;                });            }            this.resortData();        }        getSamePrice(price) {            return this.data.filter(x => {                if (x.id === price.id) return false;                return x.b_code === price.b_code && x.name === price.name && x.unit === price.unit && x.org_price === price.org_price;            });        }        refreshTreeRela(price, samePrice) {            if (!samePrice) samePrice = this.getSamePrice(price);            if (price.rela_lid) {                this.tree.loadFilter(price.rela_lid);            } else {                const invalid = [];                for (const sp of samePrice) {                    const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];                    invalid.push(...lid);                }                this.tree.loadFilter(invalid.join(','), 'filter');            }        }        refreshChangeRela(price, samePrice) {            if (!samePrice) samePrice = this.getSamePrice(price);            if (price.rela_cid) {                const choose = price.rela_cid.split(',');                for (const c of this.change) {                    c.rela = choose.indexOf(c.cid + '') >= 0;                    c.valid = c.rela;                }            } else {                const invalid = [];                for (const sp of samePrice) {                    const cid = sp.rela_cid ? sp.rela_cid.split(',') : [];                    invalid.push(...cid);                }                for (const c of this.change) {                    c.rela = invalid.indexOf(c.cid + '') >= 0;                    if (c.rela) {                        c.valid = 0;                    } else {                        const exist = c.bills.find(x => {                            return x.code === price.b_code && x.name === price.name && x.unit === price.unit && x.unit_price === price.org_price;                        });                        c.valid = exist;                    }                }            }            this.relaChange.length = 0;            for (const c of this.change) {                if (c.valid) this.relaChange.push(c);            }        }        refreshRela(price) {            const samePrice = this.getSamePrice(price);            this.refreshTreeRela(price, samePrice);            this.refreshChangeRela(price, samePrice);        }    }    const revisePrice = new RevisePrice();    const priceOprObj = {        addRevisePrice(data) {            const op = revisePrice.data.find(x => {                return x.b_code === data.b_code && x.name === x.name && x.unit === x.unit && checkZero(ZhCalc.sub(x.org_price, data.unit_price)) && (!x.rela_lid || !x.rela_cid);            });            if (op) {                toastr.warning('已存在该单价调整');                SpreadJsObj.locateData(priceSheet, op);                return;            }            postData(window.location.pathname + '/update', { add: { b_code: data.b_code, name: data.name, unit: data.unit, unit_price: data.unit_price } }, result => {                revisePrice.loadUpdateData(result);                SpreadJsObj.reLoadSheetData(priceSheet);                setPriceHint(revisePrice.data.length > 0);            });        },        /**         * 删除按钮响应事件         * @param sheet         */        deletePress: function (sheet) {            if (!sheet.zh_setting || readOnly) return;            const sortData = sheet.zh_data;            const datas = [];            const sels = sheet.getSelections();            if (!sels || !sels[0]) return;            for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {                let bDel = false;                const node = sortData[iRow];                if (node) {                    const data = {id: node.id};                    for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {                        const style = sheet.getStyle(iRow, iCol);                        if (!style.locked) {                            const colSetting = sheet.zh_setting.cols[iCol];                            data[colSetting.field] = null;                            bDel = true;                        }                    }                    if (bDel) {                        datas.push(data);                    }                }            }            if (datas.length > 0) {                postData(window.location.pathname + '/update', {update: datas}, function (result) {                    revisePrice.loadUpdateData(result);                    SpreadJsObj.reLoadSheetData(priceSheet);                }, function () {                    SpreadJsObj.reLoadSheetData(priceSheet);                });            }        },        delete: function (sheet) {            if (!sheet.zh_setting || readOnly) return;            const sortData = sheet.zh_data;            const datas = [];            const sels = sheet.getSelections();            if (!sels || !sels[0]) return;            for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {                const node = sortData[iRow];                datas.push(node.id);            }            if (datas.length > 0) {                postData(window.location.pathname + '/update', {del: datas}, function (result) {                    revisePrice.loadUpdateData(result);                    SpreadJsObj.reLoadSheetData(priceSheet);                    setPriceHint(revisePrice.data.length > 0);                }, function () {                    SpreadJsObj.reLoadSheetData(priceSheet);                });            }        },        editEnded: function (e, info) {            if (!info.sheet.zh_setting || !info.sheet.zh_data) return;            const node = info.sheet.zh_data[info.row];            if (!node) return;            const col = info.sheet.zh_setting.cols[info.col];            const data = { update: { id: node.id, org_price: node.org_price } };            const oldValue = node ? node[col.field] : null;            const newValue = trimInvalidChar(info.editingText);            if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {                SpreadJsObj.reLoadRowData(info.sheet, info.row);                return;            }            if (col.type === 'Number') {                const num = _.toNumber(newValue);                if (num) data.update[col.field] = num;            } else {                data.update[col.field] = newValue;            }            postData(window.location.pathname + '/update', data, function (result) {                revisePrice.loadUpdateData(result);                SpreadJsObj.reLoadSheetData(info.sheet);            }, function () {                SpreadJsObj.reLoadRowData(info.sheet, info.row);            });        },        clipboardPasting(e, info) {            const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;            info.cancel = true;            if (!setting || !sortData) return;            const pasteData = info.pasteData.html                ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)                : (info.pasteData.text === ''                    ? SpreadJsObj.Clipboard.getAnalysisPasteText()                    : SpreadJsObj.analysisPasteText(info.pasteData.text));            const uDatas = [];            for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {                const curRow = info.cellRange.row + iRow;                const node = sortData[curRow];                let bPaste = false;                const data = {};                for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {                    const curCol = info.cellRange.col + iCol;                    const colSetting = setting.cols[curCol];                    const value = trimInvalidChar(pasteData[iRow][iCol]);                    if (colSetting.type === 'Number') {                        const num = _.toNumber(value);                        if (num) {                            data[colSetting.field] = num;                            bPaste = true;                        }                    } else {                        data[colSetting.field] = value;                        bPaste = true;                    }                }                if (bPaste) {                    data.id = node.id;                    uDatas.push(data);                }            }            const updateData = {};            if (uDatas.length > 0) updateData.update = uDatas;            if (uDatas.length > 0) {                postData(window.location.pathname + '/update', updateData, function (result) {                    revisePrice.loadUpdateData(result);                    SpreadJsObj.reLoadSheetData(info.sheet);                });            } else {                SpreadJsObj.reLoadSheetData(info.sheet);            }        },        upMove: function () {            const sels = priceSheet.getSelections(), sortData = priceSheet.zh_data;            const node = sortData[sels[0].row];            const preNode = sortData[sels[0].row - 1];            const data = [                {id: node.id, order: preNode.order},                {id: preNode.id, order: node.order}            ];            postData(window.location.pathname + '/update', {update: data}, function (result) {                revisePrice.loadUpdateData(result);                SpreadJsObj.reLoadRowsData(priceSheet, [sels[0].row, sels[0].row - 1]);                priceSheet.setSelection(sels[0].row - 1, sels[0].col, sels[0].rowCount, sels[0].colCount);            });        },        downMove: function () {            const sels = priceSheet.getSelections(), sortData = priceSheet.zh_data;            const node = sortData[sels[0].row];            const nextNode = sortData[sels[0].row + 1];            const data = [                {id: node.id, order: nextNode.order},                {id: nextNode.id, order: node.order}            ];            postData(window.location.pathname + '/update', {update: data}, function (result) {                revisePrice.loadUpdateData(result);                SpreadJsObj.reLoadRowsData(priceSheet, [sels[0].row, sels[0].row + 1]);                priceSheet.setSelection(sels[0].row + 1, sels[0].col, sels[0].rowCount, sels[0].colCount);            });        },        updateRelaLid: function (price, rela_lid) {            const data = { update: { id: price.id, rela_lid } };            postData(window.location.pathname + '/update', data, function (result) {                revisePrice.loadUpdateData(result);                revisePrice.refreshTreeRela(price);                SpreadJsObj.refreshTreeRowVisible(priceBwSheet);                SpreadJsObj.reloadRowBackColor(priceSheet, revisePrice.data.indexOf(price));            });        },        updateRelaCid: function (price, rela_cid) {            const data = { update: { id: price.id, rela_cid } };            postData(window.location.pathname + '/update', data, function (result) {                revisePrice.loadUpdateData(result);                revisePrice.refreshChangeRela(price);                SpreadJsObj.reLoadSheetData(priceChangeSheet);                SpreadJsObj.reloadRowBackColor(priceSheet, revisePrice.data.indexOf(price));            });        },        selectionChanged: function () {            const price = SpreadJsObj.getSelectObject(priceSheet);            revisePrice.refreshRela(price);            SpreadJsObj.refreshTreeRowVisible(priceBwSheet);            SpreadJsObj.reLoadSheetData(priceChangeSheet);        },    };    if (!readOnly) {        priceSheet.bind(spreadNS.Events.EditEnded, priceOprObj.editEnded);        priceSheet.bind(spreadNS.Events.ClipboardPasting, priceOprObj.clipboardPasting);        SpreadJsObj.addDeleteBind(priceSpread, priceOprObj.deletePress);        $.contextMenu({            selector: '#price-spread',            build: function ($trigger, e) {                const target = SpreadJsObj.safeRightClickSelection($trigger, e, priceSpread);                return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;            },            items: {                del: {                    name: '删除',                    icon: 'fa-remove',                    callback: function (key, opt) {                        priceOprObj.delete(priceSheet);                    },                    disabled: function (key, opt) {                        const node = SpreadJsObj.getSelectObject(priceSheet);                        return node === undefined || node === null;                    },                    visible: function (key, opt) {                        return !readOnly;                    }                },                sprDel: '----',                upMove: {                    name: '上移',                    icon: 'fa-arrow-up',                    callback: function (key, opt) {                        priceOprObj.upMove();                    },                    disabled: function (key, opt) {                        const sels = priceSheet.getSelections();                        if (!sels || !sels[0] || sels[0].row === 0) return true;                        const row = sels[0].row;                        const node = revisePrice.data[row];                        return node === undefined || node === null;                    },                    visible: function (key, opt) {                        return !readOnly;                    }                },                downMove: {                    name: '下移',                    icon: 'fa-arrow-down',                    callback: function (key, opt) {                        priceOprObj.downMove();                    },                    disabled: function (key, opt) {                        const sels = priceSheet.getSelections();                        if (!sels || !sels[0] || sels[0].row >= revisePrice.data.length - 1) return true;                        const row = sels[0].row;                        const node = revisePrice.data[row];                        return node === undefined || node === null;                    },                    visible: function (key, opt) {                        return !readOnly;                    }                },                sprMove: '----',                chooseRelaBw: {                    name: '选择应用部位',                    icon: 'fa-link',                    callback: function (key, opt) {                        const price = SpreadJsObj.getSelectObject(priceSheet);                        const samePrice = revisePrice.getSamePrice(price);                        chooseRelaBw.show(price, samePrice);                    },                    disabled: function (key, opt) {                        const node = SpreadJsObj.getSelectObject(priceSheet);                        return !node;                    },                    visible: function (key, opt) {                        return !readOnly;                    }                },                noRelaBw: {                    name: '不应用于任何部位',                    icon: 'fa-unlink',                    callback: function (key, opt) {                        const price = SpreadJsObj.getSelectObject(priceSheet);                        priceOprObj.updateRelaLid(price, '-1');                    },                    disabled: function (key, opt) {                        const node = SpreadJsObj.getSelectObject(priceSheet);                        return !node;                    },                    visible: function (key, opt) {                        return !readOnly;                    }                },                chooseRelaChange: {                    name: '选择应用变更令',                    icon: 'fa-link',                    callback: function (key, opt) {                        const price = SpreadJsObj.getSelectObject(priceSheet);                        const samePrice = revisePrice.getSamePrice(price);                        chooseRelaChange.show(price, samePrice);                    },                    disabled: function (key, opt) {                        const node = SpreadJsObj.getSelectObject(priceSheet);                        return !node;                    },                    visible: function (key, opt) {                        return !readOnly;                    }                },                noRelaChange: {                    name: '不应用于变更令',                    icon: 'fa-unlink',                    callback: function (key, opt) {                        const price = SpreadJsObj.getSelectObject(priceSheet);                        priceOprObj.updateRelaCid(price, '-1');                    },                    disabled: function (key, opt) {                        const node = SpreadJsObj.getSelectObject(priceSheet);                        return !node;                    },                    visible: function (key, opt) {                        return !readOnly;                    }                },            },        });    }    priceSpread.bind(spreadNS.Events.SelectionChanged, priceOprObj.selectionChanged);    class LedgerGcl {        constructor(setting) {            this.setting = setting;            this.spread = SpreadJsObj.createNewSpread($(this.setting.selector)[0]);            this.sheet = this.spread.getActiveSheet();            SpreadJsObj.initSheet(this.sheet, this.setting.spreadSetting);            this.xmjSpread = SpreadJsObj.createNewSpread($(this.setting.xmjSelector)[0]);            this.xmjSheet = this.xmjSpread.getActiveSheet();            SpreadJsObj.initSheet(this.xmjSheet, this.setting.xmjSpreadSetting);            if (!readOnly) {                this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {                    const gcl = SpreadJsObj.getSelectObject(info.sheet);                    priceOprObj.addRevisePrice(gcl);                });            }            const self = this;            this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {                self.loadLeafXmj();            });        }        loadData(bills, pos) {            gclGatherModel.loadLedgerData(bills);            gclGatherModel.loadPosData(pos);            this.gcl = gclGatherModel.gatherGclData();            this.sheet && SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.gcl);            this.loadLeafXmj(0);        }        loadLeafXmj(iGclRow) {            const gcl = iGclRow ? this.gcl[iGclRow] : SpreadJsObj.getSelectObject(this.sheet);            SpreadJsObj.resetTopAndSelect(this.xmjSheet);            if (gcl) {                SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);            } else {                SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, []);            }        }    }    const ledgerGcl = new LedgerGcl({        selector: '#ledger-gcl-spread',        spreadSetting: ledgerGclSpreadSetting,        xmjSelector: '#ledger-xmj-spread',        xmjSpreadSetting: ledgerXmjSpreadSetting,    });    $.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();            priceSpread.refresh();            ledgerGcl.spread.refresh();            priceBwSpread.refresh();            priceChangeSpread.refresh();        }    });    $.divResizer({        select: '#revise-right-spr',        callback: function () {            priceSpread.refresh();            priceBwSpread.refresh();            priceChangeSpread.refresh();            ledgerGcl.spread.refresh();            ledgerGcl.xmjSpread.refresh();        }    });    $.divResizer({        select: '#gcl-spr',        callback: function () {            ledgerGcl.spread.refresh();            ledgerGcl.xmjSpread.refresh();        }    });    $.divResizer({        select: '#price-resize',        callback: function () {            priceSpread.refresh();            let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;            $(".sp-wrap").height(bcontent-30);            priceBwSpread.refresh();            priceChangeSpread.refresh();        }    });    class ChooseRelaBw {        constructor() {            const self = this;            this.tree = createNewPathTree('ledger', {                id: 'ledger_id',                pid: 'ledger_pid',                order: 'order',                level: 'level',                rootId: -1,                fullPath: 'full_path',                keys: ['id', 'tender_id', 'ledger_id'],            });            $('#choose-rela-bw').on('shown.bs.modal', function() {                self.initSpread();                SpreadJsObj.reloadColData(self.sheet, 0, 1);                SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.tree.nodes.length);            });            $('#choose-rela-bw-ok').click(function() {                const choose_lid = [];                self.tree.nodes.forEach(x => {                    if (x.check) choose_lid.push(x.ledger_id);                });                priceOprObj.updateRelaLid(self.price, choose_lid.join(','));                $('#choose-rela-bw').modal('hide');            });        }        get locate() {            return this._locate;        }        set locate(value) {            if (!this.searchResult || this.searchResult.length === 0) return;            this._locate = !value || value >= this.searchResult.length ? 0 : (value < 0 ? this.searchResult.length - 1 : value);            SpreadJsObj.locateTreeNode(this.sheet, this.searchResult[this._locate].ledger_id, true);        }        search(keyword) {            this.searchResult = [];            for (const node of this.tree.nodes) {                const code = node.code || '', name = node.name || '', b_code = node.b_code || '';                if (code.indexOf(keyword) >= 0 || b_code.indexOf(keyword) >= 0 || name.indexOf(keyword) >= 0) this.searchResult.push(node);            }            $('#rela-bw-search-result').html(`结果:${this.searchResult.length}`);            this.locate = 0;        }        initSpread() {            if (this.spread) return;            this.spread = SpreadJsObj.createNewSpread($('#rela-bw-spread')[0]);            this.sheet = this.spread.getActiveSheet();            const spreadSetting = {                cols: [                    {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', cellType: 'checkbox'},                    {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},                    {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},                    {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},                    {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},                    {title: '原单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},                ],                headRows: 1,                emptyRows: 0,                headRowHeight: [25],                defaultRowHeight: 21,                headerFont: '12px 微软雅黑',                font: '12px 微软雅黑',                readOnly: true,                getColor: function (sheet, data, row, col, defaultColor) {                    return data && data.invalid ? '#dddddd' : defaultColor;                }            };            sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);            SpreadJsObj.initSheet(this.sheet, spreadSetting);            const self = this;            this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {                function checkInvalid(node) {                    if (node.invalid) return 1;                    if (self.tree.checkParent(node, 'invalid')) return 2;                    if (self.tree.checkChildren(node, 'invalid')) return 3;                    return 0;                }                const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);                if (!sheet.zh_setting) return;                if (cellType instanceof spreadNS.CellTypes.CheckBox) {                    if (sheet.isEditing()) sheet.endEdit(true);                }                const col = sheet.zh_setting.cols[info.col];                if (col.field !== 'check') return;                const tree = sheet.zh_tree;                const node = SpreadJsObj.getSelectObject(sheet);                if (node.b_code) {                    toastr.warning('请选择部位');                    return;                }                if (!node.check) {                    const invalid = checkInvalid(node);                    const invalidHint = ['该部位已被选择,请勿重复选择', '该部位的父项已被选择,请勿选择', '该部位的子项已被选择,请勿在其子项中选择'];                    if (invalid) {                        toastr.warning(invalidHint[invalid-1]);                        return;                    }                    if (self.tree.checkParent(node)) {                        const rect = info.sheet.getCellRect(info.row, info.col);                        self.chooseConfirmPopover({                            x: rect.x + rect.width / 2 + 25,                            y: rect.y + rect.height / 2 + 3,                        }, '父项已勾选,继续将取消父项勾选。', function () {                            node.check = true;                            const parents = tree.getFullPathNodes(tree.getParent(node).full_path);                            const rows = [tree.nodes.indexOf(node)];                            for (const p of parents) {                                if (p.check) {                                    p.check = false;                                    rows.push(tree.nodes.indexOf(p));                                }                            }                            SpreadJsObj.reLoadRowsData(info.sheet, rows);                        });                    } else if (self.tree.checkChildren(node)) {                        const rect = info.sheet.getCellRect(info.row, info.col);                        self.chooseConfirmPopover({                            x: rect.x + rect.width / 2 + 25,                            y: rect.y + rect.height / 2 + 3,                        }, '子项已勾选,继续将取消子项勾选。', function () {                            node.check = true;                            const posterity = tree.getPosterity(node);                            const rows = [tree.nodes.indexOf(node)];                            for (const p of posterity) {                                if (p.check) {                                    rows.push(tree.nodes.indexOf(p));                                    p.check = false;                                }                            }                            SpreadJsObj.reLoadRowsData(info.sheet, rows);                        });                    } else {                        node.check = true;                        SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);                    }                } else {                    node.check = false;                    SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);                }            });            SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);            (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;                            case "leafXmj":                                tree.expandToLeafXmj();                                SpreadJsObj.refreshTreeRowVisible(sheet);                                break;                        }                        closeWaitingView();                    }, 100);                });            })('a[name=showLevel]', this.sheet);            $('#rela-bw-search-keyword').change(function () {                self.search(this.value);            });            $('#rela-bw-search-pre').click(function () {                self.locate = self.locate - 1;            });            $('#rela-bw-search-next').click(function () {                self.locate = self.locate + 1;            });        }        reBind(obj, eventName, fun) {            obj.unbind(eventName);            obj.bind(eventName, fun);        }        chooseConfirmPopover(pos, hint, okCallback) {            const confirmObj = $('#choose-confirm'), hintObj = $('#choose-confirm-hint');            const okObj = $('#choose-confirm-ok'), cancelObj = $('#choose-confirm-cancel');            this.reBind(cancelObj, 'click', function () {                confirmObj.hide();            });            this.reBind(okObj, 'click', function () {                okCallback();                confirmObj.hide();            });            hintObj.text(hint);            confirmObj.css("top", pos.y).css("left", pos.x).show();        }        loadTree(data) {            this.tree.loadDatas(data);        }        show(price, samePrice){            this.price = price;            this.choose = price.rela_lid ? price.rela_lid.split(',') : [];            this.invalid = [];            for (const sp of samePrice) {                const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];                this.invalid.push(...lid);            }            for (const node of this.tree.nodes) {                node.check = this.choose.indexOf(node.ledger_id + '') >= 0;                node.invalid = this.invalid.indexOf(node.ledger_id + '') >= 0;            }            $('#choose-rela-bw').modal('show');        }    }    const chooseRelaBw = new ChooseRelaBw();    class ChooseRelaChange {        constructor (){            const self = this;            $('#choose-rela-change').on('shown.bs.modal', function() {                self.initSpread();                SpreadJsObj.reloadColData(self.sheet, 0, 1);                SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.change.length);            });            $('#choose-rela-change-ok').click(function() {                const choose_cid = [];                self.change.forEach(x => {                    if (x.check) choose_cid.push(x.cid);                });                priceOprObj.updateRelaCid(self.price, choose_cid.join(','));                $('#choose-rela-change').modal('hide');            });        }        initSpread() {            if (this.spread) return;            this.spread = SpreadJsObj.createNewSpread($('#rela-change-spread')[0]);            this.sheet = this.spread.getActiveSheet();            const spreadSetting = {                cols: [                    {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@',  cellType: 'checkbox'},                    {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@'},                    {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},                    {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},                ],                headRows: 1,                emptyRows: 0,                headRowHeight: [25],                defaultRowHeight: 21,                headerFont: '12px 微软雅黑',                font: '12px 微软雅黑',                readOnly: true,                getColor: function (sheet, data, row, col, defaultColor) {                    return data && data.invalid ? '#dddddd' : defaultColor;                }            };            SpreadJsObj.initSheet(this.sheet, spreadSetting);            this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {                const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);                if (!sheet.zh_setting) return;                if (cellType instanceof spreadNS.CellTypes.CheckBox) {                    if (sheet.isEditing()) sheet.endEdit(true);                }                const col = sheet.zh_setting.cols[info.col];                if (col.field !== 'check') return;                const node = SpreadJsObj.getSelectObject(sheet);                if (!node.check) {                    if (node.invalid) return;                    node.check = true;                    SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);                } else {                    node.check = false;                    SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);                }            });            SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.change);        }        loadChange(data) {            this.change = data;        }        show(price, samePrice) {            this.price = price;            this.choose = price.rela_cid ? price.rela_cid.split(',') : [];            this.invalid = [];            for (const sp of samePrice) {                const cid = sp.rela_cid ? sp.rela_cid.split(',') : [];                this.invalid.push(...cid);            }            for (const c of this.change) {                c.check = this.choose.indexOf(c.cid + '') >= 0;                c.invalid = this.invalid.indexOf(c.cid + '') >= 0;                if (!c.check && !c.invalid) {                    const exist = c.bills.find(x => {                        return x.code === price.b_code && x.name === price.name && x.unit === price.unit && x.unit_price === price.org_price;                    });                    c.visible = !!exist;                }            }            if (this.sheet) SpreadJsObj.refreshTreeRowVisible(this.sheet);            $('#choose-rela-change').modal('show');        }    }    const chooseRelaChange = new ChooseRelaChange();    postData('load', { filter: 'bills;pos;price;change' }, result => {        revisePrice.loadDatas(result.price, result.bills, result.change);        SpreadJsObj.loadSheetData(priceSheet, SpreadJsObj.DataType.Data, revisePrice.data);        ledgerGcl.loadData(result.bills, result.pos);        chooseRelaBw.loadTree(result.bills);        chooseRelaChange.loadChange(result.change);        SpreadJsObj.loadSheetData(priceBwSheet, SpreadJsObj.DataType.Tree, revisePrice.tree);        SpreadJsObj.loadSheetData(priceChangeSheet, SpreadJsObj.DataType.Data, revisePrice.relaChange);        $("[content='#ledgerGcl']").click();    });    $('a', '#side-menu').bind('click', function (e) {        e.preventDefault();        const tab = $(this), tabPanel = $(tab.attr('content'));        // 展开工具栏、切换标签        if (!tab.hasClass('active')) {            $('a', '#side-menu').removeClass('active');            tab.addClass('active');            $('#right-view .tab-pane').removeClass('active');            tabPanel.addClass('active');            showSideTools(tab.hasClass('active'));            ledgerGcl.spread.refresh();            ledgerGcl.xmjSpread.refresh();        } else {// 收起工具栏            tab.removeClass('active');            tabPanel.removeClass('active');            showSideTools(tab.hasClass('active'));        }        priceSpread.refresh();        priceBwSpread.refresh();        priceChangeSpread.refresh();    });    $('a', '.bcontent-wrap').click(function() {        $('[name=priceRela]').removeClass('active');        $(this).addClass('active');        $('#priceRelaTab').children().removeClass('active');        $(this.getAttribute('href')).addClass('active');        priceBwSpread.refresh();        priceChangeSpread.refresh();    });});
 |