block_lib.js 27 KB

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