12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301 |
- 'use strict';
- /**
- * 台账修订页面js
- *
- * @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 = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
- const posSheet = posSpread.getActiveSheet();
- SpreadJsObj.initSheet(posSheet, posSpreadSetting);
- $.subMenu({
- menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
- toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
- key: 'revise.info.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();
- posSpread.refresh();
- }
- });
- const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
- // 初始化 清单树结构
- 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 = {
- 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 sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return;
- const first = sheet.zh_tree.nodes[row];
- let last = first, sameParent = true;
- if (sel.rowCount > 1) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- 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 = !sheet.zh_setting.readOnly;
- setObjEnable($('#insert'), valid && first && first.level > 1);
- setObjEnable($('#delete'), valid && first && sameParent && first.level > 1);
- setObjEnable($('#up-move'), valid && first && sameParent && first.level > 1 && preNode);
- setObjEnable($('#down-move'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
- if (isTz) {
- const posRange = last ? pos.getLedgerPos(last.id) : [];
- setObjEnable($('#up-level'), valid && first && sameParent && tree.getParent(first) && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
- const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
- setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
- } else {
- setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
- setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
- }
- setObjEnable($('#cut'), valid);
- setObjEnable($('#paste'), valid);
- },
- /**
- *
- * @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) {
- billsTreeSpreadObj.refreshOperationValid(info.sheet);
- posSpreadObj.loadCurPosData();
- SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
- posSearch.search($('#pos-keyword').val());
- }
- },
- /**
- * 新增节点
- * @param spread
- */
- baseOpr: function (sheet, type) {
- const self = this;
- const [tree, node, count] = this.getDefaultSelectInfo(sheet);
- if (!tree || !node || !count) return;
- if (type === 'delete') {
- const parent = tree.getParent(node);
- const children = parent ? parent.children : tree.children;
- const index = children.indexOf(node);
- for (let i = 0; i < count; i++) {
- const child = children[i+index];
- if (tree.checkNodeUsed(child, pos)) {
- toastr.warning('选中的清单已计量,不可删除');
- return;
- }
- }
- } else if (type === 'up-level') {
- const parent = tree.getParent(node);
- const children = parent ? parent.children : tree.children;
- const index = children.indexOf(node);
- for (let i = index; i < children.length; i++) {
- const child = children[index];
- if (tree.checkNodeUsed(child, pos)) {
- if (i >= index + count) {
- toastr.warning('其后清单已计量,选中的清单不可升级');
- } else {
- toastr.warning('选中的清单已计量,不可升级');
- }
- return;
- }
- }
- } else if (type === 'down-level') {
- const parent = tree.getParent(node);
- const children = parent ? parent.children : tree.children;
- const index = children.indexOf(node);
- for (let i = 0; i < count; i++) {
- const child = children[i+index];
- if (tree.checkNodeUsed(child, pos)) {
- toastr.warning('选中的清单已计量,不可降级');
- return;
- }
- }
- }
- postData(window.location.pathname + '/update', {
- postType: type,
- postData: {
- id: node.ledger_id,
- count: count,
- }
- }, function (result) {
- const refreshData = tree.loadPostData(result);
- self.refreshTree(sheet, refreshData);
- if (type === 'delete') {
- const sel = sheet.getSelections()[0];
- if (sel) {
- sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
- }
- } else 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);
- }
- } 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);
- }
- }
- self.refreshOperationValid(sheet);
- });
- },
- /**
- * 编辑单元格响应事件
- * @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_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row];
- const data = {
- id: node.id,
- tender_id: node.tender_id,
- ledger_id: node.ledger_id
- };
- // 未改变值则不提交
- const orgValue = node[col.field];
- if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (info.editingText === ''))) {
- return;
- }
- // 台账模式,检查部位明细相关
- if (isTz) {
- if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
- col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
- col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
- if (!node.children || node.children.length ===0) {
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- toastr.error('清单含有部位明细,不可修改施工图复核数量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- toastr.error('清单含有部位明细,请先删除部位明细,再删除清单编号');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- // 获取更新数据
- if (info.editingText) {
- data[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText.replace('\n', '');
- } else {
- data[col.field] = null;
- }
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
- const refreshNode = billsTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
- });
- }
- },
- clipboardPasting: function (e, info) {
- if (info.sheet.zh_setting) {
- const range = info.cellRange;
- for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
- const node = info.sheet.zh_tree.nodes[iRow];
- if (info.sheet.zh_tree.checkNodeUsed(node, pos)) {
- toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
- info.cancel = true;
- return;
- }
- }
- }
- },
- clipboardPasted: function (e, info) {
- const tree = info.sheet.zh_tree;
- if (!tree) { return; }
- const sortData = info.sheet.zh_tree.nodes;
- const datas = [], filterNodes = [];
- let bHint = false, bPaste;
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
- bPaste = false;
- const curRow = info.cellRange.row + iRow;
- const node = sortData[curRow];
- if (node) {
- 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 = info.sheet.getText(curRow, curCol).replace('\n', '');
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- if (value === '' && colSetting.field === 'b_code') {
- if (!bHint) {
- toastr.warning('清单含有部位明细,请先删除部位明细,再删除清单编号');
- bHint = true;
- }
- continue;
- }
- if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
- colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
- colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
- if (!bHint) {
- toastr.warning('清单含有部位明细,数量金额根据部位明细汇总计算所得,不可编辑');
- bHint = true;
- }
- continue;
- }
- }
- 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);
- }
- billsTreeSpreadObj.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) {
- if (!sheet.zh_setting) return;
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const node = sheet.zh_tree.nodes[iRow];
- if (sheet.zh_tree.checkNodeUsed(node, pos)) {
- toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
- return;
- }
- const data = sheet.zh_tree.getNodeKeyData(node);
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- data[col.field] = null;
- }
- datas.push(data);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- const refreshNode = sheet.zh_tree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(sheet, refreshNode);
- });
- }
- },
- pasteBlock: function (spread, copyInfo) {
- const self = this;
- const sheet = spread.getActiveSheet();
- const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
- postData(window.location.pathname + '/update', {
- postType: 'paste-block',
- postData: {
- id: tree.getNodeKey(node),
- tid: copyInfo.tid,
- block: copyInfo.block,
- }
- }, function (data) {
- pos.updateDatas(data.pos);
- const result = tree.loadPostData(data.ledger);
- self.refreshTree(sheet, result);
- self.refreshOperationValid(sheet);
- removeLocalCache(copyBlockTag);
- }, null, true);
- },
- topRowChanged: function (e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
- },
- };
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
- billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
- if (!readOnly) {
- // 增删上下移升降级
- $('a[name="base-opr"]').click(function () {
- billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
- });
- billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
- billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
- billsSpread.bind(spreadNS.Events.ClipboardPasted, billsTreeSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
- let batchInsertObj;
- // 右键菜单
- $.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: {
- 'batchInsertBillsPos': {
- name: '批量插入清单-部位',
- icon: 'fa-sign-in',
- disabled: function (key, opt) {
- const select = SpreadJsObj.getSelectObject(billsSheet);
- if (select) {
- if (select.code && select.code !== '') {
- return !billsTree.isLeafXmj(select);
- } else {
- const parent = billsTree.getParent(select);
- return !(parent && billsTree.isLeafXmj(parent));
- }
- } else {
- return false;
- }
- },
- callback: function (key, opt) {
- if (!batchInsertObj) {
- batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
- } else {
- batchInsertObj.initView();
- }
- $('#batch').modal('show');
- }
- },
- 'debug': {
- name: 'debug',
- callback: function (key, opt) {
- console.log(SpreadJsObj.getSelectObject(billsSheet));
- }
- }
- }
- });
- }
- 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);
- },
- editStarting: function (e, info) {
- posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
- },
- /**
- * 编辑单元格响应事件
- * @param {Object} e
- * @param {Object} info
- */
- editEnded: function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- const col = info.sheet.zh_setting.cols[info.col];
- const orgText = posData ? posData[col.field] : null;
- const newText = info.sheet.getCell(info.row, info.col).text();
- if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
- const node = posSpreadObj.billsNode;
- if (!node) {
- toastr.error('数据错误,请选择台账节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (newText && newText !== '' && node.children && node.children.length > 0) {
- toastr.error('父节点不可插入部位明细');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
- toastr.error('项目节不可插入部位明细');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const data = {postType: 'pos'};
- if (col.field === 'name') {
- if (newText === '' && posData) {
- toastr.error('部位名称不可为空', 'error');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (!posData) {
- if (newText && newText !== '') {
- data.posPostType = 'add';
- const sortData = info.sheet.zh_data;
- const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
- data.postData = { name: newText, lid: node.id, porder: order};
- } else {
- return;
- }
- } else {
- data.posPostType = 'update-pos';
- data.postData = {id: posData.id, name: newText};
- }
- } else if (!posData) {
- toastr.warning('新增部位请先输入名称');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else {
- data.posPostType = 'update';
- data.postData = {id: posData.id};
- data.postData[col.field] = col.type === 'Number' ? parseFloat(newText) : newText;
- }
- postData(window.location.pathname + '/update', data, function (result) {
- const updateRst = pos.updateDatas(result.pos);
- // 刷新当前行, 不适用于新增(在非下一空白行新增)
- if (updateRst.create.length > 0) {
- posSpreadObj.loadCurPosData();
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }
- const loadResult = billsTree.loadPostData(result.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- },
- /**
- * 删除按钮响应事件
- * @param sheet
- */
- deletePress: function (sheet) {
- if (!sheet.zh_settting) return;
- const sortData = sheet.zh_data;
- const datas = [], posSelects = [];
- const sel = sheet.getSelections()[0];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sortData[iRow];
- if (node) {
- const data = {id: node.id};
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (colSetting.field === 'name') {
- toastr.error('部位名称不能为空');
- return;
- }
- const style = sheet.getStyle(iRow, iCol);
- if (!style.locked) {
- const colSetting = sheet.zh_setting.cols[iCol];
- data[colSetting.field] = null;
- bDel = true;
- }
- }
- if (bDel) {
- datas.push(data);
- posSelects.push(node);
- }
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
- pos.updateDatas(result.pos);
- posSpreadObj.loadCurPosData();
- const loadResult = billsTree.loadPostData(result.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- }, function () {
- posSpreadObj.loadCurPosData();
- });
- }
- },
- /**
- * 删除 部位明细
- * @param sheet
- */
- deletePos: function (sheet) {
- const selection = sheet.getSelections();
- const data = {
- postType: 'pos',
- posPostType: 'delete',
- postData: [],
- };
- const row = selection[0].row, count = selection[0].rowCount;
- const sortData = sheet.zh_data;
- for (let iRow = 0; iRow < count; iRow++) {
- const posData = sortData[iRow + row];
- if (posData) {
- if (posData.used) {
- toastr.error('"' + posData.name + '"已计量,请勿删除');
- return;
- }
- data.postData.push(sortData[iRow + row].id);
- }
- }
- if (data.postData.length > 0) {
- postData(window.location.pathname + '/update', data, function (result) {
- pos.removeDatas(result.pos);
- sheet.deleteRows(row, count);
- const loadResult = billsTree.loadPostData(result.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- });
- }
- },
- clipboardPasting: function (e, info) {
- if (!info.sheet.zh_setting) {
- info.cancel = true;
- return;
- }
- const range = info.cellRange;
- for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
- const posData = info.sheet.zh_data[iRow];
- if (posData && posData.used) {
- toastr.warning('"' + pos.name +'"已计量,请勿修改');
- info.cancel = true;
- return;
- }
- }
- },
- /**
- * 粘贴单元格响应事件
- * @param e
- * @param info
- */
- clipboardPasted: function (e, info) {
- const node = SpreadJsObj.getSelectObject(billsSheet);
- if (node.code && (node.code !== '')) {
- toastr.error('项目节不可含有清单明细');
- posSpreadObj.loadCurPosData();
- return;
- }
- if (node.children && (node.children.length > 0)) {
- toastr.error('仅清单子项可以含有部位明细');
- posSpreadObj.loadCurPosData();
- return;
- }
- if (!info.sheet.zh_setting) {
- posSpreadObj.loadCurPosData();
- return;
- }
- const data = [];
- const sortData = info.sheet.zh_data || [];
- if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
- if (info.cellRange.col !== 0) {
- toast('新增部位请先输入名称', 'warning');
- posSpreadObj.loadCurPosData();
- return;
- }
- }
- const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = info.cellRange.row + iRow;
- const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- posData[colSetting.field] = info.sheet.getText(curRow, curCol);
- if (colSetting.type === 'Number') {
- posData[colSetting.field] = _.toNumber(posData[colSetting.field]);
- }
- }
- data.push(posData);
- }
- postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
- pos.updateDatas(result.pos);
- posSpreadObj.loadCurPosData();
- const loadResult = billsTree.loadPostData(result.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- posSpreadObj.loadCurPosData();
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- });
- },
- };
- posSpreadObj.loadCurPosData();
- SpreadJsObj.resetTopAndSelect(posSheet);
- if (!readOnly) {
- posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
- posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
- posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
- posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
- $.contextMenu({
- selector: '#pos-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'delete': {
- name: '删除',
- icon: 'fa-remove',
- disabled: function (key, opt) {
- if (posSheet.zh_data) {
- const selection = posSheet.getSelections();
- return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
- } else {
- return true;
- }
- },
- callback: function (key, opt) {
- posSpreadObj.deletePos(posSheet);
- }
- },
- 'debug': {
- name: 'debug',
- callback: function (key, opt) {
- console.log(SpreadJsObj.getSelectObject(posSheet));
- }
- }
- }
- });
- }
- $.divResizer({
- select: '#revise-resize',
- callback: function () {
- billsSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-40);
- posSpread.refresh();
- }
- });
- class stdLib {
- constructor(selector, stdType, treeSetting, spreadSetting) {
- const self = this;
- this.obj = $(selector + '-spread')[0];
- this.stdType = stdType;
- this.treeSetting = treeSetting;
- treeSetting.preUrl = this.url;
- this.spreadSetting = spreadSetting;
- this.spread = SpreadJsObj.createNewSpread(this.obj);
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- if (!readOnly) {
- this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
- const stdSheet = info.sheet;
- const mainSheet = billsSheet;
- if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
- const stdTree = stdSheet.zh_tree;
- const stdNode = stdTree.nodes[info.row];
- const mainTree = mainSheet.zh_tree;
- const sel = mainSheet.getSelections()[0];
- const mainNode = mainTree.nodes[sel.row];
- if (!stdNode) return;
- if (stdType === 'bills') {
- if (!(mainNode.code && mainNode.code !== '') && !mainTree.isLeafXmj(mainNode)) {
- toastr.warning('非最底层项目下,不应添加清单');
- return;
- }
- }
- postData(window.location.pathname + '/update', {
- postType: 'add-std',
- postData: {
- id: mainTree.getNodeKey(mainNode),
- tender_id: mainNode.tender_id,
- stdType: stdType,
- stdLibId: stdNode.list_id,
- stdNode: stdTree.getNodeKey(stdNode)
- }
- }, function (result) {
- const refreshNode = mainTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
- if (sel && refreshNode.create[0]) {
- mainSheet.setSelection(mainTree.nodes.indexOf(refreshNode.create[0]), sel.col, sel.rowCount, sel.colCount);
- }
- billsTreeSpreadObj.refreshOperationValid(mainSheet);
- });
- });
- }
- this.pathTree = createNewPathTree('base', this.treeSetting);
- this.cacheLib = [];
- $('select', selector).change(function () {
- self.loadLib(parseInt(this.value));
- });
- }
- loadLib (listId) {
- const cacheData = this.cacheLib.find(function (lib) {
- return lib.id === listId;
- });
- if (cacheData) {
- this.pathTree.loadDatas(cacheData.data);
- SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'tree', this.pathTree);
- } else {
- const self = this;
- postData('/std-lib/get-data', {stdType: this.stdType, list_id: listId}, function (data) {
- self.cacheLib.push({id: listId, data: data});
- self.pathTree.loadDatas(data);
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
- });
- }
- }
- }
- class DealBills {
- constructor (selector, spreadSetting) {
- const self = this;
- this.loaded = false;
- this.obj = $(selector)[0];
- this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
- this.spreadSetting = spreadSetting;
- this.spread = SpreadJsObj.createNewSpread(this.obj);
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- if (!readOnly) {
- this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const dealSheet = info.sheet;
- const mainSheet = ledgerSpread.getActiveSheet();
- const dealBills = SpreadJsObj.getSelectObject(dealSheet);
- if (!dealBills) { return; }
- const mainTree = mainSheet.zh_tree;
- const mainNode = SpreadJsObj.getSelectObject(mainSheet);
- if (!mainNode || !mainTree) { return; }
- if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
- toastr.warning('非最底层项目下,不应添加清单');
- return;
- }
- postData(window.location.pathname + '/update', {
- postType: 'add-deal',
- postData: {
- id: mainNode.ledger_id,
- type: mainNode.code ? 'child' : 'next',
- dealBills: {
- b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
- unit_price: dealBills.unit_price,
- }
- },
- }, function (result) {
- const refreshData = mainTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
- const sel = mainSheet.getSelections()[0];
- if (sel && refreshData.create[0]) {
- mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
- }
- billsTreeSpreadObj.refreshOperationValid(mainSheet);
- });
- });
- }
- SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
- }
- loadData () {
- if (this.loaded) return;
- const self = this;
- postData(this.url+'/get-data', {}, function (data) {
- self.data = data;
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
- self.loaded = true;
- });
- }
- calculateData () {
- if (this.data) {
- for (const d of this.data) {
- d.total_price = _.multiply(d.quantity, d.unit_price);
- }
- }
- }
- }
- class BatchInsertBillsPosObj {
- constructor (obj) {
- const self = this;
- this.obj = obj;
- this.billsCount = 6;
- this.posCount = 1000;
- // 初始化 清单编号窗口 参数
- this.qdSpreadSetting = {
- cols: [
- {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
- ],
- emptyRows: this.billsCount,
- headRows: 1,
- headRowHeight: [40],
- };
- this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
- // 初始化 部位数量复核表 参数
- this.posSpreadSetting = {
- cols: [
- {title: '部位', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
- {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
- ],
- emptyRows: this.posCount,
- headRows: 1,
- headRowHeight: [40],
- };
- for (let iNum = 1; iNum <= this.billsCount; iNum++) {
- this.posSpreadSetting.cols.push(
- {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
- )
- }
- this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
- // 初始化 签约清单 参数
- this.dealSpreadSetting = {
- cols: [
- {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
- {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
- {title: '单价', field: 'unit_price', width: 50, readOnly: true},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- };
- this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
- // 初始化 清单编号、部位数量复核表 表格
- this.initView();
- SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
- SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
- // 拉取签约清单数据
- dealBills.loadData();
- SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
- // 双击签约清单,自动添加到清单编号窗口
- this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
- const deal = info.sheet.zh_data[info.row];
- const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
- const sel = qdSheet.getSelections()[0];
- qdSheet.getCell(sel.row, 0).value(deal.code);
- qdSheet.getCell(sel.row, 1).value(deal.name);
- qdSheet.getCell(sel.row, 2).value(deal.unit);
- qdSheet.getCell(sel.row, 3).value(deal.unit_price);
- if (sel.row + 1 === qdSheet.getRowCount()) {
- const count = sel.row + 2;
- qdSheet.setRowCount(count);
- qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
- const colCount = posSheet.getColumnCount() + 1
- posSheet.setColumnCount(colCount);
- posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
- }
- qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
- });
- this.obj.bind('shown.bs.modal', function () {
- self.qdSpread.refresh();
- self.posSpread.refresh();
- self.dealSpread.refresh();
- });
- $('#batch-ok').click(function () {
- const selection = billsSheet.getSelections();
- const row = selection[0].row;
- const select = billsTree.nodes[row];
- if (select) {
- const insertData = {};
- insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
- insertData.id = select[billsTree.setting.id];
- insertData.batchData = self.getBatchData();
- postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
- pos.updateDatas(data.pos);
- const result = billsTree.loadPostData(data.ledger);
- billsTreeSpreadObj.refreshTree(sheet, result);
- billsTreeSpreadObj.refreshOperationValid(sheet, selection);
- self.obj.modal('hide');
- }, null, true);
- }
- });
- }
- // 初始化左侧表格
- initView () {
- // 初始化 清单编号
- const qdSheet = this.qdSpread.getActiveSheet();
- SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
- SpreadJsObj.refreshColumnAlign(qdSheet);
- // 清理原有数据
- SpreadJsObj.beginMassOperation(qdSheet);
- qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- for (let iRow = 1; iRow <= this.billsCount; iRow++) {
- qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
- }
- qdSheet.setSelection(0, 0, 1 ,1);
- SpreadJsObj.endMassOperation(qdSheet);
- // 初始化 部位数量复核表
- const posSheet = this.posSpread.getActiveSheet();
- SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
- SpreadJsObj.refreshColumnAlign(posSheet);
- // 清理原有数据
- SpreadJsObj.beginMassOperation(posSheet);
- posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
- posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- posSheet.setSelection(0, 0, 1 ,1);
- SpreadJsObj.endMassOperation(posSheet);
- // 检查签约清单数据,以工具栏数据为准
- if (dealBills) {
- SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
- }
- this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
- }
- // 获取界面数据
- getBatchData () {
- const result = [];
- const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
- for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
- if (qdSheet.getText(iRow, 0) === '') { continue; }
- const qd = {
- b_code: qdSheet.getText(iRow, 0),
- name: qdSheet.getText(iRow, 1),
- unit: qdSheet.getText(iRow, 2),
- price: _.toNumber(qdSheet.getText(iRow, 3)),
- pos: [],
- };
- result.push(qd);
- for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
- const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
- if (value !== 0 && !isNaN(value)) {
- qd.pos.push({
- name: posSheet.getText(iPosRow, 0),
- drawing_code: posSheet.getText(iPosRow, 1),
- quantity: value,
- });
- }
- }
- }
- return result;
- }
- }
- let stdXmj, stdGcl, searchLedger;
- const dealBills = new DealBills('#deal-bills-spread', {
- cols: [
- {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
- {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
- {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
- {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- });
- $.divResizer({
- select: '#revise-right-spr',
- callback: function () {
- billsSpread.refresh();
- if (posSpread) {
- posSpread.refresh();
- }
- if (stdXmj) {
- stdXmj.spread.refresh();
- }
- if (stdGcl) {
- stdGcl.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') === '#std-xmj') {
- if (!stdXmj) {
- stdXmj = new stdLib('#std-xmj', 'xmj', {
- id: 'chapter_id',
- pid: 'pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'list_id', 'chapter_id'],
- }, {
- cols: [
- {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
- {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
- ],
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- });
- stdXmj.loadLib($('select', '#std-xmj').val());
- }
- stdXmj.spread.refresh();
- } else if (tab.attr('content') === '#std-gcl') {
- if (!stdGcl) {
- stdGcl = new stdLib('#std-gcl', 'gcl', {
- id: 'bill_id',
- pid: 'pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'list_id', 'bill_id']
- }, {
- cols: [
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
- {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
- ],
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- });
- stdGcl.loadLib($('select', '#std-gcl').val());
- }
- stdGcl.spread.refresh();
- } else if (tab.attr('content') === '#deal-bills') {
- dealBills.loadData();
- dealBills.spread.refresh();
- } else 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();
- }
- });
- if (!readOnly) {
- // 修订详情 保存
- $('#save').click(function () {
- const content = $('textarea').val();
- postData('save', { content: content });
- });
- }
- // 显示层次
- (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);
- });
|