'use strict'; /** * * * @author Mai * @date * @version */ const ckBillsSpread = window.location.pathname + '-billsSelect'; $(document).ready(() => { autoFlashHeight(); let reviseAtt; // 初始化spread const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]); const billsSheet = billsSpread.getActiveSheet(); sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz); if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting); sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]); SpreadJsObj.initSheet(billsSheet, billsSpreadSetting); const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]); const posSheet = posSpread.getActiveSheet(); sjsSettingObj.setGridSelectStyle(posSpreadSetting); if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting); SpreadJsObj.initSheet(posSheet, posSpreadSetting); const posSearch = isTz ? $.posSearch({selector: '#pos-search', searchSpread: posSpread}) : null; $.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(); if (isTz) posSpread.refresh(); } }); // 初始化 清单树结构 const treeSetting = { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'tender_id', 'ledger_id'], calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'], autoExpand: 3, }; if (!isTz) { treeSetting.calcFields.push('deal_tp'); } treeSetting.calcFun = function (node) { node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2); }; const billsTree = createNewPathTree('revise', treeSetting); // 初始化 部位明细 const pos = new PosData({ id: 'id', ledgerId: 'lid' }); const billsTreeSpreadObj = { /** * * @param sheet * @param data */ refreshTree: function (sheet, data) { SpreadJsObj.massOperationSheet(sheet, function () { const tree = sheet.zh_tree; // 处理删除 if (data.delete) { data.delete.sort(function (a, b) { return b.deleteIndex - a.deleteIndex; }); for (const d of data.delete) { sheet.deleteRows(d.deleteIndex, 1); } } // 处理新增 if (data.create) { const newNodes = data.create; if (newNodes) { newNodes.sort(function (a, b) { return a.index - b.index; }); for (const node of newNodes) { sheet.addRows(node.index, 1); SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1); } } } // 处理更新 if (data.update) { const rows = []; for (const u of data.update) { rows.push(tree.nodes.indexOf(u)); } SpreadJsObj.reLoadRowsData(sheet, rows); } // 处理展开 if (data.expand) { const expanded = []; for (const e of data.expand) { if (expanded.indexOf(e) === -1) { const posterity = tree.getPosterity(e); for (const p of posterity) { sheet.setRowVisible(tree.nodes.indexOf(p), p.visible); expanded.push(p); } } } } }); }, selectionChanged: function (e, info) { if (info.newSelections) { if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row) { SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread); if (isTz) { SpreadJsObj.resetTopAndSelect(posSheet); posSpreadObj.loadCurPosData(); posSearch.search($('#pos-keyword').val()); reviseAtt.getCurAttHtml(SpreadJsObj.getSelectObject(billsSheet)); } } } }, topRowChanged: function (e, info) { SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread); }, }; billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged); billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged); const posSpreadObj = { /** * 加载部位明细 根据当前台账选择节点 */ loadCurPosData: function () { const node = SpreadJsObj.getSelectObject(billsSheet); if (node) { const posData = pos.getLedgerPos(node.id) || []; SpreadJsObj.loadSheetData(posSheet, 'data', posData); } else { SpreadJsObj.loadSheetData(posSheet, 'data', []); } SpreadJsObj.resetFieldReadOnly(posSheet); }, }; // 加载清单&计量单元数据 postData('load', {filter:'reviseBills;revisePos;att'}, function (result) { billsTree.loadDatas(result.reviseBills); treeCalc.calculateAll(billsTree); SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree); SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread); checkShowLast(result.reviseBills.length); pos.loadDatas(result.revisePos); posSpreadObj.loadCurPosData(); SpreadJsObj.resetTopAndSelect(posSheet); for (const r of result.att) { r.node = billsTree.datas.find(x => {return x.id === r.lid}); } reviseAtt = $.ledger_att({ selector: '#fujian', key: 'id', masterKey: 'lid', uploadUrl: 'file/upload', deleteUrl: 'file/delete', checked: true, zipName: `${tenderName}-台账修订-附件.zip`, readOnly: true, // todo fileUploadPermission, locate: function (att) { if (!att) return; SpreadJsObj.locateTreeNode(billsSheet, att.node.ledger_id, true); reviseAtt.getCurAttHtml(att.node); posSpreadObj.loadCurPosData(); } }); reviseAtt.loadDatas(result.att || []); reviseAtt.getCurAttHtml(SpreadJsObj.getSelectObject(billsSheet)); }, null); $.divResizer({ select: '#revise-resize', callback: function () { billsSpread.refresh(); let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0; $(".sp-wrap").height(bcontent-30); posSpread.refresh(); } }); let searchLedger; $.divResizer({ select: '#revise-right-spr', callback: function () { billsSpread.refresh(); if (posSpread) { posSpread.refresh(); } if (searchLedger && searchLedger.spread) { searchLedger.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-select-show').removeClass('active'); tabPanel.addClass('active'); showSideTools(tab.hasClass('active')); if (tab.attr('content') === '#search' && !searchLedger) { if (!searchLedger) { searchLedger = $.billsSearch({ selector: '#search', searchSpread: billsSpread, resultSpreadSetting: { cols: [ {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'}, {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'}, {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'}, {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'}, {title: '单价', field: 'unit_price', hAlign: 2, width: 50}, {title: '数量', field: 'quantity', hAlign: 2, width: 50}, {title: '部位', field: 'bw', hAlign: 2, width: 90}, ], emptyRows: 0, headRows: 1, headRowHeight: [32], headColWidth: [30], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', selectedBackColor: '#fffacd', readOnly: true, }, afterLocated: function () { posSpreadObj.loadCurPosData(); } }); } searchLedger.spread.refresh(); } } else {// 收起工具栏 tab.removeClass('active'); tabPanel.removeClass('active'); showSideTools(tab.hasClass('active')); } billsSpread.refresh(); if (posSpread) { posSpread.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": 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; } closeWaitingView(); }, 100); }); })('a[name=showLevel]', billsSheet); $('#reviseHistory').change(function () { postData('info', { rid: this.value }, function (result) { $('#user-name').val(result.user_name); $('#content')[0].textContent = result.content; $('#end-time').val(result.end_time_str); }); }); });