|
@@ -0,0 +1,298 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+const ckBillsSpread = window.location.pathname + '-billsSelect';
|
|
|
+
|
|
|
+$(document).ready(() => {
|
|
|
+ toastr.options = {
|
|
|
+ "closeButton": false,
|
|
|
+ "debug": false,
|
|
|
+ "newestOnTop": false,
|
|
|
+ "progressBar": false,
|
|
|
+ "positionClass": "toast-top-center",
|
|
|
+ "preventDuplicates": false,
|
|
|
+ "onclick": null,
|
|
|
+ "showDuration": "300",
|
|
|
+ "hideDuration": "1000",
|
|
|
+ "timeOut": "5000",
|
|
|
+ "extendedTimeOut": "1000",
|
|
|
+ "showEasing": "swing",
|
|
|
+ "hideEasing": "linear",
|
|
|
+ "showMethod": "fadeIn",
|
|
|
+ "hideMethod": "fadeOut"
|
|
|
+ };
|
|
|
+ autoFlashHeight();
|
|
|
+ // 初始化spread
|
|
|
+ const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
|
|
|
+ const billsSheet = billsSpread.getActiveSheet();
|
|
|
+ SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
|
|
|
+ const posSpread = isTz ? SpreadJsObj.createNewSpread($('#pos-spread')[0]) : null;
|
|
|
+ const posSheet = isTz ? posSpread.getActiveSheet() : null;
|
|
|
+ if (isTz) 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: 'revise.history.memu.1.0.0',
|
|
|
+ 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'],
|
|
|
+ };
|
|
|
+ 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);
|
|
|
+ billsTree.loadDatas(billsData);
|
|
|
+ treeCalc.calculateAll(billsTree);
|
|
|
+ // 加载至spread
|
|
|
+ SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
|
|
|
+ SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
|
|
|
+ // 初始化 部位明细
|
|
|
+ const pos = new PosData({ id: 'id', ledgerId: 'lid' });
|
|
|
+ pos.loadDatas(posData);
|
|
|
+
|
|
|
+ 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[0].row !== info.oldSelections[0].row) {
|
|
|
+ SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
|
|
|
+ if (isTz) {
|
|
|
+ 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);
|
|
|
+ },
|
|
|
+ };
|
|
|
+ posSpreadObj.loadCurPosData();
|
|
|
+ SpreadJsObj.resetTopAndSelect(posSheet);
|
|
|
+ $.divResizer({
|
|
|
+ select: '#revise-resize',
|
|
|
+ callback: function () {
|
|
|
+ billsSpread.refresh();
|
|
|
+ let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
|
|
|
+ $(".sp-wrap").height(bcontent-40);
|
|
|
+ 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: 120, formatter: '@', readOnly: true},
|
|
|
+ {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
|
|
|
+ {title: '名称', field: 'name', width: 230, 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: [40],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ },
|
|
|
+ afterLocated: function () {
|
|
|
+ posSpreadObj.loadCurPosData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ searchLedger.spread.refresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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').value(result.user_name);
|
|
|
+ $('#content')[0].textContent = result.content;
|
|
|
+ $('#end-time').value(result.end_time.toLocaleString());
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|