tree_sheet_helper.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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,autoFit=true) {
  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. sheet.setStyle(iRow, -1, nodeStyle||{});
  121. }
  122. setting.cols.forEach(function (colSetting, iCol) {
  123. /* if(typeof projectObj !== 'undefined'){ 7/28 取消黑体显示
  124. let boldFontStyle = projectObj.getBoldFontStyle(node, colSetting);
  125. sheet.setStyle(iRow, iCol, boldFontStyle);
  126. }
  127. }*/
  128. // var getFieldText = function () {
  129. // var fields = colSetting.data.field.split('.');
  130. // var validField = fields.reduce(function (field1, field2) {
  131. // if (eval('node.data.' + field1)) {
  132. // return field1 + '.' + field2
  133. // } else {
  134. // return field1;
  135. // }
  136. // });
  137. // if (eval('node.data.' + validField)) {
  138. // return eval('node.data.' + validField);
  139. // } else {
  140. // return '';
  141. // }
  142. // };
  143. var getFieldText2 = function () {
  144. var fields = colSetting.data.field.split('.'), iField, data = node.data;
  145. for (iField = 0; iField < fields.length; iField++) {
  146. if (data[fields[iField]] && data[fields[iField]]!='0') {
  147. data = data[fields[iField]];
  148. } else {
  149. return '';
  150. }
  151. }
  152. return data;
  153. };
  154. var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
  155. if(sheet.name()=="mainSheet"){
  156. if(colSetting.data.field=="code"){
  157. let tag =null;
  158. if(node.sourceType == ModuleNames.ration){//定额的时候换算子目
  159. tag = node.data.adjustState?node.data.adjustState:'';
  160. }
  161. if(tag!=null) sheet.setTag(iRow, iCol,tag);
  162. } else if (colSetting) {
  163. }
  164. // 单元格字体颜色
  165. const foreColorFunc = MainTreeCol.foreColor[colSetting.data.field];
  166. if (foreColorFunc) {
  167. cell.foreColor(foreColorFunc(node));
  168. }
  169. }
  170. if(colSetting.visible == false) return;//隐藏列不做其它操作
  171. if (colSetting.data.getText && Object.prototype.toString.apply(colSetting.data.getText) === "[object Function]") {
  172. if(colSetting.data.field=="quantity") sheet.setFormatter(iRow, iCol, '@');//输入 % 号时会出现奇怪的现像, %一直追加在后面
  173. cell.value(colSetting.data.getText(node));
  174. }else if((colSetting.data.field=="mainBills"||(['outPutMaxPrice', 'outPutLimitPrice'].includes(colSetting.data.field)))&&MainTreeCol.mainBillsEnable(node)){//主要清单有三种状态,所以直接显示就好,不走最后的逻辑
  175. cell.value(node.data[colSetting.data.field]===undefined?false:node.data[colSetting.data.field]);
  176. } else {
  177. cell.value(getFieldText2());
  178. }
  179. if (colSetting.data.cellType && Object.prototype.toString.apply(colSetting.data.cellType) !== "[object String]") {
  180. cell.cellType(colSetting.data.cellType(node,setting,colSetting.data.field));
  181. }
  182. //树节点显示列
  183. if(iCol == setting.treeCol) cell.cellType(TREE_SHEET_HELPER.getTreeNodeCellType(setting, sheet, node.tree,node));
  184. if(colSetting.data.autoHeight == true){
  185. colSetting.setAutoHeight(cell,node);
  186. }
  187. //主界面分部名称点击弹窗
  188. if(sheet.name()=="mainSheet" && colSetting.data.field=="name") MainTreeCol.setNameCusButton(cell,node);
  189. if(colSetting.editChecking&&colSetting.editChecking(node,colSetting.data.field)){
  190. cell.locked(true);
  191. }else if (colSetting.readOnly) {
  192. if(typeof projectReadOnly !== 'undefined' && projectReadOnly){
  193. cell.locked(true);
  194. }else {
  195. if (Object.prototype.toString.apply(colSetting.readOnly) === "[object Function]") {
  196. cell.locked(colSetting.readOnly(node, colSetting.data.field));
  197. } else {
  198. cell.locked(true);
  199. }
  200. }
  201. } else {
  202. cell.locked(typeof projectReadOnly !== 'undefined' && projectReadOnly ? true : false);
  203. }
  204. });
  205. if(autoFit==true && setting.setAutoFitRow){
  206. setting.setAutoFitRow(sheet,node)//自动行高功能比较费时,400行,启用和不启用相差2秒左右
  207. }
  208. if (recursive) {
  209. TREE_SHEET_HELPER.refreshTreeNodeData(setting, sheet, node.children, recursive);
  210. }
  211. });
  212. },
  213. refreshChildrenVisiable:function(sheet,tree,node,row,visiable){
  214. let iCount = node.posterityCount(), i, child;
  215. for (i = 0; i < iCount; i++) {
  216. child = tree.items[row + i +1];
  217. sheet.setRowVisible(row + i + 1, visiable?visiable:child.visible, GC.Spread.Sheets.SheetArea.viewport);
  218. }
  219. sheet.invalidateLayout();
  220. },
  221. getTipCellType: function (setting) {
  222. let TipCellType = function () {};
  223. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  224. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  225. return {
  226. x: x,
  227. y: y,
  228. row: context.row,
  229. col: context.col,
  230. cellStyle: cellStyle,
  231. cellRect: cellRect,
  232. sheet: context.sheet,
  233. sheetArea: context.sheetArea
  234. };
  235. };
  236. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  237. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  238. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  239. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  240. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  241. zoom = hitinfo.sheet.zoom();
  242. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  243. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  244. let dataField = setting.cols && setting.cols[hitinfo.col].data.field || setting.header[hitinfo.col].dataCode;
  245. if((tag==undefined||tag=='')&&hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).wordWrap()==true){//显示其它列的标记为空并且设置了自动换行
  246. return;
  247. }
  248. if(dataField === 'itemCharacterText' || dataField === 'jobContentText' || dataField === 'adjustState'||dataField=="name"){
  249. if((hitinfo.sheet.getParent() === projectObj.mainSpread||hitinfo.sheet.getParent() === tender_obj.tenderSpread) && textLength <= cellWidth)
  250. return;
  251. }
  252. if(hitinfo.sheet.name()=="mainSheet"){
  253. if(dataField=="quantity"){//显示工程量明细
  254. text = tag;
  255. }/*if(dataField=="name"){//项目特征及内容隐藏时,显示特征及内容
  256. if(projectObj.ifItemCharHiden(setting)&&tag!=''){
  257. text = tag;
  258. }else if(textLength <= cellWidth){
  259. return;
  260. }
  261. }*/
  262. else if(tag !== undefined && tag) {
  263. text = tag;
  264. }
  265. //这里要改成延时显示
  266. TREE_SHEET_HELPER.delayShowTips(hitinfo,setting,text);
  267. }else {//非造价书页面还是实时显示
  268. TREE_SHEET_HELPER.showTipsDiv(text,setting,hitinfo);
  269. }
  270. };
  271. TipCellType.prototype.processMouseLeave = function (hitinfo) {
  272. TREE_SHEET_HELPER.hideTipsDiv();
  273. }
  274. return new TipCellType();
  275. },
  276. showTreeData: function (setting, sheet, tree) {
  277. TREE_SHEET_HELPER.protectdSheet(sheet);
  278. TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
  279. sheet.rowOutlines.direction(GC.Spread.Sheets.Outlines.OutlineDirection.backward);
  280. sheet.showRowOutline(false);
  281. if (setting.defaultRowHeight) {
  282. sheet.defaults.rowHeight = setting.defaultRowHeight;
  283. }
  284. sheet.setRowCount(tree.count() + setting.emptyRows, GC.Spread.Sheets.SheetArea.viewport);
  285. sheet.getRange(tree.count(), -1, setting.emptyRows, -1).locked(true);
  286. setting.cols.forEach(function (colSetting, iCol) {
  287. sheet.setStyle(-1, iCol, TREE_SHEET_HELPER.getSheetCellStyle(colSetting));
  288. if (colSetting.showHint) {
  289. sheet.getRange(-1, iCol, -1, 1).cellType(TREE_SHEET_HELPER.getTipCellType(setting));
  290. }
  291. if(colSetting.formatter){
  292. sheet.setFormatter(-1, iCol, colSetting.formatter, GC.Spread.Sheets.SheetArea.viewport);
  293. }
  294. });
  295. //sheet.getRange(-1, setting.treeCol, -1, 1).cellType(new TreeNodeCellType());
  296. TREE_SHEET_HELPER.refreshTreeNodeData(setting, sheet, tree.roots, true);
  297. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, sheet, true);
  298. });
  299. },
  300. getTreeNodeCellType:function(setting, sheet,tree,initNode){
  301. let indent = 20;
  302. let levelIndent = -5;
  303. let halfBoxLength = 5;
  304. let halfExpandLength = 3;
  305. let isRationNode = sheet.name()=="mainSheet" && initNode.sourceType == ModuleNames.ration&&initNode.data.type == rationType.ration;
  306. let questionImg = document.getElementById('question_pic'),
  307. questionImgWidth = 16,
  308. questionImgHeight = 16;
  309. let TreeNodeCellType = function () {
  310. this.clickDropDown = false; //如果是点击下拉框的三角形的时候,默认展开下拉框
  311. };
  312. TreeNodeCellType.prototype =isRationNode? new GC.Spread.Sheets.CellTypes.Base(): new GC.Spread.Sheets.CellTypes.Text();//new GC.Spread.Sheets.CellTypes.Text();
  313. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  314. if (style.backColor) {
  315. ctx.save();
  316. ctx.fillStyle = style.backColor;
  317. ctx.fillRect(x, y, w, h);
  318. ctx.restore();
  319. } else {
  320. ctx.clearRect(x, y, w, h);
  321. }
  322. // ������(x1, y1)���(��, ��), (x2, y2)�յ�(��, ��), ��ɫ
  323. let drawLine = function (canvas, x1, y1, x2, y2, color) {
  324. ctx.save();
  325. // ����ƫ����
  326. ctx.translate(0.5, 0.5);
  327. ctx.beginPath();
  328. ctx.moveTo(x1, y1);
  329. ctx.lineTo(x2, y2);
  330. ctx.strokeStyle = color;
  331. ctx.stroke();
  332. ctx.restore();
  333. };
  334. let drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
  335. let rect = {}, h1, h2, offset = 1;
  336. rect.top = centerY - halfBoxLength;
  337. rect.bottom = centerY + halfBoxLength;
  338. rect.left = centerX - halfBoxLength;
  339. rect.right = centerX + halfBoxLength;
  340. if (rect.left < x + w) {
  341. rect.right = Math.min(rect.right, x + w);
  342. ctx.save();
  343. // ����ƫ����
  344. ctx.translate(0.5, 0.5);
  345. ctx.strokeStyle = 'black';
  346. ctx.beginPath();
  347. ctx.moveTo(rect.left, rect.top);
  348. ctx.lineTo(rect.left, rect.bottom);
  349. ctx.lineTo(rect.right, rect.bottom);
  350. ctx.lineTo(rect.right, rect.top);
  351. ctx.lineTo(rect.left, rect.top);
  352. ctx.stroke();
  353. ctx.fillStyle = 'white';
  354. ctx.fill();
  355. ctx.restore();
  356. // Draw Horizontal Line
  357. h1 = centerX - halfExpandLength;
  358. h2 = Math.min(centerX + halfExpandLength, x + w);
  359. if (h2 > h1) {
  360. drawLine(ctx, h1, centerY, h2, centerY, 'black');
  361. }
  362. // Draw Vertical Line
  363. if (!expanded && (centerX < x + w)) {
  364. drawLine(ctx, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, 'black');
  365. }
  366. }
  367. }
  368. let node = tree.items[options.row];
  369. let showTreeLine = true;
  370. if (!node) { return; }
  371. let centerX = Math.floor(x) + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  372. let x1 = centerX + indent / 2;
  373. let centerY = Math.floor((y + (y + h)) / 2);
  374. let y1;
  375. const lineColor = '#ababab';
  376. // Draw Sibling Line
  377. if (showTreeLine) {
  378. // Draw Horizontal Line
  379. if (centerX < x + w) {
  380. drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, lineColor);
  381. }
  382. // Draw Vertical Line
  383. if (centerX < x + w) {
  384. y1 = node.isLast() ? centerY : y + h;
  385. if (node.isFirst() && !node.parent) {
  386. drawLine(ctx, centerX, centerY, centerX, y1, lineColor);
  387. } else {
  388. drawLine(ctx, centerX, y, centerX, y1, lineColor);
  389. }
  390. }
  391. }
  392. // Draw Expand Box
  393. if (node.children.length > 0) {
  394. drawExpandBox(ctx, x, y, w, h, centerX, centerY, node.expanded);
  395. }
  396. // Draw Parent Line
  397. if (showTreeLine) {
  398. var parent = node.parent, parentCenterX = centerX - indent - levelIndent;
  399. while (parent) {
  400. if (!parent.isLast()) {
  401. if (parentCenterX < x + w) {
  402. drawLine(ctx, parentCenterX, y, parentCenterX, y + h, lineColor);
  403. }
  404. }
  405. parent = parent.parent;
  406. parentCenterX -= (indent + levelIndent);
  407. }
  408. };
  409. // Draw Text
  410. x = x + (node.depth() + 1) * indent + node.depth() * levelIndent;
  411. w = w - (node.depth() + 1) * indent - node.depth() * levelIndent;
  412. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  413. //画下拉框三角形
  414. let sheet = options.sheet;
  415. if (isRationNode&& options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
  416. sheetCommonObj.drowTriangle(ctx,x+w-12,y+h/2+2);
  417. }
  418. //定额库章节树问号
  419. if(sheet.name() === 'stdRationLib_chapter' && this.enterCell && options.row === this.enterCell.row
  420. && typeof rationLibObj !== 'undefined' && rationLibObj.hasExplanationRuleText(options.row)){
  421. let centerX = Math.floor(x) + w - 20;
  422. let centerY = Math.floor((y + (y + h)) / 2);
  423. ctx.drawImage(questionImg, centerX + 3, centerY - 7, questionImgWidth,questionImgHeight);
  424. }
  425. };
  426. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  427. return {
  428. x: x,
  429. y: y,
  430. row: context.row,
  431. col: context.col,
  432. cellStyle: cellStyle,
  433. cellRect: cellRect,
  434. sheetArea: context.sheetArea
  435. };
  436. };
  437. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  438. //点击问号符,弹出说明、工程量计算规则窗口
  439. if(hitinfo.sheet.name() === 'stdRationLib_chapter' && typeof rationLibObj !== 'undefined' && rationLibObj.hasExplanationRuleText(hitinfo.row)) {
  440. if(hitinfo.x < hitinfo.cellRect.x + hitinfo.cellRect.width && hitinfo.x > hitinfo.cellRect.x + hitinfo.cellRect.width - questionImgWidth) {
  441. rationLibObj.initQuestionModal(hitinfo.row);
  442. }
  443. }
  444. let offset = -1;
  445. let node = tree.items[hitinfo.row];
  446. tree.selected = node;
  447. if(isRationNode &&hitinfo.row === hitinfo.sheet.getActiveRowIndex() && hitinfo.col === hitinfo.sheet.getActiveColumnIndex()){
  448. if( hitinfo.x > hitinfo.cellRect.x + hitinfo.cellRect.width - 17){
  449. this.clickDropDown = true;
  450. setTimeout(function () {hitinfo.sheet.startEdit();},10);
  451. return;
  452. }
  453. }
  454. if (!node || node.children.length === 0) { return; }
  455. let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  456. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  457. //方框外1像素内都有效
  458. if (hitinfo.x >= centerX - halfBoxLength - 2 && hitinfo.x <= centerX + halfBoxLength + 2 &&
  459. hitinfo.y >= centerY - halfBoxLength - 2 && hitinfo.y <= centerY + halfBoxLength + 2) {
  460. node.setExpanded(!node.expanded);
  461. let sheetName = hitinfo.sheet.name();
  462. if(sheetName === 'stdBillsLib_bills'){
  463. sessionStorage.setItem('stdBillsLibExpState', billsLibObj.stdBillsTree.getExpState(billsLibObj.stdBillsTree.items));
  464. }
  465. else if(sheetName === 'stdRationLib_chapter'){
  466. sessionStorage.setItem('stdRationLibExpState', rationLibObj.tree.getExpState(rationLibObj.tree.items));
  467. }
  468. else if(sheetName === 'stdBillsGuidance_bills'){
  469. sessionStorage.setItem('stdBillsGuidanceExpState', billsGuidance.bills.tree.getExpState(billsGuidance.bills.tree.items));
  470. }
  471. TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
  472. let iCount = node.posterityCount(), i, child;
  473. for (i = 0; i < iCount; i++) {
  474. child = tree.items[hitinfo.row + i + 1];
  475. hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
  476. //hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.vis(), hitinfo.sheetArea);
  477. }
  478. hitinfo.sheet.invalidateLayout();
  479. });
  480. hitinfo.sheet.repaint();
  481. }
  482. };
  483. TreeNodeCellType.prototype.processMouseEnter = function(hitinfo){
  484. if(hitinfo.sheet.name() === 'stdBillsGuidance_bills'){
  485. TREE_SHEET_HELPER.delayShowTips(hitinfo,setting);
  486. } else if(hitinfo.sheet.name() === 'stdRationLib_chapter'){
  487. if(this.enterCell==null){
  488. this.enterCell={
  489. row:hitinfo.row,
  490. col:hitinfo.col
  491. };
  492. hitinfo.sheet.invalidateLayout();
  493. hitinfo.sheet.repaint();
  494. }
  495. }
  496. };
  497. TreeNodeCellType.prototype.processMouseMove = function(hitinfo){//造价书主界面,当鼠标移动到单元格最右往左50个像素内时才显示悬浮提示内容
  498. if (hitinfo.sheet.name()!=="mainSheet") return;//只有在造价书主界面才显示
  499. let offset = hitinfo.cellRect.width//20;从右向左显示的像素范围 2018-11-22 这里需求又改成不悬停在编码单元格右边一部分才弹出,整个单元格都弹出,所以offset先改成单元格的宽度,防止以后又改回来
  500. let leftX = hitinfo.cellRect.x + hitinfo.cellRect.width;//最右边的坐标
  501. if(leftX - hitinfo.x <= offset){//如果鼠标移动到的位置是在显示的范围内显示悬浮提示
  502. TREE_SHEET_HELPER.delayShowTips(hitinfo,setting);
  503. }else {//如果移出了范围,隐藏悬浮提示
  504. TREE_SHEET_HELPER.hideTipsDiv();
  505. }
  506. };
  507. TreeNodeCellType.prototype.processMouseLeave = function (hitinfo) {
  508. TREE_SHEET_HELPER.hideTipsDiv();
  509. if(hitinfo.sheet.name() === 'stdRationLib_chapter') {
  510. this.enterCell = null;
  511. hitinfo.sheet.invalidateLayout();
  512. hitinfo.sheet.repaint();
  513. }
  514. };
  515. if(isRationNode){
  516. TreeNodeCellType.prototype.createEditorElement = function (context) {
  517. let div = document.createElement("div");
  518. div.setAttribute("gcUIElement", "gcEditingInput");
  519. $(div).attr("id", 'rationCheckBox');
  520. return div;
  521. };
  522. TreeNodeCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
  523. $editor = $(editorContext);
  524. $editor.css("position", "fixed");
  525. $editor.css("background", 'white');
  526. $editor.css("width", cellRect.width);
  527. $editor.css("height", cellRect.height);
  528. //$editor.attr("gcUIElement", "gcEditingInput");//padding:0 //value="${context.sheet.getValue(context.row,context.col)}"
  529. $editor.html(` <div class="input-group input-group-sm">
  530. <input type="text" id="esInput" class="form-control" autocomplete="off" style=" background-color:${cellStyle.backColor}">
  531. <div class="">
  532. <div class="triangle-border_dropdown tb-border_dropdown" id="esBtn" style="z-index:10; left: ${cellRect.width - 15+"px"};top:${cellRect.height/2-2+"px"}"></div>
  533. </div>
  534. </div>
  535. `);
  536. // <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>
  537. $editor.children('div').height(cellRect.height+2);
  538. return $editor;
  539. };
  540. TreeNodeCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  541. let me = this;
  542. $(editorContext).append(`<div><ul class="es-list" style="display: block;"></ul></div>`);//<li class="" data-value="" style=""> <br></li> //background-color:${cellStyle.backColor}
  543. $('#esInput').val(context.sheet.getValue(context.row,context.col));
  544. $('#esInput').select();
  545. projectObj.project.Ration.getNearRations(initNode.data,function(rations){
  546. if(rations.length > 0){
  547. let li_html = "";
  548. for(let r of rations){
  549. let selfstyle = ""
  550. if(r.code==initNode.data.code) selfstyle="es-list-selected" //continue; //改为不排除,标记本身
  551. li_html += `<li class="es_li ${selfstyle}" data-value="${r.code}" >${r.code} ${r.name} ${r.unit}</li>`;//定额编码+空格+定额名称+空格+定额单位。
  552. }
  553. $(".es-list").html(li_html);
  554. $(".es-list").css("min-width",cellRect.width);
  555. }
  556. if(me.clickDropDown == false) $(".es-list").hide();
  557. $(".es-list").children(".es_li").bind('click',function (e) {
  558. $('#esInput').val(this.dataset.value);
  559. $(".es-list").hide();
  560. context.sheet.endEdit();
  561. })
  562. $(".es-list").children(".es_li").hover(function(){
  563. $(this).css("background-color",cellStyle.backColor);
  564. },function(){
  565. $(this).css("background-color","");
  566. });
  567. $("#esBtn").bind('click',function(e){
  568. $(".es-list").toggle();
  569. });
  570. if( $('#esInput').val()) setCursor( $("#esInput")[0], $('#esInput').val().length)
  571. });
  572. };
  573. TreeNodeCellType.prototype.processKeyDown = function (e, context){ //当用isReservedKey 不拦截编辑模式时的input框ctrl + c时,在非编辑模式的ctrl + c事件也需要自已处理,所以在这里再调用一下复制命令
  574. //console.log(tree)
  575. if(e.keyCode === GC.Spread.Commands.Key.c && e.ctrlKey) context.sheet.getParent().commandManager().execute({cmd:"copy",sheetName:context.sheet.name()});
  576. };
  577. TreeNodeCellType.prototype.isReservedKey = function (e, context) {
  578. return e.keyCode === GC.Spread.Commands.Key.c && e.ctrlKey && !e.shiftKey && !e.altKey;//不拦截ctrl + c事件。
  579. };
  580. TreeNodeCellType.prototype.setEditorValue = function (editor, value, context) {
  581. $('#esInput').val(value);
  582. };
  583. TreeNodeCellType.prototype.getEditorValue = function (editor, context) {
  584. return $('#esInput').val()!==''? $('#esInput').val():null;
  585. };
  586. }
  587. return new TreeNodeCellType();
  588. },
  589. showTipsDiv:function (text,setting,hitinfo) {
  590. if (text && text !== '') {
  591. if(text) text = replaceAll(/[\n]/,'<br>',text);
  592. if(!this._fixedTipElement){
  593. let div = $('#fixedTip')[0];
  594. if (!div) {
  595. div = document.createElement("div");
  596. $(div).css("padding", 5)
  597. .attr("id", 'fixedTip');
  598. $(div).hide();
  599. document.body.insertBefore(div, null);
  600. }
  601. this._fixedTipElement = div;
  602. }
  603. $(this._fixedTipElement).width('');
  604. $(this._fixedTipElement).html(text);
  605. if (!this._toolTipElement) {
  606. let div = $('#autoTip')[0];
  607. if (!div) {
  608. div = document.createElement("div");
  609. $(div).addClass("message-box");
  610. $(div).attr("id", 'autoTip');
  611. $(div).hide();
  612. document.body.insertBefore(div, null);
  613. }
  614. this._toolTipElement = div;
  615. $(this._toolTipElement).width('');
  616. //实时读取位置信息
  617. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  618. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  619. }
  620. $(this._toolTipElement).html(`<span>${text}</span><div class="triangle-border tb-border_up"></div><div class="triangle-border tb-background_up"></div>`);
  621. //清单指引、清单库做特殊处理
  622. if($(hitinfo.sheet.getParent().qo).attr('id') === 'stdBillsSpread' || $(hitinfo.sheet.getParent().qo).attr('id') === 'billsGuidance_bills'){
  623. $(this._toolTipElement).html(`<span>${text}</span>`);
  624. let divWidth = $(this._fixedTipElement).width(),
  625. divHeight = $(this._fixedTipElement).height();
  626. if(divWidth > 600){
  627. divWidth = 590;
  628. $(this._toolTipElement).width(divWidth);
  629. }
  630. let top = setting.pos.y + hitinfo.y - divHeight / 2 < 0 ? 0 : setting.pos.y + hitinfo.y - divHeight / 2;
  631. $(this._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth).css;
  632. } else {
  633. //计算显示的初始位置
  634. /* 显示在单元格上方,三角形指向下的版本
  635. let top = setting.pos.y + hitinfo.cellRect.y -$(this._toolTipElement).height() -26;
  636. let left = setting.pos.x + hitinfo.cellRect.x;
  637. $(this._toolTipElement).css("top", top).css("left", left);*/
  638. //显示在下方,三角形指
  639. let top = setting.pos.y +hitinfo.cellRect.y+ hitinfo.cellRect.height+10;
  640. let left = setting.pos.x + hitinfo.cellRect.x;
  641. $(this._toolTipElement).css("top", top).css("left", left).css("max-width","500px");
  642. }
  643. $(this._toolTipElement).css('z-index', 9999);
  644. $(this._toolTipElement).show("fast");
  645. TREE_SHEET_HELPER.tipDiv = 'show';//做个标记
  646. }
  647. }
  648. },
  649. hideTipsDiv:function () {
  650. TREE_SHEET_HELPER.tipTimeStamp = +new Date();//这个是为了造价书清单编号树节点的那个延时显示而打的时间戳,防止已经要隐藏的提示框,延时显示
  651. let me = TREE_SHEET_HELPER;
  652. TREE_SHEET_HELPER.tipDiv = 'hide';
  653. if (me._toolTipElement) {
  654. $(me._toolTipElement).hide();
  655. me._toolTipElement = null;
  656. }
  657. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  658. },
  659. tipDivCheck(){
  660. setTimeout(function () {
  661. let tips = $('#autoTip');
  662. if(TREE_SHEET_HELPER.tipDiv == 'show'){
  663. return;
  664. } else if(TREE_SHEET_HELPER.tipDiv == 'hide'&&tips){
  665. tips.hide();
  666. TREE_SHEET_HELPER._toolTipElement = null;
  667. }
  668. },600)
  669. },
  670. delayShowTips:function(hitinfo,setting,tips){//延时显示
  671. let delayTimes = 200; //延时时间
  672. let now_timeStamp = +new Date();
  673. TREE_SHEET_HELPER.tipTimeStamp = now_timeStamp;
  674. setTimeout(function () {
  675. if(now_timeStamp - TREE_SHEET_HELPER.tipTimeStamp == 0){//鼠标停下的时候才显示
  676. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  677. if(tips && tips !=""){ //有tips的话优先显示tips
  678. tag = tips;
  679. }
  680. if(tag&&tag!=''){
  681. TREE_SHEET_HELPER.showTipsDiv(tag,setting,hitinfo);
  682. }
  683. }
  684. },delayTimes);
  685. },
  686. getQuestionCellType: function (mouseDownCallback = null, hasData) {
  687. let img = document.getElementById('question_pic'),
  688. imgWidth = 16,
  689. imgHeight = 16;
  690. let QuestionCellType = function () {};
  691. QuestionCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  692. QuestionCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  693. if (style.backColor) {
  694. ctx.save();
  695. ctx.fillStyle = style.backColor;
  696. ctx.fillRect(x, y, w, h);
  697. ctx.restore();
  698. } else {
  699. ctx.clearRect(x, y, w, h);
  700. }
  701. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  702. if(this.editingCell && hasData(options.row)){
  703. let centerX = Math.floor(x) + w - 20;
  704. let centerY = Math.floor((y + (y + h)) / 2);
  705. ctx.drawImage(img, centerX + 3, centerY - 7, imgWidth,imgHeight);
  706. }
  707. };
  708. QuestionCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  709. return {
  710. x: x,
  711. y: y,
  712. row: context.row,
  713. col: context.col,
  714. cellStyle: cellStyle,
  715. cellRect: cellRect,
  716. sheetArea: context.sheetArea
  717. };
  718. };
  719. QuestionCellType.prototype.processMouseDown = function (hitinfo) {
  720. //弹出说明等窗口
  721. if(this.editingCell && this.editingCell.row === hitinfo.row){
  722. let offSet = hitinfo.cellRect.x + hitinfo.cellRect.width;
  723. if(hitinfo.x < offSet && hitinfo.x > offSet - imgWidth){
  724. if(mouseDownCallback && hasData(hitinfo.row)) {
  725. mouseDownCallback(hitinfo.row);
  726. }
  727. //$('#rationQuestionModal').modal('show');
  728. }
  729. }
  730. };
  731. QuestionCellType.prototype.processMouseEnter = function (hitinfo){
  732. if(this.editingCell==null){
  733. this.editingCell={
  734. row:hitinfo.row,
  735. col:hitinfo.col
  736. };
  737. hitinfo.sheet.invalidateLayout();
  738. hitinfo.sheet.repaint();
  739. }
  740. };
  741. QuestionCellType.prototype.processMouseLeave = function (hitinfo) {
  742. this.editingCell=null;
  743. hitinfo.sheet.invalidateLayout();
  744. hitinfo.sheet.repaint();
  745. };
  746. return new QuestionCellType();
  747. }
  748. };