function getGxbyText(data) { const def = thirdParty.gxby.find(function (x) { return x.value === data.gxby_status; }); return def ? def.name : ''; } function getDaglText(data) { const def = thirdParty.dagl.find(function (x) { return x.value === data.dagl_status; }); return def ? def.name : ''; } const ckBillsSpread = window.location.pathname + '-billsSelect'; $(document).ready(() => { autoFlashHeight(); let searchLedger; const settleTreeSetting = { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'tender_id', 'ledger_id'], stageId: 'id', autoExpand: 3, markExpandKey: 'settle-select-expand', markExpandSubKey: window.location.pathname.split('/')[2], calcFields: ['total_price', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'], calcFun: function(node) { if (!node.children || node.children.length === 0) { node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty); node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty); node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty); node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty); node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty); node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty); node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity); node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp); node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty); node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty); } node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp); node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price); node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp); if (!node.children || node.children.length === 0) { if (node.end_contract_qty) { node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp)); } else { node.end_correct_tp = node.end_gather_tp; } } node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2); node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2); node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2); node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2); } }; const settleTree = createNewPathTree('stage', settleTreeSetting); const settlePosSetting = { id: 'id', ledgerId: 'lid', calcFun: function(pos) { pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty); pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity); pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2); } }; const settlePos = new StagePosData(settlePosSetting); const slSpread = SpreadJsObj.createNewSpread($('#settle-bills')[0]); const slSheet = slSpread.getActiveSheet(); slSheet.frozenColumnCount(billsSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1); slSheet.options.frozenlineColor = '#93b5e4'; const ratioCol = billsSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'}); if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent'; billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) { if (!data) return defaultColor; if (data.children && data.children.length > 0) return defaultColor; if (col.field === 'gxby') { const def = thirdParty.gxby.find(function (x) { return x.value === data.gxby_status; }); if (def && def.color) return def.color; } else if (col.field === 'dagl') { const def = thirdParty.dagl.find(function (x) { return x.value === data.dagl_status; }); if (def && def.color) return def.color; } }; sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz); sjsSettingObj.set3FCols(billsSpreadSetting.cols, [ {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'}, {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'}, ]); billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) { if (data) { if (col.field === 'gxby') { const def = thirdParty.gxby.find(function (x) { return x.value === data.gxby_status; }); if (def && def.color) return def.color; } else if (col.field === 'dagl') { const def = thirdParty.dagl.find(function (x) { return x.value === data.dagl_status; }); if (def && def.color) return def.color; } return data.selected && data.undone ? spreadColor.stage.over : defaultColor; } else { return defaultColor; } }; SpreadJsObj.initSheet(slSheet, billsSpreadSetting); const spSpread = SpreadJsObj.createNewSpread($('#settle-pos')[0]); const spSheet = spSpread.getActiveSheet(); spSheet.frozenColumnCount(posSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1); spSheet.options.frozenlineColor = '#93b5e4'; posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) { if (!data) return defaultColor; if (col.field === 'gxby') { const def = thirdParty.gxby.find(function (x) { return x.value === data.gxby_status; }); if (def && def.color) return def.color; } else if (col.field === 'dagl') { const def = thirdParty.dagl.find(function (x) { return x.value === data.dagl_status; }); if (def && def.color) return def.color; } }; sjsSettingObj.set3FCols(posSpreadSetting.cols, [ {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'}, {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'}, ]); posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) { if (data) { if (col.field === 'gxby') { const def = thirdParty.gxby.find(function (x) { return x.value === data.gxby_status; }); if (def && def.color) return def.color; } else if (col.field === 'dagl') { const def = thirdParty.dagl.find(function (x) { return x.value === data.dagl_status; }); if (def && def.color) return def.color; } return data.selected && data.undone ? spreadColor.stage.over : defaultColor; } else { return defaultColor; } }; SpreadJsObj.initSheet(spSheet, posSpreadSetting); const settleCheck = { _analysisPos(pos) { if (pos.settle_status === undefined) pos.settle_status = 0; pos.undoneDeal = pos.quantity ? !checkZero(ZhCalc.sub(pos.end_contract_qty, pos.quantity)) : false; pos.undone = !!pos.undoneDeal || !!pos.undoneChange; }, _analysisNode(node) { if (node.undoneDeal === undefined) node.undoneDeal = false; if (node.undoneChange === undefined) node.undoneChange = false; if (node.settle_status === undefined) node.settle_status = 0; const status = []; if (node.children && node.children.length > 0) { for (const child of node.children) { this._analysisNode(child); if (child.undoneDeal) node.undoneDeal = true; if (child.undoneChange) node.undoneChange = true; if (status.indexOf(child.settle_status) < 0) status.push(child.settle_status); } node.undone = !!node.undoneDeal || !!node.undoneChange; node.settle_status = status.length === 1 ? status[0] : 1; } else { const posRange = settlePos.getLedgerPos(node.id); if (posRange && posRange.length > 0) { for (const pos of posRange) { this._analysisPos(pos); if (pos.undoneDeal) node.undoneDeal = true; if (pos.undoneChange) node.undoneChange = true; if (status.indexOf(pos.settle_status) < 0) status.push(pos.settle_status); } node.undone = !!node.undoneDeal || !!node.undoneChange; node.settle_status = status.length === 1 ? status[0] : 1; } else { node.undoneDeal = node.end_contract_qty ? !checkZero(ZhCalc.sub(node.end_contract_qty, node.final_1_qty)) : !checkZero(ZhCalc.sub(node.end_contract_tp, node.final_1_tp)); node.undone = !!node.undoneDeal || !!node.undoneChange; } } }, init() { for (const node of settleTree.children) { this._analysisNode(node); } } }; const settleBillsObj = { loadRelaData: function() { SpreadJsObj.saveTopAndSelect(slSheet, ckBillsSpread); SpreadJsObj.resetTopAndSelect(spSheet); settlePosObj.loadCurPosData(); }, selectionChanged: function(e, info) { if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) { settleBillsObj.loadRelaData(); } }, topRowChanged(e, info) { SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread); }, buttonClicked: function(e, info) { if (!info.sheet.zh_setting) return; const col = info.sheet.zh_setting.cols[info.col]; if (col.field !== 'selected') return; const node = SpreadJsObj.getSelectObject(info.sheet); if (node.undone && !node.selected) { let msg = '选择的节点不可结算'; if (node.undoneDeal) msg = msg + ',合同未计量完'; if (node.undoneChange) msg = msg + ',变更令未调用完'; toastr.warning(msg); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } if (node.settle_status === 2) { toastr.warning('已结算数据,请勿重复结算'); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } if (!node.selected) { const parents = settleTree.getAllParents(node); for (const p of parents) { if (p.selected) { toastr.warning(`父项${p.code || ''}以勾选,勿需重复勾选子项`); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } } } const update = {}; if (!node.selected) { update.add = [{ lid: node.id }]; const posterity = settleTree.getPosterity(node); for (const p of posterity) { if (p.selected) { if (!update.del) update.del = []; update.del.push({ lid: p.id }); } if (!p.children || p.children.length === 0) { const posRange = settlePos.getLedgerPos(p.id); if (posRange && posRange.length > 0) { for (const p of posRange) { if (p.selected) { if (!update.del) update.del = []; update.del.push({ pid: p.id }); } } } } } } else { update.del = [{ lid: node.id }]; } postData(window.location.pathname + '/update', update, result => { node.selected = !node.selected; let refreshRow = [info.row], refreshPos = false; if (result.del) { for (const d of result.del) { if (d.lid) { const sbi = settleTree.nodes.findIndex(x => { return x.id === d.lid; }); settleTree.nodes[sbi].selected = false; refreshRow.push(sbi); } else if (d.pid) { const sp = settlePos.getPos(d.pid); if (sp) { sp.selected = false; if (sp.lid === node.id) refreshPos = false; } } } } if (refreshRow.length > 0) SpreadJsObj.reLoadRowsData(info.sheet, refreshRow); if (refreshPos) settlePosObj.loadCurPosData(); }, () => { SpreadJsObj.reLoadRowData(info.sheet, info.row); }); }, }; slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged); slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged); if (!readOnly) { slSpread.bind(spreadNS.Events.ButtonClicked, settleBillsObj.buttonClicked); } const settlePosObj = { loadCurPosData: function() { const billsNode = SpreadJsObj.getSelectObject(slSheet); if (billsNode) { spSheet.zh_setting.readOnly = readOnly; const posRange = settlePos.getLedgerPos(billsNode.id) || []; SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly); if (posRange.length > 0) SpreadJsObj.locateData(spSheet, posRange[0]); } else { spSheet.zh_setting.readOnly = true; SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true); } }, buttonClicked: function(e, info) { if (!info.sheet.zh_setting) return; const col = info.sheet.zh_setting.cols[info.col]; if (col.field !== 'selected') return; const node = SpreadJsObj.getSelectObject(info.sheet); if (node.undone && !node.selected) { let msg = '选择的节点不可结算'; if (node.undoneDeal) msg = msg + ',合同未计量完'; if (node.undoneChange) msg = msg + ',变更令未调用完'; toastr.warning(msg); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } if (node.settle_status === 2) { toastr.warning('已结算数据,请勿重复结算'); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } if (!node.selected) { const billsNode = settleTree.nodes.find(x => { return x.id === node.lid }); const parents = settleTree.getAllParents(billsNode); for (const p of parents) { if (p.selected) { toastr.warning(`所属清单的父项${p.code || ''}以勾选,勿需重复勾选计量单元`); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } } } const update = {}; if (!node.selected) { update.add = [{ pid: node.id }]; } else { update.del = [{ pid: node.id }]; } postData(window.location.pathname + '/update', update, result => { node.selected = !node.selected; SpreadJsObj.reLoadRowData(info.sheet, info.row); }, () => { SpreadJsObj.reLoadRowData(info.sheet, info.row); }); }, }; if (!readOnly) { spSpread.bind(spreadNS.Events.ButtonClicked, settlePosObj.buttonClicked); } postData('load', {filter: 'stageBills;stagePos;settleSelect;tag;settleChange'}, function(result) { for (const select of result.settleSelect) { if (select.pid) { const sp = result.stagePos.find(x => { return x.id === select.pid }); if (sp) sp.selected = true; } else { const sb = result.stageBills.find(x => { return x.id === select.lid }); if (sb) sb.selected = true; } } for (const change of result.settleChange) { const sb = result.stageBills.find(x => { return x.id === change.gcl_id }); if (sb) sb.undoneChange = true; if (change.mx_id) { const sp = result.stagePos.find(x => { return x.id === change.mx_id }); if (sp) sp.undoneChange = true; } } settleTree.loadDatas(result.stageBills); treeCalc.calculateAll(settleTree); settlePos.loadDatas(result.stagePos); settlePos.calculateAll(); settleCheck.init(); SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree); SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread); settlePosObj.loadCurPosData(); }); // 展开收起工具栏 $('a', '.right-nav').bind('click', function () { const tab = $(this), tabPanel = $(tab.attr('content')); if (!tab.hasClass('active')) { $('a', '.side-menu').removeClass('active'); $('.tab-content .tab-select-show').removeClass('active'); tab.addClass('active'); tabPanel.addClass('active'); showSideTools(tab.hasClass('active')); if (tab.attr('content') === '#search' && !searchLedger) { searchLedger = $.billsSearch({ selector: '#search', searchSpread: slSpread, searchOver: true, searchEmpty: true, 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}, ], emptyRows: 0, headRows: 1, headRowHeight: [32], headColWidth: [30], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', selectedBackColor: '#fffacd', readOnly: true, }, afterLocated: function () { settlePosObj.loadCurPosData(); }, customSearch: [ { key: 'err', title: '结算错误', valid: true, parent: true, check: function (node) { const billsError = !!node.selected && node.undone; if (billsError) return billsError; const posRange = !node.children || node.children.length === 0 ? (settlePos.getLedgerPos(node.id) || []) : []; for (const pos of posRange) { if (!!pos.selected && pos.undone) return true; } return false; } }, ], }); searchLedger.spread.refresh(); } } else { tab.removeClass('active'); tabPanel.removeClass('active'); showSideTools(tab.hasClass('active')); } slSpread.refresh(); spSpread.refresh(); }); $.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(); } }); // 加载上下窗口resizer $.divResizer({ select: '#main-resize', callback: function () { slSpread.refresh(); let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0; $(".sp-wrap").height(bcontent-30); spSpread.refresh(); window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); } }); // 工具栏resizer $.divResizer({ select: '#right-spr', callback: function () { slSpread.refresh(); spSpread.refresh(); window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); if (searchLedger) searchLedger.spread.refresh(); } }); // 显示层次 (function (select, sheet) { $(select).click(function () { const tag = $(this).attr('tag'); const tree = sheet.zh_tree; if (!tree) return; 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; } closeWaitingView(); }, 100); }); })('a[name=showLevel]', slSheet); });