block_lib.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /**
  2. * 块模板库管理。
  3. * Created by CSL on 2018-09-19.
  4. */
  5. var blockLibObj = {
  6. mainSpread: null,
  7. mainSheet: null,
  8. mainTree: null,
  9. mainTreeController: null,
  10. mainSetting: {
  11. "emptyRowHeader": true,
  12. "rowHeaderWidth": 15,
  13. "emptyRows":0,
  14. "headRows":1,
  15. "headRowHeight":[30],
  16. "defaultRowHeight": 21,
  17. "treeCol": 9,
  18. "cols":[{
  19. "width":400,
  20. "readOnly": true,
  21. "head":{
  22. "titleNames":["名称"],
  23. "spanCols":[1],
  24. "spanRows":[1],
  25. "vAlign":[1],
  26. "hAlign":[1],
  27. "font":["Arial"]
  28. },
  29. "data":{
  30. "field":"nodeName",
  31. "vAlign":1,
  32. "hAlign":0,
  33. "font":"Arial"
  34. }
  35. }]
  36. },
  37. mainDatas: [],
  38. billSpread: null,
  39. billSheet: null,
  40. billSetting: {
  41. header: [
  42. {headerName: "项目编码", headerWidth: 90, dataCode: "code", dataType: "String", hAlign: "center"},
  43. {headerName: "项目名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  44. {headerName: "单位", headerWidth: 40, dataCode: "unit", dataType: "String", hAlign: "center"},
  45. {headerName: "综合单价", headerWidth: 70, dataCode: "unitFee", dataType: "Number"},
  46. {headerName: "项目特征", headerWidth: 160, dataCode: "itemCharacterText", dataType: "String"}
  47. ],
  48. view: {
  49. lockColumns: [0, 1, 2, 3, 4]
  50. }
  51. },
  52. rationSpread: null,
  53. rationSheet: null,
  54. rationSetting: {
  55. header: [
  56. {headerName: "编码", headerWidth: 45, dataCode: "code", dataType: "String", hAlign: "center"},
  57. {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  58. {headerName: "单位", headerWidth: 40, dataCode: "unit", dataType: "String", hAlign: "center"},
  59. {headerName: "含量", headerWidth: 40, dataCode: "contain", dataType: "Number"},
  60. {headerName: "取费专业", headerWidth: 70, dataCode: "programName", dataType: "String", hAlign: "center"},
  61. {headerName: "综合单价", headerWidth: 70, dataCode: "unitFee", dataType: "Number"},
  62. {headerName: "子目换算状态", headerWidth: 90, dataCode: "adjustState", dataType: "String"}
  63. ],
  64. view: {
  65. lockColumns: [0, 1, 2, 3, 4, 5, 6]
  66. }
  67. },
  68. buildSheet: function () {
  69. $.bootstrapLoading.start();
  70. let me = this;
  71. me.mainDatas = [
  72. {ID: 1, ParentID: -1, NextSiblingID: 2, nodeName: '分类1', type: 1},
  73. {ID: 2, ParentID: -1, NextSiblingID: 3, nodeName: '分类2', type: 1},
  74. {ID: 3, ParentID: -1, NextSiblingID: 4, nodeName: '分类3', type: 1},
  75. // {ID: 105, ParentID: 1, NextSiblingID: 106, name: '块1', type: 2},
  76. // {ID: 106, ParentID: 1, NextSiblingID: 107, name: '块2', type: 2},
  77. {ID: 7, ParentID: -1, NextSiblingID: 8, nodeName: '分类7', type: 1},
  78. {ID: 9, ParentID: -1, NextSiblingID: -1, nodeName: '分类9', type: 1}//,
  79. // {ID: 201, ParentID: 52, NextSiblingID: -1, nodeName: '块201', type: 2}
  80. ];
  81. if (me.mainSpread) {
  82. me.mainSpread.destroy();
  83. me.mainSpread = null;
  84. };
  85. if (me.billSpread) {
  86. me.billSpread.destroy();
  87. me.billSpread = null;
  88. };
  89. if (me.rationSpread) {
  90. me.rationSpread.destroy();
  91. me.rationSpread = null;
  92. };
  93. me.mainSpread = SheetDataHelper.createNewSpread($('#div_block_tree')[0]);
  94. // me.mainSpread = TREE_SHEET_HELPER.createNewSpread($('#div_block_tree')[0]);
  95. me.mainSheet = me.mainSpread.getSheet(0);
  96. me.mainSheet.name('blockLibSheet');
  97. sheetCommonObj.spreadDefaultStyle(me.mainSpread);
  98. function showBlockTree(datas) {
  99. me.mainTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
  100. me.mainTreeController = TREE_SHEET_CONTROLLER.createNew(me.mainTree, me.mainSheet, me.mainSetting);
  101. me.mainTree.loadDatas(datas);
  102. me.mainTreeController.showTreeData();
  103. me.mainSheet.getRange(-1, 0, -1, 1).cellType(me.getTreeCell(me.mainTree));
  104. me.mainTree.selected = me.mainTree.items[0];
  105. me.mainTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
  106. blockLibObj.loadDetailDatas(node);
  107. });
  108. };
  109. showBlockTree(me.mainDatas);
  110. me.billSpread = sheetCommonObj.buildSheet($('#div_block_bill')[0], me.billSetting, 1);
  111. me.billSheet = me.billSpread.getSheet(0);
  112. sheetCommonObj.spreadDefaultStyle(me.billSpread);
  113. me.billSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  114. me.rationSpread = sheetCommonObj.buildSheet($('#div_block_ration')[0], me.rationSetting, 1);
  115. me.rationSheet = me.rationSpread.getSheet(0);
  116. sheetCommonObj.spreadDefaultStyle(me.rationSpread);
  117. me.rationSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  118. me.loadTreeContextMenu();
  119. me.mainSpread.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  120. me.mainSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onCellDoubleClick);
  121. $.bootstrapLoading.end();
  122. },
  123. loadDetailDatas: function (node){
  124. let me = this;
  125. if (!node) return;
  126. if (node.data.type == 2){
  127. let bill = node.data;
  128. let rations = bill.children;
  129. sheetCommonObj.showData(me.billSheet, me.billSetting, [bill]);
  130. let rCount = (rations.length > 0) ? rations.length : 1;
  131. me.rationSheet.setRowCount(rCount, GC.Spread.Sheets.SheetArea.viewport);
  132. sheetCommonObj.showData(me.rationSheet, me.rationSetting, rations);
  133. }
  134. else{
  135. sheetCommonObj.cleanSheet(me.billSheet, me.billSetting, 1);
  136. sheetCommonObj.cleanSheet(me.rationSheet, me.rationSetting, 1);
  137. }
  138. },
  139. getTreeCell: function (tree) {
  140. let me = this;
  141. let indent = 20, levelIndent = -5, halfBoxLength = 5, halfExpandLength = 3, imgWidth = 14, imgHeight = 14;
  142. let TreeCell = function () {};
  143. TreeCell.prototype = new GC.Spread.Sheets.CellTypes.Text();
  144. TreeCell.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  145. if (style.backColor) {
  146. ctx.save();
  147. ctx.fillStyle = style.backColor;
  148. ctx.fillRect(x, y, w, h);
  149. ctx.restore();
  150. } else {
  151. ctx.clearRect(x, y, w, h);
  152. };
  153. let drawLine = function (canvas, x1, y1, x2, y2, color) {
  154. ctx.save();
  155. ctx.translate(0.5, 0.5);
  156. ctx.beginPath();
  157. ctx.moveTo(x1, y1);
  158. ctx.lineTo(x2, y2);
  159. ctx.strokeStyle = color;
  160. ctx.stroke();
  161. ctx.restore();
  162. };
  163. let drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
  164. let rect = {}, h1, h2, offset = 1;
  165. rect.top = centerY - halfBoxLength;
  166. rect.bottom = centerY + halfBoxLength;
  167. rect.left = centerX - halfBoxLength;
  168. rect.right = centerX + halfBoxLength;
  169. if (rect.left < x + w) {
  170. rect.right = Math.min(rect.right, x + w);
  171. ctx.save();
  172. ctx.translate(0.5, 0.5);
  173. ctx.strokeStyle = 'black';
  174. ctx.beginPath();
  175. ctx.moveTo(rect.left, rect.top);
  176. ctx.lineTo(rect.left, rect.bottom);
  177. ctx.lineTo(rect.right, rect.bottom);
  178. ctx.lineTo(rect.right, rect.top);
  179. ctx.lineTo(rect.left, rect.top);
  180. ctx.stroke();
  181. ctx.fillStyle = 'white';
  182. ctx.fill();
  183. ctx.restore();
  184. // Draw Horizontal Line
  185. h1 = centerX - halfExpandLength;
  186. h2 = Math.min(centerX + halfExpandLength, x + w);
  187. if (h2 > h1) {
  188. drawLine(ctx, h1, centerY, h2, centerY, 'black');
  189. }
  190. // Draw Vertical Line
  191. if (!expanded && (centerX < x + w)) {
  192. drawLine(ctx, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, 'black');
  193. }
  194. }
  195. };
  196. let node = tree.items[options.row];
  197. if (!node) return;
  198. let showTreeLine = true;
  199. let centerX = Math.floor(x) + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  200. let x1 = centerX + indent / 2;
  201. let centerY = Math.floor((y + (y + h)) / 2);
  202. let y1;
  203. // Draw Horizontal Line、Image、sibling Vertical Line
  204. if (centerX < x + w) {
  205. // Draw Horizontal Line
  206. drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  207. // Draw Image
  208. let imgId;
  209. if (node.data.type === 0) imgId = 'blockLib_pic'
  210. else if (node.data.type === 1) imgId = 'folder_pic'
  211. else if (node.data.type === 2) {
  212. imgId = 'block_pic';
  213. };
  214. let img = document.getElementById(imgId);
  215. ctx.drawImage(img, centerX+indent/2+3, centerY - 7, imgWidth, imgHeight);
  216. // Draw Vertical Line
  217. y1 = node.isLast() ? centerY : y + h;
  218. if (node.isFirst() && !node.parent/*.parent*/) {
  219. drawLine(ctx, centerX, centerY, centerX, y1, 'gray');
  220. } else {
  221. drawLine(ctx, centerX, y, centerX, y1, 'gray');
  222. }
  223. }
  224. // Draw Expand Box
  225. if (node.children.length > 0) {
  226. drawExpandBox(ctx, x, y, w, h, centerX, centerY, node.expanded);
  227. }
  228. // Draw Parent Line
  229. var curNode = node.parent, parentCenterX = centerX - indent - levelIndent;
  230. while (curNode) {
  231. if (!curNode.isLast()) {
  232. if (parentCenterX < x + w) {
  233. drawLine(ctx, parentCenterX, y, parentCenterX, y + h, 'gray');
  234. }
  235. }
  236. curNode = curNode.parent;
  237. parentCenterX -= (indent + levelIndent);
  238. }
  239. // Draw Text
  240. x = x + (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3;
  241. w = w - (node.depth() + 1) * indent - node.depth() * levelIndent - imgWidth - 3;
  242. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  243. };
  244. TreeCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  245. let info = {x: x, y: y, row: context.row, col: context.col, cellStyle: cellStyle, cellRect: cellRect, sheetArea: context.sheetArea};
  246. let node = tree.items[info.row];
  247. let offset = -1;
  248. let centerX = info.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  249. let text = context.sheet.getText(info.row, info.col);
  250. let value = context.sheet.getValue(info.row, info.col);
  251. let acStyle = context.sheet.getActualStyle(info.row, info.col),
  252. zoom = context.sheet.zoom();
  253. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: context.sheet, row: info.row, col: info.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  254. if(info.x > centerX + halfBoxLength && info.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength){
  255. info.isReservedLocation = true;
  256. }
  257. return info;
  258. };
  259. TreeCell.prototype.processMouseDown = function (hitinfo) {
  260. let offset = -1;
  261. let node = tree.items[hitinfo.row];
  262. let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  263. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  264. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  265. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  266. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  267. zoom = hitinfo.sheet.zoom();
  268. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  269. //(图标+名字)区域
  270. function withingClickArea(){
  271. return hitinfo.x > centerX + halfBoxLength && hitinfo.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength;
  272. }
  273. if (hitinfo.x > centerX - halfBoxLength && hitinfo.x < centerX + halfBoxLength && hitinfo.y > centerY - halfBoxLength && hitinfo.y < centerY + halfBoxLength) {
  274. node.setExpanded(!node.expanded);
  275. TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
  276. let iCount = node.posterityCount(), i, child;
  277. for (i = 0; i < iCount; i++) {
  278. child = tree.items[hitinfo.row + i + 1];
  279. hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
  280. }
  281. hitinfo.sheet.invalidateLayout();
  282. });
  283. hitinfo.sheet.repaint();
  284. }
  285. };
  286. TreeCell.prototype.processMouseMove = function (hitInfo) {
  287. let sheet = hitInfo.sheet;
  288. let div = sheet.getParent().getHost();
  289. let canvasId = div.id + "vp_vp";
  290. /* let canvas = $(`#${canvasId}`)[0];
  291. //改变鼠标图案
  292. if (sheet && hitInfo.isReservedLocation) {
  293. canvas.style.cursor='pointer';
  294. return true;
  295. }else{
  296. canvas.style.cursor='default';
  297. }*/
  298. return false;
  299. };
  300. TreeCell.prototype.processMouseEnter = function (hitinfo) {
  301. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  302. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  303. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  304. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  305. zoom = hitinfo.sheet.zoom();
  306. let node = me.mainTree.items[hitinfo.row];
  307. let nodeIndent = node ? (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3 : 0;
  308. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  309. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  310. if(textLength > cellWidth - nodeIndent){
  311. TREE_SHEET_HELPER.showTipsDiv(text,{pos: {}},hitinfo);
  312. }
  313. };
  314. TreeCell.prototype.processMouseLeave = function (hitinfo) {
  315. let me = this;
  316. TREE_SHEET_HELPER.tipDiv = 'hide';
  317. if (TREE_SHEET_HELPER._toolTipElement) {
  318. $(TREE_SHEET_HELPER._toolTipElement).hide();
  319. TREE_SHEET_HELPER._toolTipElement = null;
  320. };
  321. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  322. };
  323. return new TreeCell();
  324. },
  325. newNode: function (nodeType, nodeName, categoryID, source){ // 1 分类(只用前两个参数) 2 块文件
  326. let tree = blockLibObj.mainTree;
  327. let pID = -1, nID = -1;
  328. let select = tree.selected;
  329. if (nodeType == 1){
  330. if (!select) {
  331. nID = -1;
  332. }
  333. else if (select.data.type == 1){
  334. nID = select.getNextSiblingID();
  335. }
  336. else if (select.data.type == 2){
  337. nID = select.parent.getNextSiblingID();
  338. };
  339. }
  340. else if (nodeType == 2) {
  341. pID = categoryID;
  342. nID = -1;
  343. }
  344. let newNode = tree.insert(pID, nID);
  345. newNode.data.type = nodeType;
  346. newNode.data.nodeName = nodeName;
  347. if (nodeType == 2){
  348. let bill = source.datas[0];
  349. newNode.data.compilationID = source.compilationID;
  350. newNode.data.copyTime = source.copyTime;
  351. newNode.data.firstNodeType = source.firstNodeType;
  352. newNode.data.isFBFX = source.isFBFX;
  353. newNode.data.code = bill.code;
  354. newNode.data.name = bill.name;
  355. newNode.data.unit = bill.unit;
  356. newNode.data.itemCharacterText = bill.itemCharacterText;
  357. newNode.data.unitFee = (bill.feesIndex && bill.feesIndex.common) ? bill.feesIndex.common.unitFee : 0;
  358. newNode.data.children = bill.children;
  359. for (let r of bill.children){
  360. r.unitFee = (r.feesIndex && r.feesIndex.common) ? r.feesIndex.common.unitFee : 0;
  361. if (r.programID)
  362. r.programName = projectObj.project.calcProgram.compiledTemplateMaps[r.programID];
  363. // delete r.ID; // 这个不能删!
  364. delete r.billsItemID;
  365. delete r.fees;
  366. delete r.feesIndex;
  367. };
  368. }
  369. tree.selected = newNode;
  370. let sheet = blockLibObj.mainSheet;
  371. sheet.suspendPaint();
  372. sheet.suspendEvent();
  373. let idx = tree.items.indexOf(newNode);
  374. sheet.addRows(idx, 1);
  375. sheet.getRange(idx, 0, 1, 1).locked(true);
  376. sheet.setValue(idx, 0, newNode.data.nodeName);
  377. sheet.setSelection(idx, 0, 1, 1);
  378. sheet.resumeEvent();
  379. sheet.resumePaint();
  380. },
  381. reName: function (node, newName){
  382. if (newName == '') return;
  383. node.data.nodeName = newName;
  384. let idx = blockLibObj.mainTree.items.indexOf(node);
  385. blockLibObj.mainSheet.setValue(idx, 0, newName);
  386. },
  387. moveBlock: function (parentID) {
  388. // this.mainTreeController.moveTo(parentID);
  389. },
  390. delete: function () {
  391. this.mainTreeController.delete();
  392. },
  393. getCategories: function () {
  394. let nodes = [], node = blockLibObj.mainTree.items[0];
  395. nodes.push(node);
  396. while (node.nextSibling != null){
  397. node = node.nextSibling;
  398. nodes.push(node);
  399. };
  400. return nodes;
  401. },
  402. curIsBlock: function () {
  403. return this.mainTree.selected.data.type == 2;
  404. },
  405. curIsCategory: function () {
  406. return this.mainTree.selected.data.type == 1;
  407. },
  408. refreshSpread: function (){
  409. if (this.mainSpread)
  410. this.mainSpread.refresh();
  411. if (this.billSpread)
  412. this.billSpread.refresh();
  413. if (this.rationSpread)
  414. this.rationSpread.refresh();
  415. },
  416. loadTreeContextMenu: function (){
  417. let me = this;
  418. $.contextMenu({
  419. selector: '#div_block_tree',
  420. build: function ($trigger, e) {
  421. SheetDataHelper.safeRightClickSelection($trigger, e, me.mainSpread);
  422. me.onEnterCell();
  423. },
  424. items: {
  425. "oneToOneClone": {
  426. name: '一对一克隆',
  427. icon: "fa-battery-empty",
  428. disabled: function () {
  429. let ok = me.curIsBlock() && calcTools.isLeafBill(projectObj.project.mainTree.selected);
  430. return !ok;
  431. },
  432. visible: function(key, opt){
  433. return true;
  434. },
  435. callback: function (key, opt) {
  436. me.onCellDoubleClick();
  437. }
  438. },
  439. "oneToMoreClone": {
  440. name: '一对多克隆',
  441. icon: "fa-battery-half",
  442. disabled: function () {
  443. let ok = me.curIsBlock() && calcTools.isParentBill(projectObj.project.mainTree.selected);
  444. return !ok;
  445. },
  446. visible: function(key, opt){
  447. return true;
  448. },
  449. callback: function (key, opt) {
  450. }
  451. },
  452. "moreToMoreClone": {
  453. name: '多对多克隆',
  454. icon: "fa-battery-full",
  455. disabled: function () {
  456. let ok = me.curIsCategory() && calcTools.isParentBill(projectObj.project.mainTree.selected);
  457. return !ok;
  458. },
  459. visible: function(key, opt){
  460. return true;
  461. },
  462. callback: function (key, opt) {
  463. }
  464. },
  465. "delete": {
  466. name: '删除',
  467. icon: "delete",
  468. disabled: function () {
  469. },
  470. visible: function(key, opt){
  471. return true;
  472. },
  473. callback: function (key, opt) {
  474. let name = hintBox.fontRed(me.mainTree.selected.data.nodeName);
  475. hintBox.infoBox('操作确认', `确定要删除"${name}"吗?`, 2, function () {
  476. me.delete();
  477. });
  478. }
  479. },
  480. "moveBlock": {
  481. name: '移动模板',
  482. icon: "cut",
  483. disabled: function () {
  484. return true;
  485. },
  486. visible: function(key, opt){
  487. // return me.curIsBlock();
  488. return false;
  489. },
  490. callback: function (key, opt) {
  491. }
  492. }
  493. }
  494. });
  495. },
  496. onEnterCell: function (sender, args) {
  497. let me = blockLibObj;
  498. me.mainTree.selected = me.mainTree.items[me.mainSheet.getActiveRowIndex()];
  499. },
  500. onCellDoubleClick: function (sender, args) {
  501. let projectNode = projectObj.project.mainTree.selected;
  502. if (!calcTools.isLeafBill(projectNode)) return;
  503. $("#blockAdjustOptions").modal({show: true});
  504. },
  505. oneToOneClone: function (projectNode, block) {
  506. // 这里再次封装成伟城的块文件格式,可直接使用伟城的“粘贴块”接口。
  507. // 这里结构作出调整:忽略叶子清单层,直接从定额开始(跟粘贴块有区别),始终强制在叶子清单下插入定额。
  508. // 该操作前提:当前块文件的全部数据已从后台取到前台。
  509. let vBlock_WC = {
  510. compilationID: block.data.compilationID,
  511. copyTime: block.data.copyTime,
  512. firstNodeType: 1, // 强制改成1 (因为是从清单下的定额开始。清单自身的还是保留,暂不使用使用)。
  513. isFBFX: block.data.isFBFX,
  514. datas: block.data.children // rations
  515. };
  516. BlockController.confirmPaste(vBlock_WC, projectNode, 'sub');
  517. },
  518. oneToMoreCloneXX: function () {
  519. //
  520. }
  521. };
  522. $(document).ready(function(){
  523. $('#blockLibTab').on('click', function (){
  524. if ($("#kmbk").is(":visible")){
  525. if (!blockLibObj.mainSpread){
  526. blockLibObj.buildSheet();
  527. };
  528. }
  529. });
  530. $('#btn_block_newFolder').on('click', function (){
  531. $('#input_block_newFolder').val('');
  532. });
  533. $('#btn_block_newFolder_add').on('click', function (){
  534. let name = $('#input_block_newFolder').val();
  535. if (name != '') blockLibObj.newNode(1, name);
  536. });
  537. $('#btn_block_reName').on('click', function (){
  538. let select = blockLibObj.mainTree.selected;
  539. $('#input_block_reName').val(select.data.nodeName);
  540. });
  541. $('#btn_block_reName_OK').on('click', function (){
  542. let select = blockLibObj.mainTree.selected;
  543. let oldName = select.data.nodeName;
  544. let newName = $('#input_block_reName').val();
  545. if (oldName != newName) blockLibObj.reName(select, newName);
  546. });
  547. });