tree_sheet_helper.js 27 KB

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