'use strict'; /** * * * @author Mai * @date * @version */ $(document).ready(() => { autoFlashHeight(); const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]); const billsSheet = billsSpread.getActiveSheet(); SpreadJsObj.initSheet(billsSheet, billsSpreadSetting); const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]); const posSheet = posSpread.getActiveSheet(); SpreadJsObj.initSheet(posSheet, posSpreadSetting); $.divResizer({ select: '#revise-resize', callback: function () { billsSpread.refresh(); let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0; $(".sp-wrap").height(bcontent-40); posSpread.refresh(); } }); let stdChapter, stdBills; $.divResizer({ select: '#revise-right-spr', callback: function () { billsSpread.refresh(); if (posSpread) { posSpread.refresh(); } if (stdChapter) { stdChapter.spread.refresh(); } if (stdBills) { stdBills.spread.refresh(); } } }); // 展开收起标准清单 $('a', '#side-menu').bind('click', function (e) { e.preventDefault(); const tab = $(this), tabPanel = $(tab.attr('content')); const showSideTools = function (show) { const left = $('#left-view'), right = $('#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(); } }; // 展开工具栏、切换标签 if (!tab.hasClass('active')) { const close = $('.active', '#side-menu').length === 0; $('a', '#side-menu').removeClass('active'); tab.addClass('active'); $('.tab-content .tab-pane').removeClass('active'); tabPanel.addClass('active'); showSideTools(tab.hasClass('active')); if (tab.attr('content') === '#std-chapter') { if (!stdChapter) { stdChapter = new stdLib($('#std-chapter-spread')[0], 'chapter', { id: 'chapter_id', pid: 'pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'list_id', 'chapter_id'], }, { cols: [ {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'}, {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true}, {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true} ], treeCol: 0, emptyRows: 0, headRows: 1, headRowHeight: [40], defaultRowHeight: 21, }); stdChapter.loadLib(1); } stdChapter.spread.refresh(); } else if (tab.attr('content') === '#std-bills') { if (!stdBills) { stdBills = new stdLib($('#std-bills-spread')[0], 'bills', { id: 'bill_id', pid: 'pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'list_id', 'bill_id'] }, { cols: [ {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'}, {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true}, {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true} ], treeCol: 0, emptyRows: 0, headRows: 1, headRowHeight: [40], defaultRowHeight: 21, }); stdBills.loadLib(1); } stdBills.spread.refresh(); } } billsSpread.refresh(); if (posSpread) { posSpread.refresh(); } }); class stdLib { constructor(obj, stdType, treeSetting, spreadSetting) { this.obj = obj; this.url = '/std/' + stdType; this.treeSetting = treeSetting; treeSetting.preUrl = this.url; this.spreadSetting = spreadSetting; this.spread = SpreadJsObj.createNewSpread(this.obj); SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting); this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) { const stdSheet = info.sheet; const mainSheet = ledgerSpread.getActiveSheet(); if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; } const stdTree = stdSheet.zh_tree; const stdNode = stdTree.nodes[info.row]; const mainTree = mainSheet.zh_tree; const sel = mainSheet.getSelections()[0]; const mainNode = mainTree.nodes[sel.row]; if (!stdNode) { return; } mainTree.postData('/tender/' + getTenderId() + '/ledger/add-by-std', mainNode, { tender_id: mainNode.tender_id, stdType: stdType, stdLibId: stdNode.list_id, stdNode: stdTree.getNodeKey(stdNode) }, function (result) { treeOperationObj.refreshTree(mainSheet, result); treeOperationObj.refreshOperationValid(mainSheet); }); }); this.pathTree = createNewPathTree('base', this.treeSetting); } loadLib (listId) { const self = this; postData(this.url+'/get-data', {list_id: listId}, function (data) { self.pathTree.loadDatas(data); SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree); }); } } // 修订详情 保存 $('#save').click(function () { const content = $('textarea').val(); postData('save', { content: content }); }); });