block_lib.js 28 KB

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