|
@@ -0,0 +1,229 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+$(document).ready(function () {
|
|
|
+ const error = {
|
|
|
+ repeatBills: [],
|
|
|
+ };
|
|
|
+ autoFlashHeight();
|
|
|
+ // 根据设置整理Spread设置
|
|
|
+ const ledgerSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
|
|
|
+ {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
|
|
|
+ {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
|
|
|
+ {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
|
|
|
+ {title: '项目节数量|数量1', colSpan: '2|1', rowSpan: '1|1', field: 'dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
|
|
|
+ {title: '|数量2', colSpan: '|1', rowSpan: '|1', field: 'dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
|
|
|
+ {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'dgn_price', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '设计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 60, type: 'Number'},
|
|
|
+ {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sgfh_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '设计错漏增减|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sjcl_qty', hAlign: 2, width: 60, type: 'Number'},
|
|
|
+ {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sjcl_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '其他错漏增减|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qtcl_qty', hAlign: 2, width: 60, type: 'Number'},
|
|
|
+ {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qtcl_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '台账小计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
|
|
|
+ {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'}
|
|
|
+ ],
|
|
|
+ emptyRows: 2,
|
|
|
+ headRows: 2,
|
|
|
+ headRowHeight: [25, 25],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: true,
|
|
|
+ };
|
|
|
+ const posSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
|
|
|
+ {title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 60, formatter: '@'},
|
|
|
+ {title: '台账数量|设计量', colSpan: '4|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 100, type: 'Number'},
|
|
|
+ {title: '|设计错漏增减', colSpan: '|1', rowSpan: '|1', field: 'sjcl_qty', hAlign: 2, width: 100, type: 'Number'},
|
|
|
+ {title: '|其他错漏增减', colSpan: '|1', rowSpan: '|1', field: 'qtcl_qty', hAlign: 2, width: 100, type: 'Number'},
|
|
|
+ {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
|
|
|
+ {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
|
|
|
+ ],
|
|
|
+ emptyRows: 3,
|
|
|
+ headRows: 2,
|
|
|
+ headRowHeight: [25, 25],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: true,
|
|
|
+ };
|
|
|
+ // 初始化台账
|
|
|
+ const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
|
|
|
+ const billsSheet = billsSpread.getActiveSheet();
|
|
|
+ SpreadJsObj.initSheet(billsSheet, ledgerSpreadSetting);
|
|
|
+ // 初始化部位
|
|
|
+ const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
|
|
|
+ const posSheet = posSpread.getActiveSheet();
|
|
|
+ SpreadJsObj.initSheet(posSheet, posSpreadSetting);
|
|
|
+
|
|
|
+ const billsTree = createNewPathTree('ledger', {
|
|
|
+ id: 'ledger_id',
|
|
|
+ pid: 'ledger_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
+ calcFields: ['deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
|
|
|
+ });
|
|
|
+ const pos = new PosData({
|
|
|
+ id: 'id', ledgerId: 'lid',
|
|
|
+ });
|
|
|
+
|
|
|
+ // 获取部位明细数据
|
|
|
+ function loadPosData(iRow) {
|
|
|
+ if (!billsSheet.zh_tree) return;
|
|
|
+ const node = billsSheet.zh_tree.nodes[iRow];
|
|
|
+ if (node) {
|
|
|
+ SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, node.pos);
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, []);
|
|
|
+ }
|
|
|
+ SpreadJsObj.resetTopAndSelect(posSheet);
|
|
|
+ }
|
|
|
+ // 切换清单行,读取所属项目节数据
|
|
|
+ billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
|
|
|
+ if (info.newSelections) {
|
|
|
+ const iNewRow = info.newSelections[0].row;
|
|
|
+ if (info.oldSelections) {
|
|
|
+ const iOldRow = info.oldSelections[0].row;
|
|
|
+ if (iNewRow !== iOldRow) {
|
|
|
+ loadPosData(iNewRow);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ loadPosData(iNewRow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 右键
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#bills-spread',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
|
|
|
+ return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ checkInvisibleNode: {
|
|
|
+ name: '检查是否存在不可见节点',
|
|
|
+ icon: '',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ if (error.repeatBills.length === 0) {
|
|
|
+ toastr.success('不存在不可见节点');
|
|
|
+ } else {
|
|
|
+ toastr.warning('存在不可见节点,详细见控制台打印');
|
|
|
+ console.log('存在' + error.repeatBills.length + '个节点,无法加载至树结构:');
|
|
|
+ const sql = [];
|
|
|
+ for (const b of error.repeatBills) {
|
|
|
+ console.log(b);
|
|
|
+ sql.push("Delete From `zh_ledger` Where id = '" + b.id + "';");
|
|
|
+ }
|
|
|
+ console.log('可使用如下sql修复:');
|
|
|
+ console.log(sql.join('\n'));
|
|
|
+ console.log('如果标段已上报,请再使用以下sql更新缓存:');
|
|
|
+ console.log('\n' +
|
|
|
+ 'Update `zh_tender` t\n' +
|
|
|
+ 'INNER JOIN (Select Sum(`total_price`) as tp, Max(`tender_id`) as id From `zh_ledger` where `tender_id` = \' + billsTree.datas[0].tender_id + \') c\n' +
|
|
|
+ 'ON t.id = c.id\n' +
|
|
|
+ 'Set t.`total_price` = c.tp');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ // 选择
|
|
|
+ $('#load-tz').click(function () {
|
|
|
+ try {
|
|
|
+ const id = parseInt($('input[name=tz-id]').val());
|
|
|
+ if (id <= 0) return;
|
|
|
+ postData('/tools/load', {id: id}, function (result) {
|
|
|
+ billsTree.loadDatas(result.bills);
|
|
|
+ treeCalc.calculateAll(billsTree);
|
|
|
+ SpreadJsObj.loadSheetData(billsSheet, 'tree', billsTree);
|
|
|
+
|
|
|
+ for (const b of result.bills) {
|
|
|
+ const node = billsTree.getItems(b.ledger_id);
|
|
|
+ if (!node || node.id !== b.id) error.repeatBills.push(b);
|
|
|
+ }
|
|
|
+
|
|
|
+ pos.loadDatas(result.pos);
|
|
|
+ loadPosData();
|
|
|
+ });
|
|
|
+ } catch (err) {
|
|
|
+ toastr.error('输入的标段ID非法');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 显示层次
|
|
|
+ (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;
|
|
|
+ case "curMeasure":
|
|
|
+ tree.expandByCalcFields();
|
|
|
+ SpreadJsObj.refreshTreeRowVisible(sheet);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })('a[name=showLevel]', billsSheet);
|
|
|
+ // 导航栏
|
|
|
+ $.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();
|
|
|
+ posSpread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 上下窗口resizer
|
|
|
+ $.divResizer({
|
|
|
+ select: '#main-resize',
|
|
|
+ callback: function () {
|
|
|
+ billsSpread.refresh();
|
|
|
+ let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
|
|
|
+ $(".sp-wrap").height(bcontent - 30);
|
|
|
+ posSpread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+});
|