123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const ckBillsSpread = window.location.pathname + '-billsSelect';
- $(document).ready(() => {
- autoFlashHeight();
- // 初始化spread
- const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
- const billsSheet = billsSpread.getActiveSheet();
- sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
- 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());
- }
- }
- }
- },
- 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(window.location.pathname + '/load', {}, function (result) {
- billsTree.loadDatas(result.bills);
- treeCalc.calculateAll(billsTree);
- SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
- SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
- pos.loadDatas(result.pos);
- posSpreadObj.loadCurPosData();
- SpreadJsObj.resetTopAndSelect(posSheet);
- }, 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-pane').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: '@', readOnly: true},
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
- {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
- {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- },
- 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;
- 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);
- $('#reviseHistory').change(function () {
- postData(window.location.pathname + '/info', { rid: this.value }, function (result) {
- $('#user-name').val(result.user_name);
- $('#content')[0].textContent = result.content;
- $('#end-time').val(result.end_time_str);
- });
- });
- });
|