123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- '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', },
- ],
- 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: 60},
- ],
- extraCols: [
- {title: '%s数量', colSpan: '1', rowSpan: '1', field: '{%s}_qty{%d}', hAlign: 2, width: 60},
- ],
- emptyRows: 3,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- 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', },
- ],
- 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: 60, type: 'Number'},
- ],
- extraCols: [
- {title: '%s数量', colSpan: '1', rowSpan: '2', field: '{%s}_qty{%d}', hAlign: 2, width: 60},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- 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]);
- }
- }
- 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);
- }
- }
- }
- setSpreadSettingCols(billsSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(posSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(gclSpreadSetting, fieldSufs, roles);
- setSpreadSettingCols(leafXmjSpreadSetting, 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(() => {
- 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);
- $.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();
- }
- });
- 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: [],
- 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);
- 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);
- gclGatherData = gclGatherModel.gatherGclData();
- SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
- loadLeafXmjData(0);
- }, 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) {
- console.log(SpreadJsObj.getSelectObject(info.sheet));
- 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 () {
- 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);
- }
- }
- // 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);
- }
- 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) {
- 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']);
- treeCalc.calculateAll(cTree);
- calculateStagePosData(aData.pos);
- cPos.loadMinorData(aData.pos, aData.order + '', ['contract_qty', 'qc_qty', 'gather_qty']);
- }
- refreshView();
- $('#select-qi').modal('hide');
- }, null, true);
- } else {
- 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);
- $('#exportExcel').click(function () {
- const data = [];
- if (!billsSheet.zh_tree) return;
- for (const node of billsSheet.zh_tree.nodes) {
- data.push(node);
- const posRange = cPos.getLedgerPos(node.id);
- if (posRange && posRange.length > 0) {
- for (const pr of posRange) {
- data.push(pr);
- }
- }
- }
- SpreadExcelObj.exportSimpleXlsxSheet(billsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
- });
- $('[name=compare-data]').click(function () {
- initSpreadSettingWithRoles(compareStages);
- SpreadJsObj.reLoadSheetHeader(billsSheet);
- SpreadJsObj.reloadColData(billsSheet, billsSpreadSetting.baseCols.length, compareStages.length * billsSpreadSetting.extraCols.length);
- SpreadJsObj.reLoadSheetHeader(posSheet);
- SpreadJsObj.reloadColData(posSheet, posSpreadSetting.baseCols.length, compareStages.length * posSpreadSetting.extraCols.length);
- SpreadJsObj.reLoadSheetHeader(gclSheet);
- SpreadJsObj.reloadColData(gclSheet, gclSpreadSetting.baseCols.length, compareStages.length * gclSpreadSetting.extraCols.length);
- SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
- SpreadJsObj.reloadColData(leafXmjSheet, leafXmjSpreadSetting.baseCols.length, compareStages.length * leafXmjSpreadSetting.extraCols.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();
- });
- });
|