123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790 |
- 'use strict';
- /**
- * 多期比较
- *
- * @author Mai
- * @date
- * @version
- */
- const billsSpreadSetting = {
- baseCols: [
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {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: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number', },
- ],
- extraCols: [
- {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
- ],
- specExtraCols: [
- {title: '合计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sum_{%s}_qty', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sum_{%s}_tp', hAlign: 2, width: 60, type: 'Number', },
- ],
- emptyRows: 3,
- headRows: 2,
- headRowHeight: [25, 25],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- defaultRowHeight: 21,
- readOnly: true,
- selectedBackColor: '#fffacd',
- };
- const posSpreadSetting = {
- baseCols: [
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
- {title: '台账数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
- ],
- extraCols: [
- {title: '%s\n数量', colSpan: '1', rowSpan: '1', field: '{%s}_qty{%d}', hAlign: 2, width: 80, type: 'Number'},
- ],
- specExtraCols: [
- {title: '合计数量', colSpan: '1', rowSpan: '1', field: 'sum_{%s}_qty', hAlign: 2, width: 80, type: 'Number', },
- ],
- emptyRows: 3,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- selectedBackColor: '#fffacd',
- };
- const exportBillsSpreadSetting = {
- baseCols: [
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {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: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number', },
- ],
- extraCols: [
- {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
- ],
- specExtraCols: [
- {title: '合计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sum_{%s}_qty', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sum_{%s}_tp', hAlign: 2, width: 60, type: 'Number', },
- ],
- endCols: [],
- emptyRows: 3,
- headRows: 2,
- headRowHeight: [25, 25],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- defaultRowHeight: 21,
- readOnly: true,
- selectedBackColor: '#fffacd',
- };
- const gclSpreadSetting = {
- baseCols: [
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
- ],
- extraCols: [
- {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
- ],
- specExtraCols: [
- {title: '合计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sum_{%s}_qty', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sum_{%s}_tp', hAlign: 2, width: 60, type: 'Number', },
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- const leafXmjSpreadSetting = {
- baseCols: [
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
- {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
- {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
- {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '台账数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
- ],
- extraCols: [
- {title: '%s\n数量', colSpan: '1', rowSpan: '2', field: '{%s}_qty{%d}', hAlign: 2, width: 80},
- ],
- specExtraCols: [
- {title: '合计数量', colSpan: '1', rowSpan: '2', field: 'sum_{%s}_qty', hAlign: 2, width: 80, type: 'Number', },
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- const exportGclSpreadSetting = {
- baseCols: [
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
- {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
- {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
- ],
- extraCols: [
- {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
- ],
- specExtraCols: [
- {title: '合计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sum_{%s}_qty', hAlign: 2, width: 60, type: 'Number', },
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sum_{%s}_tp', hAlign: 2, width: 60, type: 'Number', },
- ],
- endCols: [
- {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- const chapterSpreadSetting = {
- baseCols: [
- {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: 'deal_bills_tp', hAlign: 2, width: 80, type: 'Number'},
- {title: '台账金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
- ],
- extraCols: [
- {title: '%s\n金额', colSpan: '1', rowSpan: '1', field: '{%s}_tp{%d}', hAlign: 2, width: 100, type: 'Number', },
- ],
- specExtraCols: [
- {title: '合计金额', colSpan: '1', rowSpan: '1', field: 'sum_{%s}_tp', hAlign: 2, width: 80, type: 'Number', },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [38],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- function initSpreadSettingWithRoles(compareRoles) {
- function setSpreadSettingCols(setting, fieldSufs, Roles) {
- function addExtraCols(fieldSuf, Role) {
- const sourceType = $('[name=compare-data]:checked').val();
- for (const ec of setting.extraCols) {
- const col = JSON.parse(JSON.stringify(ec));
- col.title = _.replace(col.title, '%s', Role);
- col.field = _.replace(_.replace(col.field, '{%s}', sourceType), '{%d}', fieldSuf);
- setting.cols.push(col);
- }
- }
- setting.cols = [];
- for (const col of setting.baseCols) {
- setting.cols.push(col);
- }
- setting.frozenColCount = setting.baseCols.length;
- setting.frozenLineColor = '#93b5e4';
- for (const index in fieldSufs) {
- addExtraCols(fieldSufs[index], Roles[index]);
- }
- if (setting.specExtraCols) {
- const sourceType = $('[name=compare-data]:checked').val();
- for (const col of setting.specExtraCols) {
- const eCol = JSON.parse(JSON.stringify(col));
- eCol.field = _.replace(eCol.field, '{%s}', sourceType);
- setting.cols.push(eCol);
- }
- }
- if (setting.endCols) {
- for (const col of setting.endCols) {
- setting.cols.push(col);
- }
- }
- }
- const fieldSufs = [], roles = [], trs = $('tr[stage-id]');
- for (let r of compareRoles) {
- if (r > 0) {
- const tr = trs[r-1];
- if (tr) {
- fieldSufs.push(r + '');
- roles.push(`${tr.children[0].textContent}(${tr.children[1].textContent})`);
- }
- }
- }
- setSpreadSettingCols(billsSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(posSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(exportBillsSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(gclSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(leafXmjSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(exportGclSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(chapterSpreadSetting, fieldSufs, roles);
- }
- function calculateStageLedgerData(datas) {
- for (const d of datas) {
- d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
- d.gather_tp = ZhCalc.sum([d.contract_tp, d.qc_tp, d.pc_tp]);
- // d.pc_tp = ZhCalc.add(d.qc_tp, d.qc_pc_tp);
- // d.contract_tp = ZhCalc.add(d.contract_tp, d.contract_pc_tp);
- }
- }
- function calculateStagePosData(datas) {
- for (const d of datas) {
- d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
- }
- }
- $(document).ready(() => {
- let spec, ledgerSearch, gclSearch;
- autoFlashHeight();
- initSpreadSettingWithRoles([]);
- const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
- const billsSheet = billsSpread.getActiveSheet();
- sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
- SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
- const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
- const posSheet = posSpread.getActiveSheet();
- if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
- SpreadJsObj.initSheet(posSheet, posSpreadSetting);
- let gclGatherData;
- const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
- const gclSheet = gclSpread.getActiveSheet();
- sjsSettingObj.setFxTreeStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(gclSpreadSetting);
- SpreadJsObj.initSheet(gclSheet, gclSpreadSetting);
- const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
- const leafXmjSheet = leafXmjSpread.getActiveSheet();
- if (thousandth) sjsSettingObj.setTpThousandthFormat(leafXmjSpreadSetting);
- SpreadJsObj.initSheet(leafXmjSheet, leafXmjSpreadSetting);
- const chapterSpread = SpreadJsObj.createNewSpread($('#chapter-spread')[0]);
- const chapterSheet = chapterSpread.getActiveSheet();
- sjsSettingObj.setGridSelectStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(chapterSpreadSetting);
- SpreadJsObj.initSheet(chapterSheet, chapterSpreadSetting);
- $.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();
- billsSpread.refresh();
- posSpread.refresh();
- }
- });
- // 上下窗口resizer
- $.divResizer({
- select: '#main-resize',
- callback: function () {
- billsSpread.refresh();
- let bcontent = $("#main-bottom").length > 0 ? $("#main-bottom").height() : 0;
- $("#pos-spread").height(bcontent-30);
- posSpread.refresh();
- }
- });
- $.divResizer({
- select: '#gcl-resize',
- callback: function () {
- gclSpread.refresh();
- let bcontent = $("#leafxmj-bottom").length > 0 ? $("#leafxmj-bottom").height() : 0;
- $("#leaf-xmj-spread").height(bcontent-30);
- leafXmjSpread.refresh();
- }
- });
- // 工具栏resizer
- $.divResizer({
- select: '#tz-right-spr',
- callback: function () {
- billsSpread.refresh();
- posSpread.refresh();
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- if (ledgerSearch) ledgerSearch.spread.refresh();
- }
- });
- $.divResizer({
- select: '#gcl-right-spr',
- callback: function () {
- gclSpread.refresh();
- leafXmjSpread.refresh();
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- if (gclSearch) gclSearch.spread.refresh();
- }
- });
- const cTree = createNewPathTree('master', {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tender_id', 'ledger_id'],
- masterId: 'id',
- minorId: 'lid',
- calcFields: ['total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'],
- markFoldKey: 'bills-fold',
- markFoldSubKey: window.location.pathname.split('/')[2],
- });
- const cPos = new MasterPosData({
- id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
- calcFun: function (pos) {
- pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
- }
- });
- postData(window.location.pathname + '/load', {main: true}, function (result) {
- cTree.loadDatas(result.main.ledger);
- treeCalc.calculateAll(cTree);
- cPos.loadDatas(result.main.pos);
- SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
- loadPosData(0);
- const checkField = function (x) {
- if (x === 'quantity') return true;
- if (x === 'total_price') return true;
- if (x.indexOf('_qty') >= 0) return true;
- if (x.indexOf('_tp') >= 0) return true;
- return false;
- };
- gclGatherModel.loadGatherField(checkField, checkField);
- gclGatherModel.loadLedgerData(result.main.ledger);
- gclGatherModel.loadPosData(result.main.pos);
- gclGatherModel.loadDealBillsData(result.main.deal);
- gclGatherData = gclGatherModel.gatherGclData();
- SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
- loadLeafXmjData(0);
- spec = result.spec;
- const chapterData = gclGatherModel.gatherChapterData(chapter, spec, ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp']);
- SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
- }, null, true);
- function loadPosData(iRow) {
- const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
- const posRange = node ? (cPos.getLedgerPos(node.id) || []) : [];
- SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, posRange);
- SpreadJsObj.resetTopAndSelect(posSheet);
- }
- function loadLeafXmjData(iRow) {
- const gcl = iRow ? gclSheet.zh_data[iRow] : SpreadJsObj.getSelectObject(gclSheet);
- if (gcl) {
- SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
- } else {
- SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
- }
- SpreadJsObj.resetTopAndSelect(leafXmjSheet);
- }
- billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- if (info.newSelections) {
- const iNewRow = info.newSelections[0].row;
- if (info.oldSelections) {
- const iOldRow = info.oldSelections[0].row;
- if (iNewRow !== iOldRow) {
- SpreadJsObj.resetTopAndSelect(posSheet);
- loadPosData(iNewRow);
- }
- } else {
- SpreadJsObj.resetTopAndSelect(leafXmjSheet);
- loadPosData(iNewRow);
- }
- }
- });
- gclSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- if (info.newSelections) {
- const iNewRow = info.newSelections[0].row;
- if (info.oldSelections) {
- const iOldRow = info.oldSelections[0].row;
- if (iNewRow !== iOldRow) {
- SpreadJsObj.resetTopAndSelect(leafXmjSheet);
- loadLeafXmjData(iNewRow);
- }
- } else {
- SpreadJsObj.resetTopAndSelect(leafXmjSheet);
- loadLeafXmjData(iNewRow);
- }
- }
- });
- const compareStages = [];
- $('#select-qi-ok').click(function () {
- function refreshView () {
- const gatherField = ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'];
- compareStages.length = 0;
- for (let order = 0, iLength = trs.length; order < iLength; order++) {
- const tr = trs[order];
- if ($('input', tr)[0].checked) {
- compareStages.push(order + 1);
- gatherField.push(`contract_tp${order + 1}`, `qc_tp${order + 1}`, `gather_tp${order + 1}`);
- }
- }
- // setLocalCache(cCacheKey, compareStages.join(','));
- initSpreadSettingWithRoles(compareStages);
- SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
- treeCalc.calculateAll(cTree);
- SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
- SpreadJsObj.initSheet(posSheet, posSpreadSetting);
- loadPosData();
- SpreadJsObj.reLoadSheetHeader(gclSheet);
- SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
- gclGatherModel.loadLedgerData(cTree.datas);
- gclGatherModel.loadPosData(cPos.datas);
- gclGatherData = gclGatherModel.gatherGclData();
- SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
- loadLeafXmjData(0);
- const chapterData = gclGatherModel.gatherChapterData(chapter, spec, gatherField);
- SpreadJsObj.reLoadSheetHeader(chapterSheet);
- SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
- }
- let loadData = [], showData = [], trs = $('tr[stage-id]');
- for (let order = 0, iLength = trs.length; order < iLength; order++) {
- const tr = trs[order];
- if ($('input[type=checkbox]', tr)[0].checked) {
- if (!cTree.minorData[order + 1]) {
- loadData.push(order + 1);
- }
- showData.push(order + 1);
- }
- }
- if (loadData.length > 0) {
- postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
- spec = result.spec;
- for (const aData of result.stages) {
- calculateStageLedgerData(aData.bills);
- cTree.loadMinorData(aData.bills, aData.order + '', ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], ['contract_tp', 'qc_tp', 'gather_tp']);
- calculateStagePosData(aData.pos);
- cPos.loadMinorData(aData.pos, aData.order + '', ['contract_qty', 'qc_qty', 'gather_qty']);
- }
- cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
- treeCalc.calculateAll(cTree);
- cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
- refreshView();
- $('#select-qi').modal('hide');
- }, null, true);
- } else {
- cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
- treeCalc.calculateAll(cTree);
- cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
- refreshView();
- $('#select-qi').modal('hide');
- }
- });
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- 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;
- }
- });
- })('a[name=showLevel]', billsSheet);
- // 展开收起工具栏
- const showTzSideTools = function (show) {
- const left = $('#tz-left-view'), right = $('#tz-right-view'), parent = left.parent();
- if (show) {
- right.show();
- autoFlashHeight();
- /**
- * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
- * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
- * 故需要通过最终的parent.width再计算一次left.width
- *
- * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
- * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
- *
- */
- //left.css('width', parent.width() - right.outerWidth());
- //left.css('width', parent.width() - right.outerWidth());
- const percent = 100 - right.outerWidth() /parent.width() * 100;
- left.css('width', percent + '%');
- } else {
- left.width(parent.width());
- right.hide();
- }
- };
- const showGclSideTools = function (show) {
- const left = $('#gcl-left-view'), right = $('#gcl-right-view'), parent = left.parent();
- if (show) {
- right.show();
- autoFlashHeight();
- /**
- * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
- * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
- * 故需要通过最终的parent.width再计算一次left.width
- *
- * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
- * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
- *
- */
- //left.css('width', parent.width() - right.outerWidth());
- //left.css('width', parent.width() - right.outerWidth());
- const percent = 100 - right.outerWidth() /parent.width() * 100;
- left.css('width', percent + '%');
- } else {
- left.width(parent.width());
- right.hide();
- }
- };
- $('a', '#tz-side-menu').bind('click', function (e) {
- e.preventDefault();
- const tab = $(this), tabPanel = $(tab.attr('content'));
- // 展开工具栏、切换标签
- if (!tab.hasClass('active')) {
- // const close = $('.active', '#side-menu').length === 0;
- $('a', '#tz-side-menu').removeClass('active');
- $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- // $('.tab-content .tab-pane').removeClass('active');
- showTzSideTools(tab.hasClass('active'));
- if (tab.attr('content') === '#tz-search') {
- if (!ledgerSearch) {
- ledgerSearch = $.ledgerSearch({
- selector: '#tz-search',
- ledger: { billsTree: cTree, pos: cPos },
- resultSpreadSetting: {
- cols: [
- {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
- {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- },
- locate: function(cur) {
- if (!cur.lid) return;
- SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
- loadPosData();
- if (cur.pid && cur.pid !== -1) {
- const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
- SpreadJsObj.locateRow(posSheet, pIndex);
- }
- },
- });
- }
- ledgerSearch.spread.refresh();
- }
- } else { // 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showTzSideTools(tab.hasClass('active'));
- }
- billsSpread.refresh();
- posSpread.refresh();
- });
- $('a', '#gcl-side-menu').bind('click', function (e) {
- e.preventDefault();
- const tab = $(this), tabPanel = $(tab.attr('content'));
- // 展开工具栏、切换标签
- if (!tab.hasClass('active')) {
- // const close = $('.active', '#side-menu').length === 0;
- $('a', '#gcl-side-menu').removeClass('active');
- $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- // $('.tab-content .tab-pane').removeClass('active');
- showGclSideTools(tab.hasClass('active'));
- if (tab.attr('content') === '#gcl-search') {
- if (!gclSearch) {
- gclSearch = $.gclSearch({
- selector: '#gcl-search',
- gcl: { bills: gclGatherData, getBillsXmj: function(node){ return node.leafXmjs; } },
- searchField: { bills: ['b_code', 'name'], xmj: ['code', 'dwgc', 'fbgc', 'fxgc', 'jldy', 'bwmx'], },
- resultSpreadSetting: {
- cols: [
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '项目节编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 120, hAlign: 0, formatter: '@'},
- {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
- {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- },
- locate: function(cur) {
- if (!cur.bid) return;
- const bIndex = gclSheet.zh_data.findIndex(x => { return x.id === cur.bid; });
- SpreadJsObj.locateRow(gclSheet, bIndex);
- loadLeafXmjData();
- if (cur.xid && cur.xid !== -1) {
- const xIndex = leafXmjSheet.zh_data.findIndex(x => { return x.id === cur.xid; });
- SpreadJsObj.locateRow(leafXmjSheet, xIndex);
- }
- },
- });
- }
- gclSearch.spread.refresh();
- }
- } else { // 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showGclSideTools(tab.hasClass('active'));
- }
- gclSpread.refresh();
- leafXmjSpread.refresh();
- });
- $('#exportExcel').click(function () {
- const exportLedger = function () {
- const data = [], groupData = [];
- if (!billsSheet.zh_tree) return;
- billsSheet.zh_tree.recursiveExe(function(node) {
- if (node.children && node.children.length > 0) {
- node._export_group = _.sum(node.children.map(x => { return x._export_group; })) + node.children.length;
- } else {
- const posRange = cPos.getLedgerPos(node.id);
- node._export_group = posRange ? posRange.length : 0;
- }
- });
- for (const node of billsSheet.zh_tree.nodes) {
- data.push(node);
- const posRange = cPos.getLedgerPos(node.id);
- if (posRange && posRange.length > 0) {
- if (node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
- for (const pr of posRange) {
- data.push(pr);
- }
- }
- }
- SpreadExcelObj.exportSimpleXlsxSheet(exportBillsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx", groupData);
- };
- const exportGcl = function () {
- const data = [];
- if (!gclSheet.zh_data) return;
- for (const node of gclSheet.zh_data) {
- data.push(node);
- for (const leafXmj of node.leafXmjs) {
- data.push(leafXmj);
- }
- }
- SpreadExcelObj.exportSimpleXlsxSheet(exportGclSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
- };
- const exportChapter = function () {
- SpreadExcelObj.exportSimpleXlsxSheet(chapterSpreadSetting, chapterSheet.zh_data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
- };
- const cur = $('.active[name=compareType]').attr('href');
- if (cur.indexOf('gcl') >= 0) {
- exportGcl();
- } else if (cur.indexOf('chapter') >= 0) {
- exportChapter();
- } else {
- exportLedger();
- }
- });
- $('[name=compare-data]').click(function () {
- initSpreadSettingWithRoles(compareStages);
- SpreadJsObj.reLoadSheetHeader(billsSheet);
- SpreadJsObj.reloadColData(billsSheet, billsSpreadSetting.baseCols.length, compareStages.length * billsSpreadSetting.extraCols.length + billsSpreadSetting.specExtraCols.length);
- SpreadJsObj.reLoadSheetHeader(posSheet);
- SpreadJsObj.reloadColData(posSheet, posSpreadSetting.baseCols.length, compareStages.length * posSpreadSetting.extraCols.length + posSpreadSetting.specExtraCols.length);
- SpreadJsObj.reLoadSheetHeader(gclSheet);
- SpreadJsObj.reloadColData(gclSheet, gclSpreadSetting.baseCols.length, compareStages.length * gclSpreadSetting.extraCols.length + gclSpreadSetting.specExtraCols.length);
- SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
- SpreadJsObj.reloadColData(leafXmjSheet, leafXmjSpreadSetting.baseCols.length, compareStages.length * leafXmjSpreadSetting.extraCols.length + leafXmjSpreadSetting.specExtraCols.length);
- SpreadJsObj.reLoadSheetHeader(chapterSheet);
- SpreadJsObj.reloadColData(chapterSheet, chapterSpreadSetting.baseCols.length, compareStages.length * chapterSpreadSetting.extraCols.length + chapterSpreadSetting.specExtraCols.length);
- });
- $('[name=compareType]').click(function () {
- $('[name=compareType]').removeClass('active');
- $(this).addClass('active');
- $('#compareType').children().removeClass('active');
- $(this.getAttribute('href')).addClass('active');
- billsSpread.refresh();
- posSpread.refresh();
- gclSpread.refresh();
- leafXmjSpread.refresh();
- chapterSpread.refresh();
- });
- $('#select-qi-all').click(function() {
- const check = this.checked;
- $('input', 'tr[stage-id]').each((i, x) => {
- x.checked = check;
- })
- });
- });
|