|  | @@ -0,0 +1,186 @@
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * Created by CSL on 2018-09-19.
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +var blockLibObj = {
 | 
	
		
			
				|  |  | +    datas: [],
 | 
	
		
			
				|  |  | +    mainSpread: null,
 | 
	
		
			
				|  |  | +    mainSheet: null,
 | 
	
		
			
				|  |  | +    mainSetting: {
 | 
	
		
			
				|  |  | +        header:[
 | 
	
		
			
				|  |  | +            {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"}
 | 
	
		
			
				|  |  | +        ],
 | 
	
		
			
				|  |  | +        view:{
 | 
	
		
			
				|  |  | +            comboBox:[],
 | 
	
		
			
				|  |  | +            lockColumns:[],
 | 
	
		
			
				|  |  | +            colHeaderHeight: CP_Col_Width.colHeader,
 | 
	
		
			
				|  |  | +            rowHeaderWidth: CP_Col_Width.rowHeader
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    buildSheet: function (){
 | 
	
		
			
				|  |  | +        let me = this;
 | 
	
		
			
				|  |  | +        me.datas = [];
 | 
	
		
			
				|  |  | +        if (me.mainSpread) {
 | 
	
		
			
				|  |  | +            me.mainSpread.destroy();
 | 
	
		
			
				|  |  | +            me.mainSpread = null;
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        me.mainSpread = sheetCommonObj.buildSheet($('#div_block_tree')[0], me.mainSetting, me.datas.length);
 | 
	
		
			
				|  |  | +        sheetCommonObj.spreadDefaultStyle(me.mainSpread);
 | 
	
		
			
				|  |  | +        me.mainSheet = me.mainSpread.getSheet(0);
 | 
	
		
			
				|  |  | +        // sheetCommonObj.showData(me.mainSheet, me.mainSetting, me.datas);
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    showData: function () {
 | 
	
		
			
				|  |  | +        let me = this;
 | 
	
		
			
				|  |  | +        let sheet =me.mainSheet;
 | 
	
		
			
				|  |  | +        let cols = me.mainSetting.header;
 | 
	
		
			
				|  |  | +        let datas = me.datas;
 | 
	
		
			
				|  |  | +        let fuc = function () {
 | 
	
		
			
				|  |  | +            sheet.setRowCount(datas.length);
 | 
	
		
			
				|  |  | +            me.initTree(true);
 | 
	
		
			
				|  |  | +            // sheet.setFormatter(-1, 1, '@');
 | 
	
		
			
				|  |  | +            for(let col = 0, cLen = cols.length; col < cLen; col++){
 | 
	
		
			
				|  |  | +                // sheet.getRange(-1, col, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[cols[col]['hAlign']]);
 | 
	
		
			
				|  |  | +                // sheet.getRange(-1, col, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[cols[col]['vAlign']]);
 | 
	
		
			
				|  |  | +                for(let row = 0, rLen = datas.length; row < rLen; row++){
 | 
	
		
			
				|  |  | +                    sheet.setValue(row, col, datas[row][cols[col]['dataCode']]);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        sheet.suspendPaint();
 | 
	
		
			
				|  |  | +        sheet.suspendEvent();
 | 
	
		
			
				|  |  | +        fuc();
 | 
	
		
			
				|  |  | +        sheet.resumePaint();
 | 
	
		
			
				|  |  | +        sheet.resumeEvent();
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    initTree: function (collapse) {
 | 
	
		
			
				|  |  | +        let me = this;
 | 
	
		
			
				|  |  | +        me.mainSheet.getRange(-1, 0, -1, 1).cellType(me.getTreeNodeCellType(me.datas));
 | 
	
		
			
				|  |  | +        for(let i =0, len = me.datas.length; i < len; i++){
 | 
	
		
			
				|  |  | +            if(me.datas[i].hasOwnProperty('items')){
 | 
	
		
			
				|  |  | +                let collapsed = false;
 | 
	
		
			
				|  |  | +                if(collapse){
 | 
	
		
			
				|  |  | +                    me.datas[i].collapsed = false;
 | 
	
		
			
				|  |  | +                    collapsed = true;
 | 
	
		
			
				|  |  | +                }else {
 | 
	
		
			
				|  |  | +                    collapsed = me.datas[i].collapsed == undefined ? true : me.datas[i].collapsed;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    getTreeNodeCellType: function (data) {
 | 
	
		
			
				|  |  | +        var ns = GC.Spread.Sheets;
 | 
	
		
			
				|  |  | +        var rectW = 10;
 | 
	
		
			
				|  |  | +        var rectH = 10;
 | 
	
		
			
				|  |  | +        var margin = 3;
 | 
	
		
			
				|  |  | +        function TreeNodeCellType() {
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        function drowRect(ctx,x,y,w,h) {///
 | 
	
		
			
				|  |  | +            ctx.save();
 | 
	
		
			
				|  |  | +            ctx.strokeStyle = "gray";
 | 
	
		
			
				|  |  | +            ctx.translate(0.5,0.5);
 | 
	
		
			
				|  |  | +            ctx.beginPath();
 | 
	
		
			
				|  |  | +            var rectX = x+margin;
 | 
	
		
			
				|  |  | +            var rectY =  y+ Math.round(h/2)-rectH/2;
 | 
	
		
			
				|  |  | +            ctx.moveTo(rectX, rectY);
 | 
	
		
			
				|  |  | +            ctx.lineTo(rectX, rectY+rectH);
 | 
	
		
			
				|  |  | +            ctx.lineTo(rectX+rectW, rectY+rectH);
 | 
	
		
			
				|  |  | +            ctx.lineTo(rectX+rectW, rectY);
 | 
	
		
			
				|  |  | +            ctx.lineTo(rectX, rectY);
 | 
	
		
			
				|  |  | +            ctx.moveTo(rectX+rectW, y+Math.round(h/2));
 | 
	
		
			
				|  |  | +            ctx.lineTo(rectX+rectW+5, y+Math.round(h/2));
 | 
	
		
			
				|  |  | +            ctx.stroke();
 | 
	
		
			
				|  |  | +            ctx.restore();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        function drowSymbol(ctx,x,y,w,h,collapsed) {
 | 
	
		
			
				|  |  | +            ctx.save();
 | 
	
		
			
				|  |  | +            ctx.strokeStyle = "#000000";
 | 
	
		
			
				|  |  | +            ctx.translate(0.5, 0.5);
 | 
	
		
			
				|  |  | +            ctx.beginPath();
 | 
	
		
			
				|  |  | +            ctx.moveTo(x+margin+2, y+Math.round(h/2));
 | 
	
		
			
				|  |  | +            ctx.lineTo(x+margin+8, y+Math.round(h/2));
 | 
	
		
			
				|  |  | +            var rectY =  y+ Math.round(h/2)-rectH/2;
 | 
	
		
			
				|  |  | +            if(collapsed){
 | 
	
		
			
				|  |  | +                ctx.moveTo(x+margin+rectW/2,rectY+2);
 | 
	
		
			
				|  |  | +                ctx.lineTo(x+margin+rectW/2,rectY+2+6);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            ctx.stroke();
 | 
	
		
			
				|  |  | +            ctx.restore();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        function drowSubItem(ctx,x,y,w,h,offset,nextItem) {
 | 
	
		
			
				|  |  | +            offset+=6;
 | 
	
		
			
				|  |  | +            ctx.save();
 | 
	
		
			
				|  |  | +            ctx.strokeStyle = "gray";
 | 
	
		
			
				|  |  | +            ctx.translate(0.5, 0.5);
 | 
	
		
			
				|  |  | +            ctx.beginPath();
 | 
	
		
			
				|  |  | +            ctx.moveTo(x+offset, y);
 | 
	
		
			
				|  |  | +            ctx.lineTo(x+offset, y+Math.round(h/2));
 | 
	
		
			
				|  |  | +            offset+=9;
 | 
	
		
			
				|  |  | +            ctx.lineTo(x+offset, y+Math.round(h/2));
 | 
	
		
			
				|  |  | +            if(nextItem&&!nextItem.hasOwnProperty('items')){
 | 
	
		
			
				|  |  | +                ctx.moveTo(x+offset-9, y+Math.round(h/2));
 | 
	
		
			
				|  |  | +                ctx.lineTo(x+offset-9, y+h);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            ctx.stroke();
 | 
	
		
			
				|  |  | +            ctx.restore();
 | 
	
		
			
				|  |  | +            return offset;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        TreeNodeCellType.prototype = new ns.CellTypes.Text();
 | 
	
		
			
				|  |  | +        TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
 | 
	
		
			
				|  |  | +            if(value!=null){
 | 
	
		
			
				|  |  | +                var offset = margin+rectW+6;
 | 
	
		
			
				|  |  | +                var recode = data[options.row];
 | 
	
		
			
				|  |  | +                if(recode&&recode.hasOwnProperty('items')){
 | 
	
		
			
				|  |  | +                    drowRect(ctx,x,y,w,h);
 | 
	
		
			
				|  |  | +                    var collapsed = recode.collapsed==undefined?true:recode.collapsed;//options.sheet.getTag(options.row,options.col);
 | 
	
		
			
				|  |  | +                    drowSymbol(ctx,x,y,w,h,collapsed);
 | 
	
		
			
				|  |  | +                }else if(recode&&!recode.hasOwnProperty('items')){
 | 
	
		
			
				|  |  | +                    offset= drowSubItem(ctx,x,y,w,h,offset,data[options.row+1]);
 | 
	
		
			
				|  |  | +                    offset+=1;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                arguments[2] = x + offset;
 | 
	
		
			
				|  |  | +                arguments[4] = w - offset;
 | 
	
		
			
				|  |  | +                GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        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) {
 | 
	
		
			
				|  |  | +            var recode = data[hitinfo.row];
 | 
	
		
			
				|  |  | +            if(recode&&recode.hasOwnProperty('items')){
 | 
	
		
			
				|  |  | +                var hoffset= hitinfo.cellRect.x+3;
 | 
	
		
			
				|  |  | +                if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10){
 | 
	
		
			
				|  |  | +                    var collapsed = recode.collapsed==undefined?true:recode.collapsed;
 | 
	
		
			
				|  |  | +                    collapsed = !collapsed
 | 
	
		
			
				|  |  | +                    recode.collapsed=collapsed;
 | 
	
		
			
				|  |  | +                    //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
 | 
	
		
			
				|  |  | +                    hitinfo.sheet.getRange(hitinfo.row+1, -1, recode.items.length, -1).visible(!collapsed);
 | 
	
		
			
				|  |  | +                    hitinfo.sheet.invalidateLayout();
 | 
	
		
			
				|  |  | +                    hitinfo.sheet.repaint();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        return new TreeNodeCellType();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +$(document).ready(function(){
 | 
	
		
			
				|  |  | +/*    if (!blockLibObj.mainSpread){
 | 
	
		
			
				|  |  | +        blockLibObj.buildSheet();
 | 
	
		
			
				|  |  | +        blockLibObj.showData();
 | 
	
		
			
				|  |  | +    }*/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +});
 |