'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, formatter: '@'}, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, formatter: '@'}, ], extraCols: [ {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty%s', hAlign: 2, width: 60, formatter: '@'}, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp%s', hAlign: 2, width: 60, formatter: '@'}, ], emptyRows: 3, headRows: 2, headRowHeight: [25, 25], headerFont: '12px 微软雅黑', font: '12px 微软雅黑', defaultRowHeight: 21, readOnly: true, }; 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: 'gather_qty%s', hAlign: 2, width: 60}, ], emptyRows: 3, headRows: 1, headRowHeight: [32], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', readOnly: true, }; function initSpreadSettingWithRoles(compareRoles) { function setSpreadSettingCols(setting, fieldSufs, Roles) { function addExtraCols(fieldSuf, Role) { for (const ec of setting.extraCols) { const col = JSON.parse(JSON.stringify(ec)); col.title = _.replace(col.title, '%s', Role); col.field = _.replace(col.field, '%s', fieldSuf); setting.cols.push(col); } } setting.cols = []; for (const col of setting.baseCols) { setting.cols.push(col); } 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); } function calculateStageLedgerData(datas) { for (const d of datas) { d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty); d.gather_tp = ZhCalc.add(d.contract_tp, d.qc_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); SpreadJsObj.initSheet(billsSheet, billsSpreadSetting); const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]); const posSheet = posSpread.getActiveSheet(); SpreadJsObj.initSheet(posSheet, posSpreadSetting); $.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 = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0; $(".sp-wrap").height(bcontent-30); posSpread.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: [], }); 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); }, null, true); function loadPosData(iRow) { const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet); if (node) { SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, cPos.getLedgerPos(node.id)); } else { SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, []); } SpreadJsObj.resetTopAndSelect(posSheet); } 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) { loadPosData(iNewRow); } } else { loadPosData(iNewRow); } } }); $('#select-qi-ok').click(function () { function refreshView () { const compareStages = []; 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(); } 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 + '', ['gather_qty', 'gather_tp'], ['gather_tp']); treeCalc.calculateAll(cTree); calculateStagePosData(aData.pos); cPos.loadMinorData(aData.pos, aData.order + '', ['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, $('h2')[0].innerHTML + "-多期比较.xlsx"); }); });