$(document).ready(function() { autoFlashHeight(); class BillsObj { constructor() { this.spread = SpreadJsObj.createNewSpread($('#bills-spread')[0]); this.sheet = this.spread.getActiveSheet(); this.treeSetting = { id: 'tree_id', pid: 'tree_pid', order: 'tree_order', level: 'tree_level', isLeaf: 'tree_is_leaf', fullPath: 'tree_full_path', rootId: -1, }; this.spreadSetting = { baseCols: [ {title: '编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 230, formatter: '@', cellType: 'tree'}, {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'}, {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 150, 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: 80, type: 'Number'}, ], extraCols: [ {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qty_{%d}', hAlign: 2, width: 80, type: 'Number', }, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'tp_{%d}', hAlign: 2, width: 80, type: 'Number', }, ], emptyRows: 3, headRows: 2, headRowHeight: [25, 25], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', readOnly: true, }; this.spreadSetting.getColor = function (sheet, data, row, col, defaultColor) { function checkDiffer(data) { const fieldSufs = sheet.zh_setting.fieldSufs; if (fieldSufs.length <= 1) return false; const base = data['qty_' + fieldSufs[0]]; for (let i = 1; i< fieldSufs.length; i++) { const compare = data['qty_' + fieldSufs[i]]; if ((base || compare) && (compare!== base)) return true; } } return checkDiffer(data) ? spreadColor.safe.differ : defaultColor; }; this.tree = createNewPathTree('ledger', this.treeSetting); this.ckBillsSpread = window.location.pathname + '-billsSelect'; this.initSpread(); } refreshSpreadSetting(roles) { this.spreadSetting.cols = []; this.spreadSetting.fieldSufs = []; for (const col of this.spreadSetting.baseCols) { this.spreadSetting.cols.push(col); } for (const role of roles) { this.spreadSetting.fieldSufs.push(role.order); for (const ec of this.spreadSetting.extraCols) { const col = JSON.parse(JSON.stringify(ec)); col.title = _.replace(col.title, '%s', role.name); col.field = _.replace(col.field, '{%d}', role.order); this.spreadSetting.cols.push(col); } } } initSpread(roles = []) { this.refreshSpreadSetting(roles); SpreadJsObj.initSheet(this.sheet, this.spreadSetting); } analysisCompareData(datas, roles){ const findHis = function (role, history) { let his = null; for (const h of history) { if (h.times < role.times || (h.times === role.times && h.order <= role.order)) { his = h; } else { break; } } return his; }; for (const d of datas) { if (!d.tree_is_leaf) continue; d.cur_his.sort((x, y) => { return x.times === y.times ? x.order - y.order : x.times - y.times; }); for (const r of roles) { if (r.latest) { d[`qty_${r.order}`] = d.cur_qty; d[`tp_${r.order}`] = d.cur_tp; } else { const rHis = findHis(r, d.cur_his); if (rHis) { d[`qty_${r.order}`] = rHis.qty; d[`tp_${r.order}`] = rHis.tp; } } } } } loadData(datas, roles) { this.initSpread(roles); this.analysisCompareData(datas, roles); this.tree.loadDatas(datas); this.tree.setting.calcFields = roles.map(x => { return `tp_${x.order}`}); treeCalc.calculateAll(this.tree); SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree); SpreadJsObj.loadTopAndSelect(this.sheet, this.ckBillsSpread); } } const billsObj = new BillsObj(); // 加载安全生产费数据 postData('load', { filter: 'billsCompare;auditFlow' }, function(result) { billsObj.loadData(result.billsCompare, result.auditFlow); }); // 导航Menu $.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(); billsObj.spread.refresh(); } }); // 显示层次 (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": tree.expandByLevel(parseInt(tag)); SpreadJsObj.refreshTreeRowVisible(sheet); break; case "last": tree.expandByCustom(() => { return true; }); SpreadJsObj.refreshTreeRowVisible(sheet); break; } closeWaitingView(); }, 100); }); })('a[name=showLevel]', billsObj.sheet); });