tree_sheet_helper.js 37 KB

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