| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- $(document).ready(() => {
- autoFlashHeight();
- const ledgerGatherSpreadSetting = {
- cols: [
- {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 230, formatter: '@', cellType: 'tree'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@', cellType: 'autoTip'},
- ],
- baseCols: [
- {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 230, formatter: '@', cellType: 'tree'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@', cellType: 'autoTip'},
- ],
- extraCols: [
- {title: '%s|付款金额', colSpan: '4|1', rowSpan: '1|1', field: 'pay_tp', hAlign: 2, width: 80, type: 'Number'},
- {title: '|扣款金额', colSpan: '|1', rowSpan: '|1', field: 'cut_tp', hAlign: 2, width: 80, type: 'Number'},
- {title: '|应付金额', colSpan: '|1', rowSpan: '|1', field: 'yf_tp', hAlign: 2, width: 80, type: 'Number'},
- {title: '|实付金额', colSpan: '|1', rowSpan: '|1', field: 'sf_tp', hAlign: 2, width: 80, type: 'Number'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- sjsSettingObj.setFxTreeStyle(ledgerGatherSpreadSetting, sjsSettingObj.FxTreeStyle.phasePay);
- const ledgerGatherSpread = SpreadJsObj.createNewSpread($('#ledger-gather-spread')[0]);
- const ledgerGatherSheet = ledgerGatherSpread.getActiveSheet();
- SpreadJsObj.initSheet(ledgerGatherSheet, ledgerGatherSpreadSetting);
- const ledgerGatherObj = {
- tree: createNewPathTree('ledger', {
- id: 'tree_id', pid: 'tree_pid', order: 'tree_order',
- level: 'tree_level', isLeaf: 'tree_is_leaf', fullPath: 'tree_full_path',
- rootId: -1, calcFields: [],
- }),
- stages: [],
- splitStages (gatherType, gatherStageIds) {
- const gatherStages = this.stages.filter(x => { return gatherStageIds.indexOf(x.id) >= 0; });
- gatherStages.sort((a, b) => { return a.stage_order - b.stage_order; });
- const result = { main: gatherStages[gatherStages.length - 1], gatherPart: [] };
- for (const gs of gatherStages) {
- if (gatherType === 'stage') {
- result.gatherPart.push({title: `第${gs.stage_order}期(${gs.stage_date})`, stages: [gs]});
- } else {
- let title;
- if (gatherType === 'month') title = `${gs.stage_date}`;
- if (gatherType === 'quarter') title = `${gs.gather_year} 第${gs.gather_quarter}季度`;
- if (gatherType === 'year') title = `${gs.gather_year}`;
- let gp = result.gatherPart.find(x => { return x.title === title; });
- if (!gp) {
- gp = { title, stages: [] };
- result.gatherPart.push(gp);
- }
- gp.stages.push(gs);
- }
- }
- return result;
- },
- gather (gatherType, gatherStageIds) {
- if (gatherStageIds.length === 0) return;
- const gatherInfo = this.splitStages(gatherType, gatherStageIds);
- this.tree.setting.calcFields.length = 0;
- this.tree.loadDatas(gatherInfo.main.detail.bills);
- ledgerGatherSpreadSetting.cols.length = 0;
- ledgerGatherSpreadSetting.cols.push(...ledgerGatherSpreadSetting.baseCols);
- for (const [i, gp] of gatherInfo.gatherPart.entries()) {
- const loadFields = [];
- for (const ec of ledgerGatherSpreadSetting.extraCols) {
- const col = JSON.parse(JSON.stringify(ec));
- col.title = col.title.replace('%s', gp.title);
- loadFields.push({ sf: col.field, tf: col.field + '_' + i});
- col.field = col.field + '_' + i;
- ledgerGatherSpreadSetting.cols.push(col);
- this.tree.setting.calcFields.push(col.field);
- this.tree.nodes.forEach(x => { x[col.field] = 0; });
- }
- for (const s of gp.stages) {
- for (const b of s.detail.bills) {
- const node = this.tree.nodes.find(x => { return x.cost_id === b.cost_id; });
- if (!node) continue;
- for (const lf of loadFields) {
- node[lf.tf] = ZhCalc.add(node[lf.tf], b[lf.sf]);
- }
- }
- }
- }
- treeCalc.calculateAll(this.tree);
- SpreadJsObj.initSheet(ledgerGatherSheet, ledgerGatherSpreadSetting);
- SpreadJsObj.loadSheetData(ledgerGatherSheet, SpreadJsObj.DataType.Tree, this.tree);
- SpreadJsObj.locateRow(ledgerGatherSheet, 0);
- },
- loadStages (stages) {
- for (const s of stages) {
- s.gather_stage = s.stage_order;
- s.gather_month = s.stage_date;
- s.gather_time = moment(new Date(s.stage_date));
- s.gather_quarter = s.gather_time.quarter();
- s.gather_year = s.gather_time.year();
- this.stages.push(s);
- }
- },
- exportExcel() {
- if (!this.tree || this.tree.nodes.length === 0) {
- toastr.warning('无可导出数据');
- return;
- }
- SpreadExcelObj.exportSimpleXlsxSheet(ledgerGatherSpreadSetting, this.tree.nodes, "成本管理-汇总分析.xlsx");
- }
- };
- $('#select-qi-all').click(function() {
- const check = this.checked;
- $('input', 'tr[stage-id]').each((i, x) => {
- x.checked = check;
- })
- });
- $('#select-qi-ok').click(function() {
- let loadData = [], gatherData = [], 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) {
- const sid = tr.getAttribute('stage-id');
- const exist = ledgerGatherObj.stages.find(x => { return x.id === sid; });
- if (!exist) loadData.push(sid);
- gatherData.push(sid);
- }
- }
- const gatherType = $('input[name=gather-type]:checked').val();
- if (loadData.length > 0) {
- postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
- ledgerGatherObj.loadStages(result.stages);
- ledgerGatherObj.gather(gatherType, gatherData);
- $('#select-qi').modal('hide');
- }, null, true);
- } else {
- ledgerGatherObj.gather(gatherType, gatherData);
- $('#select-qi').modal('hide');
- }
- });
- $('#export-excel').click(function() {
- ledgerGatherObj.exportExcel();
- });
- // 显示层次
- (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":
- tree.expandByLevel(parseInt(tag));
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "last":
- tree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- }
- });
- })('a[name=showLevel]', ledgerGatherSheet);
- $.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');
- $('.c-body table thead').css('left', '56px');
- } else {
- $('.panel-title').removeClass('fluid');
- $('#sub-menu').addClass('panel-sidebar');
- $('.c-body table thead').css('left', '176px');
- }
- autoFlashHeight();
- ledgerGatherSpread.refresh();
- }
- });
- });
|