block_lib.js 26 KB

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