|
@@ -0,0 +1,786 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+const invalidFields = {
|
|
|
+ parent: ['quantity', 'total_price', 'unit_price'],
|
|
|
+ gcl: ['dgn_qty1', 'dgn_qty2', 'total_price'],
|
|
|
+ xmj: ['quantity', 'unit_price'],
|
|
|
+};
|
|
|
+$(document).ready(() => {
|
|
|
+ const copyBlockTag = 'zh.calc.copyBlock';
|
|
|
+ let stdXmj, stdGcl, searchCtrlPrice;
|
|
|
+ autoFlashHeight();
|
|
|
+ const priceSpread = SpreadJsObj.createNewSpread($('#ctrl-price-spread')[0]);
|
|
|
+ const priceSheet = priceSpread.getActiveSheet();
|
|
|
+ sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);
|
|
|
+ spreadSetting.readOnly = readOnly;
|
|
|
+ SpreadJsObj.initSheet(priceSheet, spreadSetting);
|
|
|
+
|
|
|
+ $.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();
|
|
|
+ priceSpread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const priceTree = createNewPathTree('ledger', {
|
|
|
+ id: 'tree_id',
|
|
|
+ pid: 'tree_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ keys: ['id', 'tid', 'tree_id'],
|
|
|
+ autoExpand: 3,
|
|
|
+ markExpandKey: 'price-expand',
|
|
|
+ markExpandSubKey: window.location.pathname.split('/')[2],
|
|
|
+ calcFields: ['total_price'],
|
|
|
+ calcFun: function (node) {
|
|
|
+ node.dgn_price = ZhCalc.div(node.total_price, node.dgn_qty1, 2);
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ $.divResizer({
|
|
|
+ select: '#right-spr',
|
|
|
+ callback: function () {
|
|
|
+ priceSpread.refresh();
|
|
|
+ if (stdXmj) stdXmj.spread.refresh();
|
|
|
+ if (stdGcl) stdGcl.spread.refresh();
|
|
|
+ if (searchCtrlPrice) searchCtrlPrice.spread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const priceTreeOpr = {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getDefaultSelectInfo: function (sheet) {
|
|
|
+ const tree = sheet.zh_tree;
|
|
|
+ if (!tree) return;
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ const node = sheet.zh_tree.nodes[sel.row];
|
|
|
+ if (!node) return;
|
|
|
+ let count = 1;
|
|
|
+ if (sel.rowCount > 1) {
|
|
|
+ for (let r = 1; r < sel.rowCount; r++) {
|
|
|
+ const rNode = sheet.zh_tree.nodes[sel.row + r];
|
|
|
+ if (rNode.level > node.level) continue;
|
|
|
+ if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
|
|
|
+ toastr.warning('请选择同一节点下的节点,进行该操作');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ count += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return [tree, node, count];
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 刷新顶部按钮是否可用
|
|
|
+ * @param sheet
|
|
|
+ * @param selections
|
|
|
+ */
|
|
|
+ refreshOperationValid: function (sheet, selection) {
|
|
|
+ const setObjEnable = function (obj, enable) {
|
|
|
+ if (enable) {
|
|
|
+ obj.removeClass('disabled');
|
|
|
+ } else {
|
|
|
+ obj.addClass('disabled');
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const invalidAll = function () {
|
|
|
+ setObjEnable($('a[name=base-opr][type=add]'), false);
|
|
|
+ setObjEnable($('a[name=base-opr][type=delete]'), false);
|
|
|
+ setObjEnable($('a[name=base-opr][type=up-move]'), false);
|
|
|
+ setObjEnable($('a[name=base-opr][type=down-move]'), false);
|
|
|
+ setObjEnable($('a[name=base-opr][type=up-level]'), false);
|
|
|
+ setObjEnable($('a[name=base-opr][type=down-level]'), false);
|
|
|
+ };
|
|
|
+ const sel = selection ? selection[0] : sheet.getSelections()[0];
|
|
|
+ const row = sel ? sel.row : -1;
|
|
|
+ const tree = sheet.zh_tree;
|
|
|
+ if (!tree) {
|
|
|
+ invalidAll();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const first = sheet.zh_tree.nodes[row];
|
|
|
+ if (!first) {
|
|
|
+ invalidAll();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let last = first, sameParent = true;
|
|
|
+ if (sel.rowCount > 1 && first) {
|
|
|
+ for (let r = 1; r < sel.rowCount; r++) {
|
|
|
+ const rNode = tree.nodes[sel.row + r];
|
|
|
+ if (!rNode) {
|
|
|
+ sameParent = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (rNode.level > first.level) continue;
|
|
|
+ if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
|
|
|
+ sameParent = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ last = rNode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const preNode = tree.getPreSiblingNode(first);
|
|
|
+ const valid = !readOnly;
|
|
|
+
|
|
|
+ setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1);
|
|
|
+ setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1);
|
|
|
+ setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
|
|
|
+ setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
|
|
|
+ setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && first.level > 2 && tree.isLastSibling(last));
|
|
|
+ setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent && first.level > 1 && preNode);
|
|
|
+ },
|
|
|
+ selectionChanged: function (e, info) {
|
|
|
+ if (info.newSelections) {
|
|
|
+ if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row) {
|
|
|
+ priceTreeOpr.refreshOperationValid(info.sheet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 新增节点
|
|
|
+ * @param spread
|
|
|
+ */
|
|
|
+ baseOpr: function (sheet, type, addCount = 1) {
|
|
|
+ const self = this;
|
|
|
+ const [tree, node, count] = this.getDefaultSelectInfo(sheet);
|
|
|
+ if (!tree || !node || !count) return;
|
|
|
+
|
|
|
+ if (type === 'delete') {
|
|
|
+ deleteAfterHint(function () {
|
|
|
+ postData(window.location.pathname + '/update', {
|
|
|
+ postType: type,
|
|
|
+ postData: { id: node.tree_id, count: type === 'add' ? addCount : count }
|
|
|
+ }, function (result) {
|
|
|
+ const refreshData = tree.loadPostData(result);
|
|
|
+ self.refreshTree(sheet, refreshData);
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ if (sel) {
|
|
|
+ sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
|
|
|
+ }
|
|
|
+ self.refreshOperationValid(sheet);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ postData(window.location.pathname + '/update', {
|
|
|
+ postType: type,
|
|
|
+ postData: { id: node.tree_id, count: type === 'add' ? addCount : count }
|
|
|
+ }, function (result) {
|
|
|
+ const refreshData = tree.loadPostData(result);
|
|
|
+ self.refreshTree(sheet, refreshData);
|
|
|
+ if (['up-move', 'down-move'].indexOf(type) > -1) {
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ if (sel) {
|
|
|
+ sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
|
|
|
+ SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
|
|
|
+ }
|
|
|
+ } else if (type === 'add') {
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ if (sel) {
|
|
|
+ sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
|
|
|
+ SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.refreshOperationValid(sheet);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ editStarting(e, info) {
|
|
|
+ if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ const node = info.sheet.zh_tree.nodes[info.row];
|
|
|
+ if (!node) {
|
|
|
+ info.cancel = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ switch (col.field) {
|
|
|
+ case 'unit_price':
|
|
|
+ case 'quantity':
|
|
|
+ info.cancel = (node.children && node.children.length > 0) || !node.b_code;
|
|
|
+ break;
|
|
|
+ case 'total_price':
|
|
|
+ info.cancel = (node.children && node.children.length > 0) || node.b_code;
|
|
|
+ break;
|
|
|
+ case 'dgn_price':
|
|
|
+ info.cance = false;
|
|
|
+ break;
|
|
|
+ case 'dgn_qty1':
|
|
|
+ case 'dgn_qty2':
|
|
|
+ info.cancel = !_.isEmpty(node.b_code);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 编辑单元格响应事件
|
|
|
+ * @param {Object} e
|
|
|
+ * @param {Object} info
|
|
|
+ */
|
|
|
+ editEnded: function (e, info) {
|
|
|
+ if (info.sheet.zh_setting) {
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ const sortData = info.sheet.zh_tree.nodes;
|
|
|
+ const node = sortData[info.row];
|
|
|
+ const data = { id: node.id, tid: node.tid, tree_id: node.tree_id };
|
|
|
+ // 未改变值则不提交
|
|
|
+ const orgValue = node[col.field];
|
|
|
+ const newValue = trimInvalidChar(info.editingText);
|
|
|
+ if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) return;
|
|
|
+
|
|
|
+ if (node.b_code && invalidFields.gcl.indexOf(col.field) >=0) {
|
|
|
+ toastr.error('工程量清单请勿输入设计数量、金额');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取更新数据
|
|
|
+ if (newValue) {
|
|
|
+ if (col.type === 'Number') {
|
|
|
+ const num = _.toNumber(newValue);
|
|
|
+ if (_.isNaN(num)) {
|
|
|
+ toastr.error('请输入数字');
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ data[col.field] = num;
|
|
|
+ } else {
|
|
|
+ data[col.field] = newValue;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data[col.field] = col.type === 'Number' ? 0 : '';
|
|
|
+ }
|
|
|
+ console.log(data);
|
|
|
+ // 更新至服务器
|
|
|
+ postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
|
|
|
+ const refreshNode = priceTree.loadPostData(result);
|
|
|
+ priceTreeOpr.refreshTree(info.sheet, refreshNode);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ clipboardPasting: function (e, info) {
|
|
|
+ const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
|
|
|
+ info.cancel = true;
|
|
|
+ if (!setting || !tree) return;
|
|
|
+
|
|
|
+ const pasteData = info.pasteData.html
|
|
|
+ ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
|
|
|
+ : (info.pasteData.text === ''
|
|
|
+ ? SpreadJsObj.Clipboard.getAnalysisPasteText()
|
|
|
+ : SpreadJsObj.analysisPasteText(info.pasteData.text));
|
|
|
+ const hint = {
|
|
|
+ invalidNum: {type: 'warning', msg: '粘贴的数字非法'},
|
|
|
+ parent: {type: 'warning', msg: `含有子项,不可粘贴${needGcl ? '数量、单价、' : ''}金额`},
|
|
|
+ gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量、金额'},
|
|
|
+ xmj: {type: 'warning', msg: '项目节,不可粘贴数量、单价'},
|
|
|
+ };
|
|
|
+ const datas = [], filterNodes = [];
|
|
|
+
|
|
|
+ let filterRow = 0;
|
|
|
+ for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
|
|
|
+ const curRow = info.cellRange.row + iRow;
|
|
|
+ const node = tree.nodes[curRow];
|
|
|
+ if (!node) continue;
|
|
|
+
|
|
|
+ let bPaste = false;
|
|
|
+ const data = info.sheet.zh_tree.getNodeKeyData(node);
|
|
|
+ for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
|
|
|
+ const curCol = info.cellRange.col + iCol;
|
|
|
+ const colSetting = info.sheet.zh_setting.cols[curCol];
|
|
|
+ const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
|
|
|
+ if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
|
|
|
+ toastMessageUniq(hint.parent);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
|
|
|
+ toastMessageUniq(hint.gcl);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (_.isEmpty(node.b_code) && invalidFields.xmj.indexOf(colSetting.field) >= 0) {
|
|
|
+ toastMessageUniq(hint.xmj);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (colSetting.type === 'Number') {
|
|
|
+ if (colSetting.type === 'Number') {
|
|
|
+ const num = _.toNumber(value);
|
|
|
+ if (_.isNaN(num)) {
|
|
|
+ toastMessageUniq(hint.invalidExpr);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ data[colSetting.field] = num;
|
|
|
+ } else {
|
|
|
+ data[colSetting.field] = value;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data[colSetting.field] = value;
|
|
|
+ }
|
|
|
+ bPaste = true;
|
|
|
+ }
|
|
|
+ if (bPaste) {
|
|
|
+ datas.push(data);
|
|
|
+ } else {
|
|
|
+ filterNodes.push(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
|
|
|
+ const refreshNode = tree.loadPostData(result);
|
|
|
+ if (refreshNode.update) refreshNode.update = refreshNode.update.concat(filterNodes);
|
|
|
+ priceTreeOpr.refreshTree(info.sheet, refreshNode);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deletePress: function (sheet) {
|
|
|
+ const tree = sheet.zh_tree, setting = sheet.zh_setting;
|
|
|
+ if (!setting || !tree) return;
|
|
|
+
|
|
|
+ const sortData = sheet.zh_tree.nodes;
|
|
|
+ const datas = [];
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
|
|
|
+ const node = sortData[iRow];
|
|
|
+ if (node) {
|
|
|
+ let bDel = false;
|
|
|
+ const data = tree.getNodeKeyData(node);
|
|
|
+ for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
|
|
|
+ const style = sheet.getStyle(iRow, iCol);
|
|
|
+ if (!style.locked) {
|
|
|
+ const colSetting = setting.cols[iCol];
|
|
|
+ data[colSetting.field] = colSetting.type === 'Number' ? 0 : '';
|
|
|
+ bDel = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bDel) datas.push(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
|
|
|
+ const refreshNode = tree.loadPostData(result);
|
|
|
+ priceTreeOpr.refreshTree(sheet, refreshNode);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ pasteBlock: function (sheet, copyInfo) {
|
|
|
+ const self = this;
|
|
|
+ const [tree, node] = this.getDefaultSelectInfo(sheet);
|
|
|
+
|
|
|
+ postData(window.location.pathname + '/update', {
|
|
|
+ postType: 'paste-block',
|
|
|
+ postData: {
|
|
|
+ id: tree.getNodeKey(node),
|
|
|
+ tid: copyInfo.tid,
|
|
|
+ block: copyInfo.block,
|
|
|
+ }
|
|
|
+ }, function (data) {
|
|
|
+ const result = tree.loadPostData(data);
|
|
|
+ self.refreshTree(sheet, result);
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ if (sel) {
|
|
|
+ sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
|
|
|
+ SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
|
|
|
+ }
|
|
|
+ self.refreshOperationValid(sheet);
|
|
|
+ removeLocalCache(copyBlockTag);
|
|
|
+ }, null, true);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ priceSpread.bind(spreadNS.Events.SelectionChanged, priceTreeOpr.selectionChanged);
|
|
|
+ if (!readOnly) {
|
|
|
+ // 增删上下移升降级
|
|
|
+ $('a[name="base-opr"]').click(function () {
|
|
|
+ priceTreeOpr.baseOpr(priceSheet, this.getAttribute('type'));
|
|
|
+ });
|
|
|
+ priceSpread.bind(spreadNS.Events.EditStarting, priceTreeOpr.editStarting);
|
|
|
+ priceSpread.bind(spreadNS.Events.EditEnded, priceTreeOpr.editEnded);
|
|
|
+ priceSpread.bind(spreadNS.Events.ClipboardPasting, priceTreeOpr.clipboardPasting);
|
|
|
+ SpreadJsObj.addDeleteBind(priceSpread, priceTreeOpr.deletePress);
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#budget-spread',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, priceSpread);
|
|
|
+ return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ copyBlock: {
|
|
|
+ name: '复制整块',
|
|
|
+ icon: 'fa-files-o',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const copyBlockList = [];
|
|
|
+ const sheet = priceSheet;
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ let iRow = sel.row;
|
|
|
+ const pid = sheet.zh_tree.nodes[iRow].tree_pid;
|
|
|
+ while (iRow < sel.row + sel.rowCount) {
|
|
|
+ const node = sheet.zh_tree.nodes[iRow];
|
|
|
+ if (node.tree_pid !== pid) {
|
|
|
+ toastr.error('仅可同时选中同层节点');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const posterity = sheet.zh_tree.getPosterity(node);
|
|
|
+ iRow += posterity.length + 1;
|
|
|
+ posterity.unshift(node);
|
|
|
+ copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
|
|
|
+ }
|
|
|
+ setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(priceSheet);
|
|
|
+ return !!select;
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(priceSheet);
|
|
|
+ return !!select && select.level <= 1;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ copyBlockXmj: {
|
|
|
+ name: '复制整块(只复制项目节)',
|
|
|
+ icon: 'fa-files-o',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const copyBlockList = [];
|
|
|
+ const sheet = priceSheet;
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ let iRow = sel.row;
|
|
|
+ const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
|
|
|
+ while (iRow < sel.row + sel.rowCount) {
|
|
|
+ const node = sheet.zh_tree.nodes[iRow];
|
|
|
+ if (node.ledger_pid !== pid) {
|
|
|
+ toastr.error('仅可同时选中同层节点');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const posterity = sheet.zh_tree.getPosterity(node);
|
|
|
+ iRow += posterity.length + 1;
|
|
|
+ const copyPosterity = posterity.filter(x => { return !x.b_code; });
|
|
|
+ copyPosterity.unshift(node);
|
|
|
+ const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
|
|
|
+ for (const p of copyData) {
|
|
|
+ const children = copyData.filter(y => {return y.tree_pid === p.tree_id}) || [];
|
|
|
+ p.is_leaf = children.length === 0;
|
|
|
+ }
|
|
|
+ copyBlockList.push(copyData);
|
|
|
+ }
|
|
|
+ setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(priceSheet);
|
|
|
+ return needGcl && !!select;
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const select = SpreadJsObj.getSelectObject(priceSheet);
|
|
|
+ return !!select && select.level <= 1;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ pasteBlock: {
|
|
|
+ name: '粘贴整块',
|
|
|
+ icon: 'fa-clipboard',
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
|
|
|
+ return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
|
|
|
+ },
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
|
|
|
+ if (copyInfo.block.length > 0) {
|
|
|
+ priceTreeOpr.pasteBlock(priceSheet, copyInfo);
|
|
|
+ } else {
|
|
|
+ document.execCommand('paste');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ return !readOnly;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ postData(window.location.pathname + '/load', {}, function (result) {
|
|
|
+ priceTree.loadDatas(result);
|
|
|
+ treeCalc.calculateAll(priceTree);
|
|
|
+ SpreadJsObj.loadSheetData(priceSheet, SpreadJsObj.DataType.Tree, priceTree);
|
|
|
+ priceTreeOpr.refreshOperationValid(priceSheet);
|
|
|
+ });
|
|
|
+
|
|
|
+ const stdLibCellDoubleClick = function (e, info) {
|
|
|
+ const stdSheet = info.sheet;
|
|
|
+ if (!stdSheet.zh_setting || !stdSheet.zh_tree || !priceSheet.zh_tree) return;
|
|
|
+
|
|
|
+ const stdTree = stdSheet.zh_tree;
|
|
|
+ const stdNode = stdTree.nodes[info.row];
|
|
|
+ if (!stdNode) return;
|
|
|
+
|
|
|
+ const priceTree = priceSheet.zh_tree;
|
|
|
+ const sel = priceSheet.getSelections()[0];
|
|
|
+ const mainNode = priceTree.nodes[sel.row];
|
|
|
+ if (info.sheet.zh_setting.stdType === 'gcl') {
|
|
|
+ if (mainNode.code && mainNode.code !== '' && !priceTree.isLeafXmj(mainNode)) {
|
|
|
+ toastr.warning('非最底层项目下,不应添加清单');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ postData(window.location.pathname + '/update', {
|
|
|
+ postType: 'add-std',
|
|
|
+ postData: {
|
|
|
+ id: priceTree.getNodeKey(mainNode),
|
|
|
+ tender_id: mainNode.tender_id,
|
|
|
+ stdType: info.sheet.zh_setting.stdType,
|
|
|
+ stdLibId: stdNode.list_id,
|
|
|
+ stdNode: stdTree.getNodeKey(stdNode)
|
|
|
+ }
|
|
|
+ }, function (result) {
|
|
|
+ const refreshNode = priceTree.loadPostData(result);
|
|
|
+ priceTreeOpr.refreshTree(priceSheet, refreshNode);
|
|
|
+ if (refreshNode.create && refreshNode.create.length > 0) {
|
|
|
+ priceSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
|
|
|
+ SpreadJsObj.reloadRowsBackColor(priceSheet, [sel.row, priceTree.nodes.indexOf(mainNode), refreshNode.create[refreshNode.create.length - 1].index]);
|
|
|
+ } else {
|
|
|
+ const node = _.find(priceTree.nodes, {code: stdNode.code, name: stdNode.name});
|
|
|
+ if (node) {
|
|
|
+ priceSheet.setSelection(priceTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
|
|
|
+ SpreadJsObj.reloadRowsBackColor(priceSheet, [sel.row, priceTree.nodes.indexOf(node)]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ priceTreeOpr.refreshOperationValid(priceSheet);
|
|
|
+ priceSpread.focus();
|
|
|
+ });
|
|
|
+ };
|
|
|
+ const stdXmjSetting = {
|
|
|
+ selector: '#std-xmj',
|
|
|
+ stdType: 'xmj',
|
|
|
+ libs: stdChapters,
|
|
|
+ treeSetting: {
|
|
|
+ id: 'chapter_id',
|
|
|
+ pid: 'pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ keys: ['id', 'list_id', 'chapter_id'],
|
|
|
+ },
|
|
|
+ spreadSetting: {
|
|
|
+ cols: [
|
|
|
+ {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', cellType: 'tree'},
|
|
|
+ {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
|
|
|
+ {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'}
|
|
|
+ ],
|
|
|
+ treeCol: 0,
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ headColWidth: [30],
|
|
|
+ selectedBackColor: '#fffacd',
|
|
|
+ readOnly: true,
|
|
|
+ },
|
|
|
+ cellDoubleClick: !readOnly ? stdLibCellDoubleClick : null,
|
|
|
+ page: 'ctrlPrice',
|
|
|
+ tid: window.location.pathname.split('/')[2],
|
|
|
+ };
|
|
|
+ const stdGclSetting = {
|
|
|
+ selector: '#std-gcl',
|
|
|
+ stdType: 'gcl',
|
|
|
+ libs: stdBills,
|
|
|
+ treeSetting: {
|
|
|
+ id: 'bill_id',
|
|
|
+ pid: 'pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ keys: ['id', 'list_id', 'bill_id']
|
|
|
+ },
|
|
|
+ spreadSetting: {
|
|
|
+ cols: [
|
|
|
+ {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', cellType: 'tree'},
|
|
|
+ {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
|
|
|
+ {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'}
|
|
|
+ ],
|
|
|
+ treeCol: 0,
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ headColWidth: [30],
|
|
|
+ selectedBackColor: '#fffacd',
|
|
|
+ readOnly: true,
|
|
|
+ },
|
|
|
+ cellDoubleClick: !readOnly ? stdLibCellDoubleClick : null,
|
|
|
+ page: 'ctrlPrice',
|
|
|
+ tid: window.location.pathname.split('/')[2],
|
|
|
+ };
|
|
|
+ // 展开收起标准清单
|
|
|
+ $('a', 'ul.right-nav').bind('click', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ const tab = $(this), tabPanel = $(tab.attr('content'));
|
|
|
+ // 展开工具栏、切换标签
|
|
|
+ if (!tab.hasClass('active')) {
|
|
|
+ $('a', '.side-menu').removeClass('active');
|
|
|
+ $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
|
|
|
+ tab.addClass('active');
|
|
|
+ tabPanel.addClass('active');
|
|
|
+ showSideTools(tab.hasClass('active'));
|
|
|
+ if (tab.attr('content') === '#std-xmj') {
|
|
|
+ if (!stdXmj) stdXmj = $.stdLib(stdXmjSetting);
|
|
|
+ stdXmj.spread.refresh();
|
|
|
+ } else if (tab.attr('content') === '#std-gcl') {
|
|
|
+ if (!stdGcl) stdGcl = $.stdLib(stdGclSetting);
|
|
|
+ stdGcl.spread.refresh();
|
|
|
+ } else if (tab.attr('content') === '#search') {
|
|
|
+ if (!searchCtrlPrice) {
|
|
|
+ const searchSetting = {
|
|
|
+ selector: '#search',
|
|
|
+ searchSpread: priceSpread,
|
|
|
+ keyId: 'tree_id',
|
|
|
+ resultSpreadSetting: {
|
|
|
+ cols: [
|
|
|
+ {title: '项目节编号', field: 'code', hAlign: 0, width: 120, 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: '@'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ headColWidth: [30],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ selectedBackColor: '#fffacd',
|
|
|
+ readOnly: true,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ if (!needGcl) {
|
|
|
+ searchSetting.resultSpreadSetting.cols = searchSetting.resultSpreadSetting.cols.filter(x => {
|
|
|
+ return ['b_code', 'quantity', 'unit_price'].indexOf(x.field) < 0;
|
|
|
+ });
|
|
|
+ searchSetting.searchRangeStr = '项目节编号/名称';
|
|
|
+ } else {
|
|
|
+ searchSetting.searchRangeStr = '项目节编号/清单编号/名称';
|
|
|
+ }
|
|
|
+ searchCtrlPrice = $.billsSearch(searchSetting);
|
|
|
+ }
|
|
|
+ searchCtrlPrice.spread.refresh();
|
|
|
+ }
|
|
|
+ } else { // 收起工具栏
|
|
|
+ tab.removeClass('active');
|
|
|
+ tabPanel.removeClass('active');
|
|
|
+ showSideTools(tab.hasClass('active'));
|
|
|
+ }
|
|
|
+ priceSpread.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]', priceSheet);
|
|
|
+ // 导入
|
|
|
+ $('#budget-import').click(() => {
|
|
|
+ importExcel.doImport({
|
|
|
+ template: {
|
|
|
+ hint: '导入Excel',
|
|
|
+ url: '/template/估概预算示例EXCEL格式.xlsx',
|
|
|
+ },
|
|
|
+ filter: needGcl,
|
|
|
+ callback: function (sheet, filter) {
|
|
|
+ postDataCompress(window.location.pathname + '/upload-excel/tz', {sheet, filter}, function (result) {
|
|
|
+ priceTree.loadDatas(result);
|
|
|
+ treeCalc.calculateAll(priceTree);
|
|
|
+ SpreadJsObj.reLoadSheetData(priceSheet);
|
|
|
+ checkShowLast(result.length);
|
|
|
+ }, null);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|