|
@@ -752,7 +752,139 @@ var sheetCommonObj = {
|
|
|
}
|
|
}
|
|
|
return new getTipsCombo();
|
|
return new getTipsCombo();
|
|
|
},
|
|
},
|
|
|
|
|
+ getTreeNodeCellType:function (datas,row,parentMap) {// 2018-09-26 不用spreadjs默认的树结构,自定义控件
|
|
|
|
|
+ var ns = GC.Spread.Sheets;
|
|
|
|
|
+ let rectW = 10;
|
|
|
|
|
+ let rectH = 10;
|
|
|
|
|
+ let margin = 3;
|
|
|
|
|
+
|
|
|
|
|
+ function TreeNodeCellType() {
|
|
|
|
|
+ this.collapsed = gljUtil.isDef(datas[row].collapsed)?datas[row].collapsed: true; //默认是折叠的
|
|
|
|
|
+ this. treeNodeType = true;
|
|
|
|
|
+ this.rectInfo = {};
|
|
|
|
|
+ }
|
|
|
|
|
+ TreeNodeCellType.prototype = new ns.CellTypes.Text();
|
|
|
|
|
+ TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
|
|
|
|
|
+ let offset = 0;
|
|
|
|
|
+ let step = 7;
|
|
|
|
|
+ let level = getTreeLevel(datas[row],datas);//从0开始,取当前节点是第几级的
|
|
|
|
|
+ let tem = offset+margin+ rectW/2+step;//两条线之间的间隔
|
|
|
|
|
+ let t_offset = offset;
|
|
|
|
|
+ let temParentID = datas[row].ParentID;
|
|
|
|
|
+ if(this.treeNodeType == true){
|
|
|
|
|
+ for(let i = level;i>0;i--){//这里是画子节点前面的竖线,从第二级开始
|
|
|
|
|
+ let temParent = getParent(temParentID,datas);
|
|
|
|
|
+ if(temParent){//父节点有下一个兄弟节点才需要画
|
|
|
|
|
+ if(hasNextBrother(parentMap,temParent)) sheetCommonObj.drawLine(ctx,x+t_offset+tem*i,y,x+t_offset+tem*i,y+h);
|
|
|
|
|
+ temParentID = temParent.ParentID;
|
|
|
|
|
+ }
|
|
|
|
|
+ offset +=tem;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ offset+=step; //这个没法移动,所以要两个判断
|
|
|
|
|
+ if(this.treeNodeType == true){
|
|
|
|
|
+ if(hasChildern(datas[row].ID,datas)){//如果是有子节点
|
|
|
|
|
+ //第一条 或者没有父节点(如费率子表综合里程项)不用画方框头上那条竖线其它都要
|
|
|
|
|
+ if(row !=0 && gljUtil.isDef(datas[row].ParentID)) sheetCommonObj.drawLine(ctx,x+offset+ rectW/2+margin,y,x+offset+ rectW/2+margin,y + Math.round(h / 2) - rectH / 2);
|
|
|
|
|
+ //画方框下面的那条竖线,如果没有下一个兄弟节点,则不用画
|
|
|
|
|
+ if(hasNextBrother(parentMap,datas[row])) sheetCommonObj.drawLine(ctx,x+offset+ rectW/2+margin,y + Math.round(h / 2) + rectH / 2,x+offset+ rectW/2+margin,y + h);
|
|
|
|
|
+ sheetCommonObj.drowRect(ctx, x+offset, y, w, h,rectW,rectH,margin);
|
|
|
|
|
+ sheetCommonObj.drowSymbol(ctx, x+offset, y, w, h,rectW,rectH,margin, this.collapsed);
|
|
|
|
|
+ this.rectInfo = {x:x+offset+margin,rectW:rectW}//计录一下可点击位置
|
|
|
|
|
+ }else {
|
|
|
|
|
+ let hasNext = datas[row+1]?datas[row+1].ParentID == datas[row].ParentID:false;
|
|
|
|
|
+ sheetCommonObj.drowSubItem(ctx, x, y, w, h, offset,hasNext,margin+ rectW/2);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ offset += step;
|
|
|
|
|
+ offset += rectW;
|
|
|
|
|
+ x = x + offset;//设置偏移
|
|
|
|
|
+ w = w - offset;
|
|
|
|
|
+ GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
|
|
|
|
|
+ };
|
|
|
|
|
+ // override getHitInfo to allow cell type get mouse messages
|
|
|
|
|
+ TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ x: x,
|
|
|
|
|
+ y: y,
|
|
|
|
|
+ row: context.row,
|
|
|
|
|
+ col: context.col,
|
|
|
|
|
+ cellStyle: cellStyle,
|
|
|
|
|
+ cellRect: cellRect,
|
|
|
|
|
+ sheetArea: context.sheetArea
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
|
|
|
|
|
+ ////方框外1像素内都有效
|
|
|
|
|
+ if (!_.isEmpty(this.rectInfo)&&Math.floor(hitinfo.x) <= this.rectInfo.x+this.rectInfo.rectW+2 && Math.floor(hitinfo.x) >= this.rectInfo.x-2) {
|
|
|
|
|
+ this.collapsed = !this.collapsed;
|
|
|
|
|
+ datas[row].collapsed = this.collapsed;
|
|
|
|
|
+ this.refreshChildrenVisible(hitinfo.sheet);
|
|
|
|
|
+ hitinfo.sheet.invalidateLayout();
|
|
|
|
|
+ hitinfo.sheet.repaint();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ TreeNodeCellType.prototype.refreshChildrenVisible = function (sheet) {
|
|
|
|
|
+ sheet.suspendPaint();
|
|
|
|
|
+ sheet.suspendEvent();
|
|
|
|
|
+ refreshVisible(datas[row]);
|
|
|
|
|
+ sheet.resumeEvent();
|
|
|
|
|
+ sheet.resumePaint();
|
|
|
|
|
+ function refreshVisible(item){
|
|
|
|
|
+ if(parentMap[item.ID]){
|
|
|
|
|
+ for(let sub of parentMap[item.ID]){
|
|
|
|
|
+ refreshVisible(sub)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let visible = getVisible(item);
|
|
|
|
|
+ let trow = datas.indexOf(item);
|
|
|
|
|
+ sheet.getRange(trow , -1, 1, -1).visible(visible);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getVisible(item) {
|
|
|
|
|
+ if(item.ParentID){
|
|
|
|
|
+ let parent = getParent(item.ParentID,datas);
|
|
|
|
|
+ if(!parent) return true;
|
|
|
|
|
+ let p_row= datas.indexOf(parent);
|
|
|
|
|
+ let visible = !sheet.getCellType(p_row,0).collapsed;
|
|
|
|
|
+ if(visible == true){ //如果是显示的,则要再往父节点的父节点检查,只要有一个节点是隐藏的,则都是隐藏
|
|
|
|
|
+ return getVisible(parent);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return visible
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {//如果parentID 为空则是最根节点
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ };
|
|
|
|
|
+ return new TreeNodeCellType()
|
|
|
|
|
+
|
|
|
|
|
+ function getTreeLevel(item,data) {
|
|
|
|
|
+ if(item.ParentID){
|
|
|
|
|
+ let pitem = _.find(data,{'ID':item.ParentID});
|
|
|
|
|
+ return getTreeLevel(pitem,data) + 1;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return 0
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ function hasChildern(ID,data) {//返回是否有子项
|
|
|
|
|
+ let p = _.find(data,{'ParentID':ID});
|
|
|
|
|
+ if(p) return true;
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ function getParent(ParentID,data) {
|
|
|
|
|
+ let p = _.find(data,{'ID':ParentID});
|
|
|
|
|
+ return p;
|
|
|
|
|
+ }
|
|
|
|
|
+ function hasNextBrother(parentMap,item){
|
|
|
|
|
+ let children =parentMap[item.ParentID];
|
|
|
|
|
+ if(!gljUtil.isDef(children)|| children.indexOf(item) == children.length -1) return false;
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ },
|
|
|
setDynamicCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
|
|
setDynamicCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
|
|
|
let me = this;
|
|
let me = this;
|
|
|
sheet.suspendPaint();
|
|
sheet.suspendPaint();
|