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: 45, dataCode: "code", dataType: "String", hAlign: "center"},
  59. {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  60. {headerName: "单位", headerWidth: 40, 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. // Draw Horizontal Line、Image、sibling Vertical Line
  213. if (centerX < x + w) {
  214. // Draw Horizontal Line
  215. drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  216. // Draw Image
  217. let imgId;
  218. if (node.data.type === 0) imgId = 'blockLib_pic'
  219. else if (node.data.type === 1) imgId = 'folder_pic'
  220. else if (node.data.type === 2) {
  221. imgId = 'block_pic';
  222. };
  223. let img = document.getElementById(imgId);
  224. ctx.drawImage(img, centerX+indent/2+3, centerY - 7, imgWidth, imgHeight);
  225. // Draw Vertical Line
  226. y1 = node.isLast() ? centerY : y + h;
  227. if (node.isFirst() && !node.parent/*.parent*/) {
  228. drawLine(ctx, centerX, centerY, centerX, y1, 'gray');
  229. } else {
  230. drawLine(ctx, centerX, y, centerX, y1, 'gray');
  231. }
  232. }
  233. // Draw Expand Box
  234. if (node.children.length > 0) {
  235. drawExpandBox(ctx, x, y, w, h, centerX, centerY, node.expanded);
  236. }
  237. // Draw Parent Line
  238. var curNode = node.parent, parentCenterX = centerX - indent - levelIndent;
  239. while (curNode) {
  240. if (!curNode.isLast()) {
  241. if (parentCenterX < x + w) {
  242. drawLine(ctx, parentCenterX, y, parentCenterX, y + h, 'gray');
  243. }
  244. }
  245. curNode = curNode.parent;
  246. parentCenterX -= (indent + levelIndent);
  247. }
  248. // Draw Text
  249. x = x + (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3;
  250. w = w - (node.depth() + 1) * indent - node.depth() * levelIndent - imgWidth - 3;
  251. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  252. };
  253. TreeCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  254. let info = {x: x, y: y, row: context.row, col: context.col, cellStyle: cellStyle, cellRect: cellRect, sheetArea: context.sheetArea};
  255. let node = tree.items[info.row];
  256. let offset = -1;
  257. let centerX = info.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  258. let text = context.sheet.getText(info.row, info.col);
  259. let value = context.sheet.getValue(info.row, info.col);
  260. let acStyle = context.sheet.getActualStyle(info.row, info.col),
  261. zoom = context.sheet.zoom();
  262. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: context.sheet, row: info.row, col: info.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  263. if(info.x > centerX + halfBoxLength && info.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength){
  264. info.isReservedLocation = true;
  265. }
  266. return info;
  267. };
  268. TreeCell.prototype.processMouseDown = function (hitinfo) {
  269. let offset = -1;
  270. let node = tree.items[hitinfo.row];
  271. let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  272. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  273. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  274. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  275. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  276. zoom = hitinfo.sheet.zoom();
  277. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  278. //(图标+名字)区域
  279. function withingClickArea(){
  280. return hitinfo.x > centerX + halfBoxLength && hitinfo.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength;
  281. }
  282. //方框外1像素内都有效
  283. if (hitinfo.x >= centerX - halfBoxLength - 2 && hitinfo.x <= centerX + halfBoxLength + 2 &&
  284. hitinfo.y >= centerY - halfBoxLength - 2 && hitinfo.y <= centerY + halfBoxLength + 2) {
  285. node.setExpanded(!node.expanded);
  286. TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
  287. let iCount = node.posterityCount(), i, child;
  288. for (i = 0; i < iCount; i++) {
  289. child = tree.items[hitinfo.row + i + 1];
  290. hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
  291. }
  292. hitinfo.sheet.invalidateLayout();
  293. });
  294. hitinfo.sheet.repaint();
  295. }
  296. };
  297. TreeCell.prototype.processMouseMove = function (hitInfo) {
  298. let sheet = hitInfo.sheet;
  299. let div = sheet.getParent().getHost();
  300. let canvasId = div.id + "vp_vp";
  301. /* let canvas = $(`#${canvasId}`)[0];
  302. //改变鼠标图案
  303. if (sheet && hitInfo.isReservedLocation) {
  304. canvas.style.cursor='pointer';
  305. return true;
  306. }else{
  307. canvas.style.cursor='default';
  308. }*/
  309. return false;
  310. };
  311. TreeCell.prototype.processMouseEnter = function (hitinfo) {
  312. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  313. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  314. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  315. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  316. zoom = hitinfo.sheet.zoom();
  317. let node = me.mainTree.items[hitinfo.row];
  318. let nodeIndent = node ? (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3 : 0;
  319. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  320. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  321. if(textLength > cellWidth - nodeIndent){
  322. TREE_SHEET_HELPER.showTipsDiv(text,{pos: {}},hitinfo);
  323. }
  324. };
  325. TreeCell.prototype.processMouseLeave = function (hitinfo) {
  326. let me = this;
  327. TREE_SHEET_HELPER.tipDiv = 'hide';
  328. if (TREE_SHEET_HELPER._toolTipElement) {
  329. $(TREE_SHEET_HELPER._toolTipElement).hide();
  330. TREE_SHEET_HELPER._toolTipElement = null;
  331. };
  332. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  333. };
  334. return new TreeCell();
  335. },
  336. newNode: async function (nodeType, nodeName, categoryID, source){ // 1 分类(只用前两个参数) 2 块文件
  337. if (nodeName == '') return;
  338. let tree = blockLibObj.mainTree;
  339. let ID = uuid.v1();
  340. let pID = (nodeType == 2) ? categoryID : -1;
  341. let nID = -1;
  342. // 先生成临时结点数据用于提交入库,成功后才生成树结点,并在UI上刷新显示。
  343. let temp = {};
  344. temp.data = {
  345. ID: ID,
  346. ParentID: pID,
  347. NextSiblingID: nID,
  348. libID: blockLibObj.activeLib.libID,
  349. type: nodeType,
  350. nodeName: nodeName
  351. };
  352. if (nodeType == 2)
  353. blockLibObj.assignData(temp, source);
  354. try {
  355. let obj = {
  356. libID: blockLibObj.activeLib.libID,
  357. nodeID: temp.data.ID,
  358. create: temp.data
  359. };
  360. await ajaxPost('/blockLib/saveBlock', obj);
  361. let newN = tree.insertByID(ID, pID, nID);
  362. newN.data = temp.data;
  363. tree.selected = newN;
  364. let sheet = blockLibObj.mainSheet;
  365. sheet.suspendPaint();
  366. sheet.suspendEvent();
  367. let idx = tree.items.indexOf(newN);
  368. sheet.addRows(idx, 1);
  369. sheet.getRange(idx, 0, 1, 1).locked(true);
  370. sheet.setValue(idx, 0, newN.data.nodeName);
  371. sheet.setSelection(idx, 0, 1, 1);
  372. sheet.resumeEvent();
  373. sheet.resumePaint();
  374. }
  375. catch (err) {
  376. console.log(err.message);
  377. return;
  378. };
  379. },
  380. assignData: function (block, source){
  381. block.data.compilationID = source.compilationID;
  382. block.data.copyTime = source.copyTime;
  383. block.data.firstNodeType = source.firstNodeType;
  384. block.data.isFBFX = source.isFBFX;
  385. let bill = source.datas[0];
  386. block.data.code = bill.code;
  387. block.data.name = bill.name;
  388. block.data.unit = bill.unit;
  389. block.data.itemCharacterText = bill.itemCharacterText;
  390. block.data.unitFee = (bill.feesIndex && bill.feesIndex.common) ? bill.feesIndex.common.unitFee : 0;
  391. block.data.children = bill.children;
  392. for (let r of bill.children){
  393. r.unitFee = (r.feesIndex && r.feesIndex.common) ? r.feesIndex.common.unitFee : 0;
  394. if (r.programID)
  395. r.programName = projectObj.project.calcProgram.compiledTemplateMaps[r.programID];
  396. // delete r.ID; // 这个不能删!
  397. delete r.billsItemID;
  398. delete r.fees;
  399. delete r.feesIndex;
  400. };
  401. },
  402. reName: async function (node, newName){
  403. if (newName == '') return;
  404. let obj = {
  405. libID: blockLibObj.activeLib.libID,
  406. nodeID: node.data.ID,
  407. update: {nodeName: newName}
  408. };
  409. await ajaxPost('/blockLib/saveBlock', obj);
  410. node.data.nodeName = newName;
  411. let idx = blockLibObj.mainTree.items.indexOf(node);
  412. blockLibObj.mainSheet.setValue(idx, 0, newName);
  413. },
  414. moveBlock: function (parentID) {
  415. // this.mainTreeController.moveTo(parentID);
  416. },
  417. delete: async function () {
  418. let node = blockLibObj.mainTree.selected;
  419. let obj = {
  420. libID: blockLibObj.activeLib.libID,
  421. nodeID: node.data.ID,
  422. delete: {nodeType: node.data.type}
  423. };
  424. await ajaxPost('/blockLib/saveBlock', obj);
  425. this.mainTreeController.delete();
  426. },
  427. getCategories: function () {
  428. let nodes = [], node = blockLibObj.mainTree.items[0];
  429. nodes.push(node);
  430. while (node.nextSibling != null){
  431. node = node.nextSibling;
  432. nodes.push(node);
  433. };
  434. return nodes;
  435. },
  436. curIsBlock: function () {
  437. return this.mainTree.selected.data.type == 2;
  438. },
  439. curIsCategory: function () {
  440. return this.mainTree.selected.data.type == 1;
  441. },
  442. getSameNameNode: function(name){
  443. let rst = null;
  444. let nodes = blockLibObj.mainTree.items;
  445. for (let i = 0; i < nodes.length; i++) {
  446. let node = nodes[i];
  447. if (node.data.nodeName == name){
  448. rst = node;
  449. break;
  450. }
  451. }
  452. return rst;
  453. },
  454. refreshSpread: function (){
  455. if (this.mainSpread)
  456. this.mainSpread.refresh();
  457. if (this.billSpread)
  458. this.billSpread.refresh();
  459. if (this.rationSpread)
  460. this.rationSpread.refresh();
  461. },
  462. loadTreeContextMenu: function (){
  463. let me = this;
  464. $.contextMenu({
  465. selector: '#div_block_tree',
  466. build: function ($trigger, e) {
  467. SheetDataHelper.safeRightClickSelection($trigger, e, me.mainSpread);
  468. me.onEnterCell();
  469. },
  470. items: {
  471. "oneToOneClone": {
  472. name: '一对一克隆',
  473. icon: "fa-stop",
  474. disabled: function () {
  475. let ok = me.curIsBlock() && calcTools.isLeafBill(projectObj.project.mainTree.selected);
  476. return !ok;
  477. },
  478. visible: function(key, opt){
  479. return true;
  480. },
  481. callback: function (key, opt) {
  482. blockLibObj.cloneType = 1;
  483. $("#div_cloneOptions").modal({show: true});
  484. }
  485. },
  486. "oneToMoreClone": {
  487. name: '一对多克隆',
  488. icon: "fa-th-list",
  489. disabled: function () {
  490. let ok = me.curIsBlock() && calcTools.isParentBill(projectObj.project.mainTree.selected);
  491. return !ok;
  492. },
  493. visible: function(key, opt){
  494. return true;
  495. },
  496. callback: function (key, opt) {
  497. blockLibObj.cloneType = 2;
  498. $("#div_cloneOptions").modal({show: true});
  499. }
  500. },
  501. "moreToMoreClone": {
  502. name: '多对多克隆',
  503. icon: "fa-th",
  504. disabled: function () {
  505. let ok = me.curIsCategory() && calcTools.isParentBill(projectObj.project.mainTree.selected);
  506. return !ok;
  507. },
  508. visible: function(key, opt){
  509. return true;
  510. },
  511. callback: function (key, opt) {
  512. blockLibObj.cloneType = 3;
  513. $("#div_cloneOptions").modal({show: true});
  514. }
  515. },
  516. "delete": {
  517. name: '删除',
  518. icon: "delete",
  519. disabled: function () {
  520. },
  521. visible: function(key, opt){
  522. return true;
  523. },
  524. callback: function (key, opt) {
  525. let name = hintBox.fontRed(me.mainTree.selected.data.nodeName);
  526. hintBox.infoBox('操作确认', `确定要删除"${name}"吗?`, 2, function () {
  527. me.delete();
  528. });
  529. }
  530. },
  531. "moveBlock": {
  532. name: '移动模板',
  533. icon: "cut",
  534. disabled: function () {
  535. return true;
  536. },
  537. visible: function(key, opt){
  538. // return me.curIsBlock();
  539. return false;
  540. },
  541. callback: function (key, opt) {
  542. }
  543. }
  544. }
  545. });
  546. },
  547. onEnterCell: function (sender, args) {
  548. let me = blockLibObj;
  549. me.mainTree.selected = me.mainTree.items[me.mainSheet.getActiveRowIndex()];
  550. },
  551. onCellDoubleClick: function (sender, args) {
  552. if (blockLibObj.curIsCategory()) {
  553. hintBox.infoBox('系统提示', `双击是“一对一克隆”,不支持分类操作,请在块文件上双击!`, 1);
  554. return;
  555. }
  556. let projectNode = projectObj.project.mainTree.selected;
  557. if (!calcTools.isLeafBill(projectNode)) {
  558. hintBox.infoBox('系统提示', `双击是“一对一克隆”,请在造价书界面选择最底层的分项/补项/清单进行操作!`, 1);
  559. return;
  560. }
  561. blockLibObj.cloneType = 1;
  562. $("#div_cloneOptions").modal({show: true});
  563. },
  564. oneToOneClone: function (projectNode, block, options) {
  565. let canClone = true;
  566. if (options.checkCode)
  567. canClone = canClone && (projectNode.data.code.substr(0, 9) == block.data.code.substr(0, 9));
  568. if (options.checkName)
  569. canClone = canClone && (projectNode.data.name == block.data.name);
  570. if (options.checkUnit)
  571. canClone = canClone && (projectNode.data.unit == block.data.unit);
  572. if (!canClone) return;
  573. if (options.overwriteRations)
  574. projectObj.project.Bills.deleteChildren(projectNode);
  575. /* 这里封装成伟城的块文件格式,可直接使用伟城的“粘贴块”接口。
  576. 但这里结构要作出调整:忽略叶子清单层,直接从定额开始(跟粘贴块有区别),始终强制在叶子清单下插入定额。
  577. 该操作前提:当前块文件的全部数据已从后台取到前台。 */
  578. let vBlock_WC = {
  579. compilationID: block.data.compilationID,
  580. copyTime: block.data.copyTime,
  581. firstNodeType: 1, // 强制改成1 (因为是从清单下的定额开始。清单自身的还是保留,暂不使用使用)。
  582. isFBFX: block.data.isFBFX,
  583. zeroQuantity: options.zeroQuantity,
  584. datas: block.data.children // rations
  585. };
  586. vBlock_WC = JSON.parse(JSON.stringify(vBlock_WC));
  587. BlockController.confirmPaste(vBlock_WC, projectNode, 'sub');
  588. },
  589. checkShow: async function () { // 这里需要处理异步:模板库装载完再弹出位置选择窗。
  590. if (!$("#kmbk").is(":visible")){ // 如果还没显示
  591. if (!blockLibObj.mainSpread){
  592. await blockLibObj.buildSheet();
  593. };
  594. $('#blockLibTab').click(); // 强制显示
  595. };
  596. $("#div_createBlocks").modal({show: true});
  597. }
  598. };
  599. $(document).ready(function(){ // 这里不需要处理异步:因为不需要弹出位置选择窗。
  600. $('#blockLibTab').on('click', function (){
  601. if ($("#kmbk").is(":visible")){ // 显示状态下
  602. if (!blockLibObj.mainSpread){
  603. blockLibObj.buildSheet();
  604. };
  605. }
  606. });
  607. $('#btn_block_newFolder').on('click', function (){
  608. $('#input_block_newFolder').val('');
  609. });
  610. $('#btn_block_newFolder_add').on('click', function (){
  611. let name = $('#input_block_newFolder').val();
  612. blockLibObj.newNode(1, name);
  613. });
  614. $('#btn_block_reName').on('click', function (){
  615. let select = blockLibObj.mainTree.selected;
  616. $('#input_block_reName').val(select.data.nodeName);
  617. });
  618. $('#btn_block_reName_OK').on('click', function (){
  619. let select = blockLibObj.mainTree.selected;
  620. let oldName = select.data.nodeName;
  621. let newName = $('#input_block_reName').val();
  622. if (oldName != newName) blockLibObj.reName(select, newName);
  623. });
  624. $("#select_block_lib_names").change(function() {
  625. async function getLib(){
  626. let libID = $("#select_block_lib_names").val();
  627. let lib = await ajaxPost('/blockLib/getLib', {libID: libID});
  628. blockLibObj.loadLib(lib);
  629. };
  630. $.bootstrapLoading.start();
  631. getLib();
  632. $.bootstrapLoading.end();
  633. });
  634. });