tree_sheet_helper.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var TREE_SHEET_HELPER = {
  5. getObjPos: function (obj) {
  6. let target = obj;
  7. let pos = {x: obj.offsetLeft, y: obj.offsetTop};
  8. target = obj.offsetParent;
  9. while (target) {
  10. pos.x += target.offsetLeft;
  11. pos.y += target.offsetTop;
  12. target = target.offsetParent;
  13. }
  14. return pos;
  15. },
  16. /**
  17. * 初始化setting,需要提示单元格text时,必须先初始化setting
  18. * @param obj
  19. * @param setting
  20. */
  21. /*initSetting: function (obj, setting) {
  22. setting.pos = this.getObjPos(obj);
  23. },*/
  24. initSetting: function (obj, setting) {
  25. setting.pos = this.getObjPos(obj);
  26. },
  27. createNewSpread: function (obj) {
  28. var spread = new GC.Spread.Sheets.Workbook(obj, {sheetCount: 1});
  29. spread.options.tabStripVisible = false;
  30. spread.options.scrollbarMaxAlign = true;
  31. spread.options.cutCopyIndicatorVisible = false;
  32. spread.options.allowCopyPasteExcelStyle = false;
  33. spread.options.allowUserDragDrop = false;
  34. spread.getActiveSheet().setRowCount(3);
  35. return spread;
  36. },
  37. getSheetCellStyle: function (setting) {
  38. var style = new GC.Spread.Sheets.Style();
  39. //style.locked = setting.readOnly ? true : false;
  40. style.name = setting.id;
  41. //style.font = setting.data.font;
  42. style.hAlign = setting.data.hAlign;
  43. style.vAlign = setting.data.vAlign;
  44. style.wordWrap = setting.data.wordWrap;
  45. if (setting.data.formatter) {
  46. style.formatter = setting.data.formatter;
  47. }
  48. return style;
  49. },
  50. loadSheetHeader: function (setting, sheet) {
  51. this.massOperationSheet(sheet, function () {
  52. if(setting.rowHeaderWidth !== undefined && setting.rowHeaderWidth !== null){
  53. sheet.setColumnWidth(0, setting.rowHeaderWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  54. }else {
  55. sheet.setColumnWidth(0, 25, GC.Spread.Sheets.SheetArea.rowHeader);
  56. }
  57. if (setting.frozenCols) {
  58. sheet.frozenColumnCount(setting.frozenCols);
  59. }
  60. sheet.setColumnCount(setting.cols.length);
  61. sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
  62. setting.headRowHeight.forEach(function (rowHeight, index) {
  63. sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
  64. });
  65. setting.cols.forEach(function (col, index) {
  66. var i, iRow = 0, cell;
  67. for (i = 0; i < col.head.spanCols.length; i++) {
  68. if (col.head.spanCols[i] !== 0) {
  69. cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
  70. //cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]).wordWrap(true);
  71. cell.value(col.head.titleNames[i]).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]).wordWrap(true);
  72. }
  73. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  74. sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
  75. }
  76. iRow += col.head.spanRows[i];
  77. };
  78. sheet.setColumnWidth(index, col.width);
  79. sheet.setColumnVisible(index, col.visible && true);
  80. });
  81. });
  82. },
  83. protectdSheet: function (sheet) {
  84. var option = {
  85. allowSelectLockedCells: true,
  86. allowSelectUnlockedCells: true,
  87. allowResizeRows: true,
  88. allowResizeColumns: true
  89. };
  90. sheet.options.protectionOptions = option;
  91. sheet.options.isProtected = true;
  92. sheet.options.allowCellOverflow = false;
  93. },
  94. massOperationSheet: function (sheet, Operation) {
  95. sheet.suspendPaint();
  96. sheet.suspendEvent();
  97. Operation();
  98. sheet.resumeEvent();
  99. sheet.resumePaint();
  100. },
  101. refreshNodesVisible: function (nodes, sheet, recursive) {
  102. nodes.forEach(function (node) {
  103. var iRow;
  104. iRow = node.serialNo();
  105. sheet.setRowVisible(iRow, node.visible, GC.Spread.Sheets.SheetArea.viewport);
  106. if (recursive) {
  107. TREE_SHEET_HELPER.refreshNodesVisible(node.children, sheet, recursive);
  108. }
  109. })
  110. },
  111. refreshTreeNodeData: function (setting, sheet, nodes, recursive) {
  112. nodes.forEach(function (node) {
  113. let iRow = node.serialNo();
  114. if(setting.emptyRowHeader){
  115. sheet.setValue(iRow, 0, '', GC.Spread.Sheets.SheetArea.rowHeader);
  116. }
  117. if(typeof projectObj !== 'undefined'){
  118. let nodeStyle = projectObj.getNodeColorStyle(sheet, node);
  119. if(node.data.bgColour){
  120. nodeStyle.backColor = node.data.bgColour;
  121. }
  122. if(nodeStyle){
  123. sheet.setStyle(iRow, -1, nodeStyle);
  124. }
  125. }
  126. setting.cols.forEach(function (colSetting, iCol) {
  127. /* if(typeof projectObj !== 'undefined'){ 7/28 取消黑体显示
  128. let boldFontStyle = projectObj.getBoldFontStyle(node, colSetting);
  129. sheet.setStyle(iRow, iCol, boldFontStyle);
  130. }
  131. }*/
  132. // var getFieldText = function () {
  133. // var fields = colSetting.data.field.split('.');
  134. // var validField = fields.reduce(function (field1, field2) {
  135. // if (eval('node.data.' + field1)) {
  136. // return field1 + '.' + field2
  137. // } else {
  138. // return field1;
  139. // }
  140. // });
  141. // if (eval('node.data.' + validField)) {
  142. // return eval('node.data.' + validField);
  143. // } else {
  144. // return '';
  145. // }
  146. // };
  147. var getFieldText2 = function () {
  148. var fields = colSetting.data.field.split('.'), iField, data = node.data;
  149. for (iField = 0; iField < fields.length; iField++) {
  150. if (data[fields[iField]] && data[fields[iField]]!='0') {
  151. data = data[fields[iField]];
  152. } else {
  153. return '';
  154. }
  155. }
  156. return data;
  157. };
  158. if(sheet.name()=="mainSheet"){
  159. /* if(colSetting.data.field=="quantity"){ 2018-08-06 去掉工程量列表达式
  160. let tag = node.data.quantityEXP?node.data.quantityEXP:'';
  161. sheet.setTag(iRow, iCol,tag);
  162. }*/
  163. if(colSetting.data.field=="code"){
  164. let tag ="";
  165. if(node.sourceType == ModuleNames.ration){//定额的时候换算子目
  166. tag = node.data.adjustState?node.data.adjustState:'';
  167. }/*else if(node.sourceType == ModuleNames.bills &&projectObj.ifItemCharHiden(setting)){//清单、并且项目特征列隐藏的时候悬浮提示 这里改成在 计量单位那里提示
  168. tag = node.data.itemCharacterText?node.data.itemCharacterText:'';
  169. }*/
  170. sheet.setTag(iRow, iCol,tag);
  171. }
  172. /*if(colSetting.data.field=="name"){ 2018-08-06 改成在编号列悬浮提示
  173. let tag = node.data.itemCharacterText?node.data.itemCharacterText:'';
  174. sheet.setTag(iRow, iCol,tag);
  175. }*/
  176. }
  177. if(colSetting.visible == false) return;//隐藏列不做其它操作
  178. var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
  179. if (colSetting.data.getText && Object.prototype.toString.apply(colSetting.data.getText) === "[object Function]") {
  180. cell.value(colSetting.data.getText(node));
  181. } else {
  182. cell.value(getFieldText2());
  183. }
  184. if (colSetting.data.cellType && Object.prototype.toString.apply(colSetting.data.cellType) !== "[object String]") {
  185. cell.cellType(colSetting.data.cellType(node,setting));
  186. }
  187. //树节点显示列
  188. if(iCol == setting.treeCol) cell.cellType(TREE_SHEET_HELPER.getTreeNodeCellType(setting, sheet, node.tree,node));
  189. if(colSetting.data.autoHeight == true){
  190. colSetting.setAutoHeight(cell,node);
  191. }
  192. if(colSetting.editChecking&&colSetting.editChecking(node)){
  193. cell.locked(true);
  194. }else if (colSetting.readOnly) {
  195. if(typeof projectReadOnly !== 'undefined' && projectReadOnly){
  196. cell.locked(true);
  197. }else {
  198. if (Object.prototype.toString.apply(colSetting.readOnly) === "[object Function]") {
  199. cell.locked(colSetting.readOnly(node));
  200. } else {
  201. cell.locked(true);
  202. }
  203. }
  204. } else {
  205. cell.locked(typeof projectReadOnly !== 'undefined' && projectReadOnly ? true : false);
  206. }
  207. });
  208. if(setting.setAutoFitRow){
  209. setting.setAutoFitRow(sheet,node)
  210. }
  211. if (recursive) {
  212. TREE_SHEET_HELPER.refreshTreeNodeData(setting, sheet, node.children, recursive);
  213. }
  214. });
  215. },
  216. refreshChildrenVisiable:function(sheet,tree,node,row,visiable){
  217. let iCount = node.posterityCount(), i, child;
  218. for (i = 0; i < iCount; i++) {
  219. child = tree.items[row + i +1];
  220. sheet.setRowVisible(row + i + 1, visiable?visiable:child.visible, GC.Spread.Sheets.SheetArea.viewport);
  221. }
  222. sheet.invalidateLayout();
  223. },
  224. showTreeData: function (setting, sheet, tree) {
  225. let TipCellType = function () {};
  226. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  227. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  228. return {
  229. x: x,
  230. y: y,
  231. row: context.row,
  232. col: context.col,
  233. cellStyle: cellStyle,
  234. cellRect: cellRect,
  235. sheet: context.sheet,
  236. sheetArea: context.sheetArea
  237. };
  238. };
  239. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  240. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  241. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  242. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  243. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  244. zoom = hitinfo.sheet.zoom();
  245. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  246. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  247. let dataField = setting.cols[hitinfo.col].data.field;
  248. if((tag==undefined||tag=='')&&hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).wordWrap()==true){//显示其它列的标记为空并且设置了自动换行
  249. return;
  250. }
  251. if(dataField === 'itemCharacterText' || dataField === 'jobContentText' || dataField === 'adjustState'||dataField=="name"){
  252. if((hitinfo.sheet.getParent() === projectObj.mainSpread||hitinfo.sheet.getParent() === tender_obj.tenderSpread) && textLength <= cellWidth)
  253. return;
  254. }
  255. if(hitinfo.sheet.name()=="mainSheet"){
  256. if(dataField=="quantity"){//显示工程量明细
  257. text = tag;
  258. }/*if(dataField=="name"){//项目特征及内容隐藏时,显示特征及内容
  259. if(projectObj.ifItemCharHiden(setting)&&tag!=''){
  260. text = tag;
  261. }else if(textLength <= cellWidth){
  262. return;
  263. }
  264. }*/
  265. else if(tag !== undefined && tag) {
  266. text = tag;
  267. }
  268. }
  269. TREE_SHEET_HELPER.showTipsDiv(text,setting,hitinfo);
  270. };
  271. TipCellType.prototype.processMouseLeave = function (hitinfo) {
  272. TREE_SHEET_HELPER.hideTipsDiv();
  273. }
  274. TREE_SHEET_HELPER.protectdSheet(sheet);
  275. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  276. sheet.rowOutlines.direction(GC.Spread.Sheets.Outlines.OutlineDirection.backward);
  277. sheet.showRowOutline(false);
  278. if (setting.defaultRowHeight) {
  279. sheet.defaults.rowHeight = setting.defaultRowHeight;
  280. }
  281. sheet.setRowCount(tree.count() + setting.emptyRows, GC.Spread.Sheets.SheetArea.viewport);
  282. sheet.getRange(tree.count(), -1, setting.emptyRows, -1).locked(true);
  283. setting.cols.forEach(function (colSetting, iCol) {
  284. sheet.setStyle(-1, iCol, TREE_SHEET_HELPER.getSheetCellStyle(colSetting));
  285. if (colSetting.showHint) {
  286. sheet.getRange(-1, iCol, -1, 1).cellType(new TipCellType());
  287. }
  288. if(colSetting.formatter){
  289. sheet.setFormatter(-1, iCol, colSetting.formatter, GC.Spread.Sheets.SheetArea.viewport);
  290. }
  291. });
  292. //sheet.getRange(-1, setting.treeCol, -1, 1).cellType(new TreeNodeCellType());
  293. TREE_SHEET_HELPER.refreshTreeNodeData(setting, sheet, tree.roots, true);
  294. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, sheet, true);
  295. });
  296. },
  297. getTreeNodeCellType:function(setting, sheet,tree,initNode){
  298. let indent = 20;
  299. let levelIndent = -5;
  300. let halfBoxLength = 5;
  301. let halfExpandLength = 3;
  302. let isRationNode = sheet.name()=="mainSheet" && initNode.sourceType == ModuleNames.ration;
  303. let TreeNodeCellType = function () {
  304. this.clickDropDown = false; //如果是点击下拉框的三角形的时候,默认展开下拉框
  305. };
  306. TreeNodeCellType.prototype =isRationNode? new GC.Spread.Sheets.CellTypes.Base(): new GC.Spread.Sheets.CellTypes.Text();//new GC.Spread.Sheets.CellTypes.Text();
  307. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  308. if (style.backColor) {
  309. ctx.save();
  310. ctx.fillStyle = style.backColor;
  311. ctx.fillRect(x, y, w, h);
  312. ctx.restore();
  313. } else {
  314. ctx.clearRect(x, y, w, h);
  315. }
  316. // ������(x1, y1)���(��, ��), (x2, y2)�յ�(��, ��), ��ɫ
  317. let drawLine = function (canvas, x1, y1, x2, y2, color) {
  318. ctx.save();
  319. // ����ƫ����
  320. ctx.translate(0.5, 0.5);
  321. ctx.beginPath();
  322. ctx.moveTo(x1, y1);
  323. ctx.lineTo(x2, y2);
  324. ctx.strokeStyle = color;
  325. ctx.stroke();
  326. ctx.restore();
  327. };
  328. let drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
  329. let rect = {}, h1, h2, offset = 1;
  330. rect.top = centerY - halfBoxLength;
  331. rect.bottom = centerY + halfBoxLength;
  332. rect.left = centerX - halfBoxLength;
  333. rect.right = centerX + halfBoxLength;
  334. if (rect.left < x + w) {
  335. rect.right = Math.min(rect.right, x + w);
  336. ctx.save();
  337. // ����ƫ����
  338. ctx.translate(0.5, 0.5);
  339. ctx.strokeStyle = 'black';
  340. ctx.beginPath();
  341. ctx.moveTo(rect.left, rect.top);
  342. ctx.lineTo(rect.left, rect.bottom);
  343. ctx.lineTo(rect.right, rect.bottom);
  344. ctx.lineTo(rect.right, rect.top);
  345. ctx.lineTo(rect.left, rect.top);
  346. ctx.stroke();
  347. ctx.fillStyle = 'white';
  348. ctx.fill();
  349. ctx.restore();
  350. // Draw Horizontal Line
  351. h1 = centerX - halfExpandLength;
  352. h2 = Math.min(centerX + halfExpandLength, x + w);
  353. if (h2 > h1) {
  354. drawLine(ctx, h1, centerY, h2, centerY, 'black');
  355. }
  356. // Draw Vertical Line
  357. if (!expanded && (centerX < x + w)) {
  358. drawLine(ctx, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, 'black');
  359. }
  360. }
  361. }
  362. let node = tree.items[options.row];
  363. let showTreeLine = true;
  364. if (!node) { return; }
  365. let centerX = Math.floor(x) + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  366. let x1 = centerX + indent / 2;
  367. let centerY = Math.floor((y + (y + h)) / 2);
  368. let y1;
  369. // Draw Sibling Line
  370. if (showTreeLine) {
  371. // Draw Horizontal Line
  372. if (centerX < x + w) {
  373. drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  374. }
  375. // Draw Vertical Line
  376. if (centerX < x + w) {
  377. y1 = node.isLast() ? centerY : y + h;
  378. if (node.isFirst() && !node.parent) {
  379. drawLine(ctx, centerX, centerY, centerX, y1, 'gray');
  380. } else {
  381. drawLine(ctx, centerX, y, centerX, y1, 'gray');
  382. }
  383. }
  384. }
  385. // Draw Expand Box
  386. if (node.children.length > 0) {
  387. drawExpandBox(ctx, x, y, w, h, centerX, centerY, node.expanded);
  388. }
  389. // Draw Parent Line
  390. if (showTreeLine) {
  391. var parent = node.parent, parentCenterX = centerX - indent - levelIndent;
  392. while (parent) {
  393. if (!parent.isLast()) {
  394. if (parentCenterX < x + w) {
  395. drawLine(ctx, parentCenterX, y, parentCenterX, y + h, 'gray');
  396. }
  397. }
  398. parent = parent.parent;
  399. parentCenterX -= (indent + levelIndent);
  400. }
  401. };
  402. // Draw Text
  403. x = x + (node.depth() + 1) * indent + node.depth() * levelIndent;
  404. w = w - (node.depth() + 1) * indent - node.depth() * levelIndent;
  405. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  406. //画下拉框三角形
  407. let sheet = options.sheet;
  408. if (isRationNode&& options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
  409. sheetCommonObj.drowTriangle(ctx,x+w-12,y+h/2+2);
  410. }
  411. };
  412. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  413. return {
  414. x: x,
  415. y: y,
  416. row: context.row,
  417. col: context.col,
  418. cellStyle: cellStyle,
  419. cellRect: cellRect,
  420. sheetArea: context.sheetArea
  421. };
  422. };
  423. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  424. let offset = -1;
  425. let node = tree.items[hitinfo.row];
  426. tree.selected = node;
  427. if(isRationNode &&hitinfo.row === hitinfo.sheet.getActiveRowIndex() && hitinfo.col === hitinfo.sheet.getActiveColumnIndex()){
  428. if( hitinfo.x > hitinfo.cellRect.x + hitinfo.cellRect.width - 17){
  429. this.clickDropDown = true;
  430. setTimeout(function () {hitinfo.sheet.startEdit();},10);
  431. return;
  432. }
  433. }
  434. if (!node || node.children.length === 0) { return; }
  435. let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  436. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  437. if (hitinfo.x > centerX - halfBoxLength && hitinfo.x < centerX + halfBoxLength && hitinfo.y > centerY - halfBoxLength && hitinfo.y < centerY + halfBoxLength) {
  438. node.setExpanded(!node.expanded);
  439. let sheetName = hitinfo.sheet.name();
  440. if(sheetName === 'stdBillsLib_bills'){
  441. sessionStorage.setItem('stdBillsLibExpState', billsLibObj.stdBillsTree.getExpState(billsLibObj.stdBillsTree.items));
  442. }
  443. else if(sheetName === 'stdRationLib_chapter'){
  444. sessionStorage.setItem('stdRationLibExpState', rationLibObj.tree.getExpState(rationLibObj.tree.items));
  445. }
  446. else if(sheetName === 'stdBillsGuidance_bills'){
  447. sessionStorage.setItem('stdBillsGuidanceExpState', billsGuidance.bills.tree.getExpState(billsGuidance.bills.tree.items));
  448. }
  449. TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
  450. let iCount = node.posterityCount(), i, child;
  451. for (i = 0; i < iCount; i++) {
  452. child = tree.items[hitinfo.row + i + 1];
  453. hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
  454. //hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.vis(), hitinfo.sheetArea);
  455. }
  456. hitinfo.sheet.invalidateLayout();
  457. });
  458. hitinfo.sheet.repaint();
  459. }
  460. };
  461. TreeNodeCellType.prototype.processMouseEnter = function(hitinfo){
  462. if(hitinfo.sheet.name() === 'stdBillsGuidance_bills'){
  463. TREE_SHEET_HELPER.delayShowTips(hitinfo,setting);
  464. }
  465. };
  466. TreeNodeCellType.prototype.processMouseMove = function(hitinfo){//造价书主界面,当鼠标移动到单元格最右往左50个像素内时才显示悬浮提示内容
  467. if (hitinfo.sheet.name()!=="mainSheet") return;//只有在造价书主界面才显示
  468. let offset = 20;//从右向左显示的像素范围
  469. let leftX = hitinfo.cellRect.x + hitinfo.cellRect.width;//最右边的坐标
  470. if(leftX - hitinfo.x <= offset){//如果鼠标移动到的位置是在显示的范围内显示悬浮提示
  471. TREE_SHEET_HELPER.delayShowTips(hitinfo,setting);
  472. }else {//如果移出了范围,隐藏悬浮提示
  473. TREE_SHEET_HELPER.hideTipsDiv();
  474. }
  475. };
  476. TreeNodeCellType.prototype.processMouseLeave = function (hitinfo) {
  477. TREE_SHEET_HELPER.hideTipsDiv();
  478. };
  479. if(isRationNode){
  480. TreeNodeCellType.prototype.createEditorElement = function (context) {
  481. return document.createElement("div");
  482. };
  483. TreeNodeCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
  484. $editor = $(editorContext);
  485. $editor.css("position", "fixed");
  486. $editor.css("background", 'white');
  487. $editor.css("width", cellRect.width);
  488. $editor.css("height", cellRect.height);
  489. $editor.attr("gcUIElement", "gcEditingInput");//padding:0 //value="${context.sheet.getValue(context.row,context.col)}"
  490. $editor.html(` <div class="input-group input-group-sm">
  491. <input type="text" id="esInput" class="form-control" aria-label="Text input with dropdown button" autocomplete="off" style="background-color:${cellStyle.backColor}">
  492. <div class="">
  493. <div class="triangle-border_dropdown tb-border_dropdown" id="esBtn" style="left: ${cellRect.width - 15+"px"}"></div>
  494. </div>
  495. </div>
  496. `);
  497. // <div class = "input-group-append"><button class="btn btn-outline-secondary dropdown-toggle" id="esBtn" type="button" aria-haspopup="true" aria-expanded="false"></button></div>
  498. $editor.children('div').height(cellRect.height+2);
  499. return $editor;
  500. };
  501. TreeNodeCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  502. let me = this;
  503. $(editorContext).append(`<div><ul class="es-list" style="display: block;background-color:${cellStyle.backColor}"></ul></div>`);//<li class="" data-value="" style=""> <br></li>
  504. $('#esInput').val(context.sheet.getValue(context.row,context.col));
  505. $('#esInput').select();
  506. projectObj.project.Ration.getNearRations(initNode.data,function(rations){
  507. if(rations.length > 0){
  508. let li_html = "";
  509. for(let r of rations){
  510. if(r.code==initNode.data.code) continue; //排除自已
  511. li_html += `<li class="es_li" data-value="${r.code}" >${r.code} ${r.name} ${r.unit}</li>`;//定额编码+空格+定额名称+空格+定额单位。
  512. }
  513. $(".es-list").html(li_html);
  514. $(".es-list").css("min-width",cellRect.width);
  515. }
  516. if(me.clickDropDown == false) $(".es-list").hide();
  517. $(".es-list").children(".es_li").bind('click',function (e) {
  518. $('#esInput').val(this.dataset.value);
  519. $(".es-list").hide();
  520. context.sheet.endEdit();
  521. })
  522. $("#esBtn").bind('click',function(e){
  523. $(".es-list").toggle();
  524. });
  525. if( $('#esInput').val()) setCursor( $("#esInput")[0], $('#esInput').val().length)
  526. });
  527. };
  528. TreeNodeCellType.prototype.setEditorValue = function (editor, value, context) {
  529. $('#esInput').val(value);
  530. };
  531. TreeNodeCellType.prototype.getEditorValue = function (editor, context) {
  532. this.isEscKey = false;
  533. console.log($('#esInput').val());
  534. return $('#esInput').val()!==''? $('#esInput').val():null;
  535. };
  536. }
  537. return new TreeNodeCellType();
  538. },
  539. showTipsDiv:function (text,setting,hitinfo) {
  540. if (setting.pos && text && text !== '') {
  541. if(text) text = replaceAll(/[\n]/,'<br>',text);
  542. if(!this._fixedTipElement){
  543. let div = $('#fixedTip')[0];
  544. if (!div) {
  545. div = document.createElement("div");
  546. $(div).css("padding", 5)
  547. .attr("id", 'fixedTip');
  548. $(div).hide();
  549. document.body.insertBefore(div, null);
  550. }
  551. this._fixedTipElement = div;
  552. }
  553. $(this._fixedTipElement).width('');
  554. $(this._fixedTipElement).html(text);
  555. if (!this._toolTipElement) {
  556. let div = $('#autoTip')[0];
  557. if (!div) {
  558. div = document.createElement("div");
  559. $(div).addClass("message-box");
  560. $(div).attr("id", 'autoTip');
  561. $(div).hide();
  562. document.body.insertBefore(div, null);
  563. }
  564. this._toolTipElement = div;
  565. $(this._toolTipElement).width('');
  566. //实时读取位置信息
  567. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  568. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  569. }
  570. $(this._toolTipElement).html(`<span>${text}</span><div class="triangle-border tb-border_up"></div><div class="triangle-border tb-background_up"></div>`);
  571. //清单指引、清单库做特殊处理
  572. if($(hitinfo.sheet.getParent().qo).attr('id') === 'stdBillsSpread' || $(hitinfo.sheet.getParent().qo).attr('id') === 'billsGuidance_bills'){
  573. $(this._toolTipElement).html(`<span>${text}</span>`);
  574. let divWidth = $(this._fixedTipElement).width(),
  575. divHeight = $(this._fixedTipElement).height();
  576. if(divWidth > 600){
  577. divWidth = 590;
  578. $(this._toolTipElement).width(divWidth);
  579. }
  580. let top = setting.pos.y + hitinfo.y - divHeight / 2 < 0 ? 0 : setting.pos.y + hitinfo.y - divHeight / 2;
  581. $(this._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  582. } else {
  583. //计算显示的初始位置
  584. /* 显示在单元格上方,三角形指向下的版本
  585. let top = setting.pos.y + hitinfo.cellRect.y -$(this._toolTipElement).height() -26;
  586. let left = setting.pos.x + hitinfo.cellRect.x;
  587. $(this._toolTipElement).css("top", top).css("left", left);*/
  588. //显示在下方,三角形指
  589. let top = setting.pos.y + hitinfo.cellRect.y+26;
  590. let left = setting.pos.x + hitinfo.cellRect.x;
  591. $(this._toolTipElement).css("top", top).css("left", left);
  592. }
  593. $(this._toolTipElement).show("fast");
  594. TREE_SHEET_HELPER.tipDiv = 'show';//做个标记
  595. }
  596. }
  597. },
  598. hideTipsDiv:function () {
  599. TREE_SHEET_HELPER.tipTimeStamp = +new Date();//这个是为了造价书清单编号树节点的那个延时显示而打的时间戳,防止已经要隐藏的提示框,延时显示
  600. let me = TREE_SHEET_HELPER;
  601. TREE_SHEET_HELPER.tipDiv = 'hide';
  602. if (me._toolTipElement) {
  603. $(me._toolTipElement).hide();
  604. me._toolTipElement = null;
  605. }
  606. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  607. },
  608. tipDivCheck(){
  609. setTimeout(function () {
  610. let tips = $('#autoTip');
  611. if(TREE_SHEET_HELPER.tipDiv == 'show'){
  612. return;
  613. } else if(TREE_SHEET_HELPER.tipDiv == 'hide'&&tips){
  614. tips.hide();
  615. TREE_SHEET_HELPER._toolTipElement = null;
  616. }
  617. },600)
  618. },
  619. delayShowTips:function(hitinfo,setting,tips){//延时显示
  620. let delayTimes = 500; //延时时间
  621. let now_timeStamp = +new Date();
  622. TREE_SHEET_HELPER.tipTimeStamp = now_timeStamp;
  623. setTimeout(function () {
  624. if(now_timeStamp - TREE_SHEET_HELPER.tipTimeStamp == 0){//鼠标停下的时候才显示
  625. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  626. if(tips && tips !=""){ //有tips的话优先显示tips
  627. tag = tips;
  628. }
  629. if(tag&&tag!=''){
  630. TREE_SHEET_HELPER.showTipsDiv(tag,setting,hitinfo);
  631. }
  632. }
  633. },delayTimes);
  634. }
  635. };