|  | @@ -0,0 +1,247 @@
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * Created by zhang on 2018/7/20.
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +let quantityEditObj = {
 | 
	
		
			
				|  |  | +    spread:null,
 | 
	
		
			
				|  |  | +    datas:[],
 | 
	
		
			
				|  |  | +    setting:{
 | 
	
		
			
				|  |  | +        header:[
 | 
	
		
			
				|  |  | +            {headerName: "基数名称", headerWidth: 250, dataCode: "name", dataType: "String"},
 | 
	
		
			
				|  |  | +            {headerName: "代码", headerWidth: 150, dataCode: "code", dataType: "String"},
 | 
	
		
			
				|  |  | +        ],
 | 
	
		
			
				|  |  | +        view: {
 | 
	
		
			
				|  |  | +            lockColumns: [0,1]
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    initSpread:function () {
 | 
	
		
			
				|  |  | +        if(!this.spread){
 | 
	
		
			
				|  |  | +            this.spread = SheetDataHelper.createNewSpread($("#quantityEditSpread")[0]);
 | 
	
		
			
				|  |  | +            this.initSheet();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        this.showData();
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    initSheet:function () {
 | 
	
		
			
				|  |  | +        this.sheet = this.spread .getSheet(0);
 | 
	
		
			
				|  |  | +        sheetCommonObj.initSheet( this.sheet, this.setting, 30);
 | 
	
		
			
				|  |  | +        this.sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick,this.onCellDoubleClick);
 | 
	
		
			
				|  |  | +        this.sheet.name('quantityEdit');
 | 
	
		
			
				|  |  | +        // console.log(cell.value());
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    showData:function () {
 | 
	
		
			
				|  |  | +        this.datas = [];//{name:'工程量明细合计',code:'GCLMXHJ'}这里暂时只有清单量一个选项
 | 
	
		
			
				|  |  | +        let selected = projectObj.project.mainTree.selected;
 | 
	
		
			
				|  |  | +        if(selected.sourceType == ModuleNames.ration){
 | 
	
		
			
				|  |  | +            this.datas.push({name:'清单量',code:'QDL'});
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        sheetCommonObj.showData(this.sheet, this.setting,this.datas);
 | 
	
		
			
				|  |  | +        this.sheet.setRowCount(this.datas.length);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    onCellDoubleClick:function (e,info) {
 | 
	
		
			
				|  |  | +        if(quantityEditObj.datas[info.row]){
 | 
	
		
			
				|  |  | +            let oldVal = $("#quantityEXPValue").val();
 | 
	
		
			
				|  |  | +            $("#quantityEXPValue").val(oldVal+quantityEditObj.datas[info.row].code);
 | 
	
		
			
				|  |  | +            $("#quantityEXPValue").focus();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    getQuantityEditCellType:function () {
 | 
	
		
			
				|  |  | +        var ns = GC.Spread.Sheets;
 | 
	
		
			
				|  |  | +        function QuantityEditCellType() {
 | 
	
		
			
				|  |  | +            var init=false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        QuantityEditCellType.prototype = new ns.CellTypes.Text();
 | 
	
		
			
				|  |  | +        QuantityEditCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
 | 
	
		
			
				|  |  | +            // if(value!=null){
 | 
	
		
			
				|  |  | +            // ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3);
 | 
	
		
			
				|  |  | +            // }
 | 
	
		
			
				|  |  | +            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
 | 
	
		
			
				|  |  | +            if(quantityEditObj.editingCell && !projectReadOnly){
 | 
	
		
			
				|  |  | +                if(quantityEditObj.editingCell.row==options.row&&quantityEditObj.editingCell.col==options.col){
 | 
	
		
			
				|  |  | +                    var image = document.getElementById('f_btn'),imageMagin = 3;
 | 
	
		
			
				|  |  | +                    var imageHeight = h-2*imageMagin;
 | 
	
		
			
				|  |  | +                    var imageWidth = w*2/7;
 | 
	
		
			
				|  |  | +                    var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
 | 
	
		
			
				|  |  | +                    ctx.save();
 | 
	
		
			
				|  |  | +                    ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
 | 
	
		
			
				|  |  | +                    ctx.beginPath();
 | 
	
		
			
				|  |  | +                    ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
 | 
	
		
			
				|  |  | +                    ctx.arc(imageX+imageWidth/2-4,imageY+imageHeight/2,1,0,360,false);
 | 
	
		
			
				|  |  | +                    ctx.arc(imageX+imageWidth/2+4,imageY+imageHeight/2,1,0,360,false);
 | 
	
		
			
				|  |  | +                    ctx.fillStyle="black";//填充颜色,默认是黑色
 | 
	
		
			
				|  |  | +                    ctx.fill();//画实心圆
 | 
	
		
			
				|  |  | +                    ctx.closePath();
 | 
	
		
			
				|  |  | +                    ctx.restore();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        QuantityEditCellType.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
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        QuantityEditCellType.prototype.processMouseDown = function (hitinfo) {
 | 
	
		
			
				|  |  | +            var me=quantityEditObj;
 | 
	
		
			
				|  |  | +            me.pmLeave = false;
 | 
	
		
			
				|  |  | +            if(me.editingCell==null){
 | 
	
		
			
				|  |  | +                var showSelectBtn = true;
 | 
	
		
			
				|  |  | +                if(showSelectBtn){
 | 
	
		
			
				|  |  | +                    me.editingCell={
 | 
	
		
			
				|  |  | +                        row:hitinfo.row,
 | 
	
		
			
				|  |  | +                        col:hitinfo.col
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    hitinfo.sheet.invalidateLayout();
 | 
	
		
			
				|  |  | +                    hitinfo.sheet.repaint();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }else if(hitinfo.row==me.editingCell.row){
 | 
	
		
			
				|  |  | +                var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
 | 
	
		
			
				|  |  | +                var imageMagin=3;
 | 
	
		
			
				|  |  | +                var imageHeight = hitinfo.cellRect.height-2*imageMagin;
 | 
	
		
			
				|  |  | +                var imageWidth = hitinfo.cellRect.width*2/7;
 | 
	
		
			
				|  |  | +                if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
 | 
	
		
			
				|  |  | +                    if(!projectReadOnly){
 | 
	
		
			
				|  |  | +                        me.showSelectModal(hitinfo);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        QuantityEditCellType.prototype.processMouseEnter = function (hitinfo) {
 | 
	
		
			
				|  |  | +            let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
 | 
	
		
			
				|  |  | +            let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
 | 
	
		
			
				|  |  | +            let dataField = "quantity";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if(hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).wordWrap()==true){
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(dataField=="quantity"){
 | 
	
		
			
				|  |  | +                text = tag;
 | 
	
		
			
				|  |  | +            }else if(tag !== undefined && tag) {
 | 
	
		
			
				|  |  | +                text = tag;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (text && text !== '') {
 | 
	
		
			
				|  |  | +                if (!this._toolTipElement) {
 | 
	
		
			
				|  |  | +                    let div = $('#autoTip')[0];
 | 
	
		
			
				|  |  | +                    if (!div) {
 | 
	
		
			
				|  |  | +                        div = document.createElement("div");
 | 
	
		
			
				|  |  | +                        $(div).css("position", "absolute")
 | 
	
		
			
				|  |  | +                            .css("border", "1px #C0C0C0 solid")
 | 
	
		
			
				|  |  | +                            .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
 | 
	
		
			
				|  |  | +                            .css("font", "9pt Arial")
 | 
	
		
			
				|  |  | +                            .css("background", "white")
 | 
	
		
			
				|  |  | +                            .css("padding", 5)
 | 
	
		
			
				|  |  | +                            .attr("id", 'autoTip');
 | 
	
		
			
				|  |  | +                        $(div).hide();
 | 
	
		
			
				|  |  | +                        document.body.insertBefore(div, null);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    this._toolTipElement = div;
 | 
	
		
			
				|  |  | +                    $(this._toolTipElement).text(text);
 | 
	
		
			
				|  |  | +                    let cellRect =  hitinfo.sheet.getCellRect(hitinfo.row,hitinfo.col);
 | 
	
		
			
				|  |  | +                    $(this._toolTipElement).css("top", cellRect.y+$('#main').offset().top+cellRect.height).css("left",  hitinfo.x );//
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    $(this._toolTipElement).show("fast");
 | 
	
		
			
				|  |  | +                    TREE_SHEET_HELPER.tipDiv = 'show';//做个标记
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        QuantityEditCellType.prototype.processMouseLeave = function (hitinfo) {
 | 
	
		
			
				|  |  | +            if(!quantityEditObj.pmLeave){
 | 
	
		
			
				|  |  | +                quantityEditObj.editingCell=null;
 | 
	
		
			
				|  |  | +                hitinfo.sheet.invalidateLayout();
 | 
	
		
			
				|  |  | +                hitinfo.sheet.repaint();
 | 
	
		
			
				|  |  | +                quantityEditObj.pmLeave = true;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            let me = this;
 | 
	
		
			
				|  |  | +            TREE_SHEET_HELPER.tipDiv = 'hide';
 | 
	
		
			
				|  |  | +            if (me._toolTipElement) {
 | 
	
		
			
				|  |  | +                $(me._toolTipElement).hide();
 | 
	
		
			
				|  |  | +                me._toolTipElement = null;
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +            TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        return new QuantityEditCellType();
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    showSelectModal:function (hitinfo) {
 | 
	
		
			
				|  |  | +        //锁定的清单不显示
 | 
	
		
			
				|  |  | +        let project = projectObj.project;
 | 
	
		
			
				|  |  | +        if(project.isBillsLocked() && project.withinBillsLocked(project.mainTree.selected)){
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $("#quantityEXPEdit").modal({show:true});
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    checkingAndUpdate(quantityEXP,node){
 | 
	
		
			
				|  |  | +        let me = this;
 | 
	
		
			
				|  |  | +        quantityEXP = quantityEXP.toUpperCase();
 | 
	
		
			
				|  |  | +        if(quantityEXP === node.data.quantityEXP){ //没有变化,不做任何操作
 | 
	
		
			
				|  |  | +            projectObj.mainController.refreshTreeNode([node]);
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        let value = me.evalQuantityExp(quantityEXP,node);
 | 
	
		
			
				|  |  | +        if(value!=='evalError'){
 | 
	
		
			
				|  |  | +            if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
 | 
	
		
			
				|  |  | +                hintBox.infoBox('操作确认', '已有工程量明细,是否清空明细表,采用手工输入的表达式?', 2, function () {
 | 
	
		
			
				|  |  | +                    node.data.isFromDetail=0;
 | 
	
		
			
				|  |  | +                    me.updateQuantityEXP(value,quantityEXP,node);
 | 
	
		
			
				|  |  | +                }, function () {
 | 
	
		
			
				|  |  | +                    projectObj.mainController.refreshTreeNode([node]);
 | 
	
		
			
				|  |  | +                },['确定','取消'],false);
 | 
	
		
			
				|  |  | +                return;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            me.updateQuantityEXP(value,quantityEXP,node);
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  | +            projectObj.mainController.refreshTreeNode([node]);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    evalQuantityExp(quantityEXP,node){
 | 
	
		
			
				|  |  | +        let evalString = quantityEXP;
 | 
	
		
			
				|  |  | +        if( node.sourceType == ModuleNames.ration && quantityEXP.indexOf('QDL')!=-1){
 | 
	
		
			
				|  |  | +            let billNode = node.parent;
 | 
	
		
			
				|  |  | +            let bQuantity = billNode.data.quantity?scMathUtil.roundForObj(billNode.data.quantity,getDecimal("quantity",billNode)):0;
 | 
	
		
			
				|  |  | +            evalString = replaceAll("QDL","("+bQuantity+")",evalString);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            let value = eval(evalString);
 | 
	
		
			
				|  |  | +            return value;
 | 
	
		
			
				|  |  | +        }catch (error){
 | 
	
		
			
				|  |  | +            alert("输入的表达式有误,请重新输入!");
 | 
	
		
			
				|  |  | +            return "evalError"
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    updateQuantityEXP:function (value,quantityEXP,node) {
 | 
	
		
			
				|  |  | +        let quantity_detail = projectObj.project.quantity_detail;
 | 
	
		
			
				|  |  | +        quantity_detail.cleanQuantityDetail(node,true);
 | 
	
		
			
				|  |  | +        if(node.sourceType === ModuleNames.bills){
 | 
	
		
			
				|  |  | +            quantity_detail.updateBillQuantity(value,node,quantityEXP,quantityEXP);
 | 
	
		
			
				|  |  | +            //me.updateBillQuantity(value,node,null,editingText);
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  | +            quantity_detail.updateRationQuantity(value,node,quantityEXP,quantityEXP);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +$(function(){
 | 
	
		
			
				|  |  | +    $('#quantityEXPEdit').on('shown.bs.modal', function (e) {
 | 
	
		
			
				|  |  | +        let selected = projectObj.project.mainTree.selected;
 | 
	
		
			
				|  |  | +        $("#quantityEXPValue").val(selected.data.quantityEXP);
 | 
	
		
			
				|  |  | +        quantityEditObj.initSpread();
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    $('#operation_p').children("button").bind('click',function (){
 | 
	
		
			
				|  |  | +        let oldVal = $("#quantityEXPValue").val();
 | 
	
		
			
				|  |  | +        $("#quantityEXPValue").val(oldVal+$(this).text());
 | 
	
		
			
				|  |  | +        $("#quantityEXPValue").focus();
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    $("#quantityEditConf").bind('click',function () {
 | 
	
		
			
				|  |  | +        let selected = projectObj.project.mainTree.selected;
 | 
	
		
			
				|  |  | +        quantityEditObj.checkingAndUpdate($("#quantityEXPValue").val(),selected);
 | 
	
		
			
				|  |  | +        $("#quantityEXPEdit").modal('hide');
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +});
 |