block_lib.js 27 KB

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