block_lib.js 26 KB

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