block_lib.js 27 KB

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