if(!wd.form){ wd.form={}; } function divShow(){} function loadBgbj(){} wd.form._table=function(){ this.cells=null;//单元格集合 this.allcells=null;//除了录入单元格,包括图片,文字 this.tableId=null; this.assignField=null; this._dom=null; this.exportDataToField=function(){}; this._isMouseMove=false; this._dragKey=null; this._zoom=1; this._minZoom=1; this._maxZoom=1; this._certify=function(data){ if(!data){alert("nonononono");return} for(var i=0;i= 0){ code="dynamic&codebookstr="+encodeURIComponent(c); }else{ code=c; } var url=wd.display.replaceDynamicParam(editurl,{bgmbid:bgmbid,codebook:code}); eval(url); } })() } } } THIS._dragKey=mark+"drag"; if(document.querySelector("[name="+mark+"id]")){ THIS.tableId=document.querySelector("[name="+mark+"id]").value; } if(!THIS.tableId){ console.log(mark+"id为空"); return; } THIS._dom=document.querySelector("#"+mark+"Edit"); $.ajax({ type:"post", data:{ pmtid:THIS.tableId }, url:loadurl, async:false, success:function(re){ THIS._dom.innerHTML=re; } }); /*// var colNum = $("div[hl^='1_']").length; var rowNum = $("div[hl*='_']").length / colNum // var containerWidth = $(THIS._dom).width() - 30 var containerHeight = $(THIS._dom).height() - 30 var wr = containerWidth / ($("div[hl='1_1']").outerWidth() * colNum) var hr = containerHeight / ($("div[hl='1_1']").outerHeight() * rowNum) $("div[hl^='4_']").each(function (idx) { var preWidth = $(this).width() $(this).width(preWidth * wr) var afterWidth = $(this).width() var preHeight = $(this).height() $(this).height(preHeight * hr) var afterHeight = $(this).height() if ($(this).attr("hl") != "4_1") { $(this).css({"left": parseFloat($(this).css("left")) + (afterWidth - preWidth) * idx}) // $(this).css({"top": parseFloat($(this).css("top")) + (preHeight - afterHeight) * idx}) } }) for (var i = 1; i<=rowNum; i++) { $("div[hl^='" + i + "_']").each(function (idx) { $(this).width($("div[hl='4_" + (idx + 1) + "']").width()) $(this).height($("div[hl='4_" + (idx + 1) + "']").height()) $(this).css({ "left": parseFloat($("div[hl='4_" + (idx + 1) + "']").css("left")) }) if (i > 1) { $(this).css({ "top": parseFloat($("div[hl='" + (i-1) + "_1']").position().top + $("div[hl='" + (i-1) + "_1']").height()) }) } }) }*/ //全部单元格 var allcells = $(THIS._dom).find("[bgbjlbm]"); allcells.each(function(){ var c=new wd.form._cell(); c._load(THIS,this); if(this.getAttribute("bgbjlbm")==1){ THIS.cells.push(c); } THIS.allcells.push(c); }) THIS.assignField=document.querySelector("[name="+mark+"data]"); var c=THIS.assignField.value; if(c&&c.length>0){ var j=JSON.parse(c); THIS._certify(j); } THIS.refresh(); THIS._dom.style.position="relative"; // THIS._dom.style.overflow="hidden"; var setwidth=false; var setheight=false; if(!THIS._dom.style.width){ THIS._dom.style.width="95%" setwidth=true; } if(!THIS._dom.style.height){ THIS._dom.style.height="95%"; setheight=true; } THIS._dom.style.zoom=1; THIS._dom.style.transform = "scale(1)"; THIS._dom.style.transformOrigin = "left top"; THIS._dom.style.overflow = null; THIS._dom.style.border = "none" var minZoom=1; var zoomcount = 0; // while(document.documentElement.clientHeight1000){ // console.log("zooom count fail"); // THIS._dom.style.zoom = 1; // THIS._zoom=1; // THIS._minZoom = 1; // // break; // } // // var zoom=parseFloat( THIS._dom.style.zoom); // var zoom = parseFloat($(THIS._dom).css("transform").replace(/[^0-9\\.]*/ig,"")); // // minZoom=zoom-0.05; // // THIS._dom.style.zoom=minZoom; // THIS._dom.style.transform = "scale(" + minZoom + ")"; // THIS._zoom=minZoom; // THIS._minZoom = minZoom; // // } THIS._zoom=1; THIS._minZoom = 1; var dWidth=$(THIS._dom).width(); var dHeight=$(THIS._dom).height(); var mWidth=0; var mHeight=0; for(var i=0;i0){ // THIS._zoom=THIS._maxZoom; // }else{ // THIS._zoom=THIS._minZoom; // } // if(this.style.zoom==THIS._zoom){return}; // this.style.zoom=THIS._zoom; // this.scrollLeft=x/THIS._zoom-this.clientWidth/2; // this.scrollTop=y/THIS._zoom-this.clientHeight/2; // // if(THIS._maxZoom==THIS._minZoom||THIS._minZoom==THIS._zoom){ // shrinkButton.style.display="none"; // }else{ // shrinkButton.style.display=""; // } // // } THIS._dom.ondblclick=function(){ var e=window.event; var x=THIS.findx(e); var y=THIS.findy(e); if(THIS._zoom!=THIS._maxZoom){ THIS._zoom=THIS._maxZoom; this.style.cursor="-webkit-grab" }else{ THIS._zoom=THIS._minZoom; this.style.cursor="default"; } // this.style.zoom=THIS._zoom; THIS._zoomAllCell(THIS._zoom); this.scrollLeft=x/THIS._zoom-this.clientWidth/2; this.scrollTop=y/THIS._zoom-this.clientHeight/2; if(THIS._maxZoom==THIS._minZoom||THIS._minZoom==THIS._zoom){ shrinkButton.style.display="none" }else{ shrinkButton.style.display="" } } // document.oncontextmenu=function(){ // window.event.preventDefault() // }; // console.log(THIS._zoom+" "+THIS._maxZoom) THIS._dom.onmousedown=function(){ THIS._isMouseMove=false; var that=this; var e=window.event; // console.log(THIS) //缩小状态 if(THIS._zoom!=THIS._maxZoom){ THIS._dom.onmousemove=function(){ THIS._bindRegionSelectEvent(); } THIS._dom.onmouseup=function(){ shrinkButton.style.display=""; THIS._zoom=THIS._maxZoom; THIS._dom.style.zoom=THIS._maxZoom; THIS._dom.onmousemove=null; } //正常状态 }else{ //没有缩小状态,变成拖选 if(THIS._minZoom==THIS._maxZoom){ // console.log("cc") THIS._bindRegionSelectEvent(); }else{ THIS._bindClimbEvent(); } } // } THIS._findDragItem(); if(THIS.loadFinish){ THIS.loadFinish(); } }) } this._findDragItem=function(){ var items=document.querySelectorAll("["+this._dragKey+"=true]"); for(var i=0;i=y&&pos.left<=x&&(pos.left+pos.width)>=x){ cell.check(); selectedCell=cell; }else{ cell.uncheck(); } } }) $(document).on("mouseup.wdform",function(){ $(".wdformghost").remove(); item.style.cursor="pointer"; item.style.display=""; if(selectedCell){ var result=THIS.dragToCell(item,selectedCell) selectedCell=null; $(item).remove(); THIS.refresh() } $(document).off("mousemove.wdform"); $(document).off("mouseup.wdform"); setTimeout(function(){ $(document).off("mousemove.wdform"); $(document).off("mouseup.wdform"); },500); }) }) } this.findx=function(event){ var a=event.srcElement; var result=event.offsetX; var c=0; while(a!=this._dom){ if(c==10){console.log("mmmm");break;} c++; result+=a.offsetLeft a=a.offsetParent; } return result; } this.findy=function(event){ var a=event.srcElement; var result=event.offsetY; var c=0; while(a!=this._dom){ if(c==10){console.log("mmmm");break;} c++; result+=a.offsetTop a=a.offsetParent; } return result; } this._bindRegionSelectEvent=function(){ var e=window.event; var THIS=this; var selectDiv; if(!document.getElementById("selContainer")){ selectDiv = document.createElement("div"); selectDiv.style.cssText = "position:absolute;width:0px;height:0px;font-size:0px;margin:0px;padding:0px;border:1px dashed #0099FF;background-color:#C3D5ED;z-index:1000;filter:alpha(opacity:60);opacity:0.6;display:'';"; selectDiv.id = "selContainer"; THIS._dom.appendChild(selectDiv); }else{ selectDiv = document.getElementById("selContainer"); } var startX=THIS.findx(e); var startY=THIS.findy(e); selectDiv.style.display="none"; THIS._isMouseMove=false; if(e.which!=1){ return ; } var count=0; THIS._dom.onmousemove=null; THIS._dom.onmouseup=null; THIS._dom.onmouseout=null; THIS._dom.onmousemove=function(){ count++; if(count<5)return THIS._isMouseMove=true; var e=window.event; e.preventDefault(); var poxX=THIS.findx(e); var poxY=THIS.findy(e); selectDiv.style.display="" selectDiv.style.left = Math.min(poxX, startX)+"px"; selectDiv.style.top = Math.min(poxY, startY)+"px"; selectDiv.style.width = Math.abs(poxX - startX)+"px"; selectDiv.style.height = Math.abs(poxY - startY)+"px"; var s=[]; s[0]=[parseInt(selectDiv.style.left),parseInt(selectDiv.style.top)]; s[1]=[parseInt(selectDiv.style.left)+parseInt(selectDiv.style.width),parseInt(selectDiv.style.top)+parseInt(selectDiv.style.height)]; for(var i=0;i0){ var imageEle=document.createElement("img"); imageEle.setAttribute("src",cell.image); imageEle.style.maxHeight=50; imageEle.style.maxHeight=50; // cell._dom.querySelector("td").style.maxWidth="auto"; // cell._dom.querySelector("td").style.height="auto"; // cell._dom.querySelector("td").appendChild(imageEle); cell._dom.appendChild(imageEle); } } wd.form._table.prototype._setCellClass=function(cell){ // wd.form.pmt.cellClass={ //objectState:{“1”:” “.clean”,”2”:” .broken”}, //usageState:{“1”:” “.freeed”,”3”:” .using”}, //} var cellclass=this.cellClass; var classValue=""; // for(var key in cellclass){ // if(key==cell.state){ // classValue=cellclass[key]; // } // } if(cellclass.objectState&&cell.objectState){ for(var key in cellclass.objectState){ if(key==cell.objectState){ classValue+=" "+cellclass.objectState[key]; } } } if(cellclass.usageState&&cell.usageState){ for(var key in cellclass.usageState){ if(key==cell.usageState){ classValue+=" "+cellclass.usageState[key]; } } } if(classValue&&classValue.length>0){ cell._dom.setAttribute("class",classValue); }else{ cell._dom.setAttribute("class",cell._dom.getAttribute("class")||"default"); } } wd.form._table.prototype.getCurrCells=function(){ var a=[]; for(var i=0;i" var inp=cell._dom.querySelector("input"); function _inputFinish(){ cell._dom.removeChild(inp); if(inp.value&&inp.value.length>0){ if(callback){ callback.call(THIS,inp.value,cell); }else{ cell.text=inp.value; } THIS.refresh() } } inp.onkeyup=function(){ // window.event.preventDefault(); var e=window.event; e.stopPropagation(); if(e.keyCode==13){ _inputFinish() } } inp.onblur=function(){ _inputFinish() } inp.select(); } //[ // //{ //ID:单元格ID, //NO:单元格序号, //lineNum: 行号, //columnNum:列号,//对于特定的单元格数据,单元格ID、单元格编号、行列号这三者必需至少有其中一项,否则程序无法得知是那个单元格 //text: 单元格中的文字 //image: “\abc\123.jsp”//单元格中的图片路径(在页面显示时会被转换为token) //objectName:单元格关联的对象名(现在座位号床位号也放这) //objectID: 单元格关联的对象ID //state:状态值,例如1代表空闲、2代表已预订、3代表已入住等 //objectState //usageState //data:{业务数据} //}, //{//另一单元格数据 //} //] wd.form._cell=function(){ this._certeria=null; this.ID=null;//单元格ID this.NO=null;//单元格序号 this.lineNum=null;//行号 this.columnNum=null;//列号 this.objectID=null;//单元格关联的对象ID this.objectName=null;//状态值,例如1代表空闲、2代表已预订、3代表已入住等 this.text=null;//单元格中的文字 this.image=null;//单元格中的图片路径(在页面显示时会被转换为token) // this.state=null; this.objectState=null; this.usageState=null; this.data=null;//业务数据 this._table=null; this._dom=null; this.checked=false; this._originSize=null; this._currentSize=null this._load=function(table,dom){ var THIS=this; this._table=table; this._dom=dom; var position=$(dom).position(); this._originSize={ left:position.left, top:position.top, width:$(dom).width(), height:$(dom).height() }; this._currentSize={ left:position.left, top:position.top, width:$(dom).width(), height:$(dom).height() }; var id=dom.getAttribute("id"); var name=dom.getAttribute("name"); var xh=dom.getAttribute("xh"); var hl=dom.getAttribute("hl"); var dxm=dom.getAttribute("dxm"); var dxid=dom.getAttribute("dxid"); this.ID=id.replace(/[^0-9]/,""); if(hl){ this.lineNum=parseInt(hl.split("_")[0]) ; this.columnNum=parseInt(hl.split("_")[1]) ; } if(dxm){ this.objectName=dxm; } if(xh){ this.NO=parseInt(xh) } if(dxid){ this.objectID=dxid; } this._dom.onmouseenter=(function(){ return function(){ if(THIS._table._isMouseMove){ return; } THIS._table.hover(THIS) THIS._table.mouseenter(THIS); } })() this._dom.onmouseout=(function(){ return function(){ if(THIS._table._isMouseMove){ return; } THIS._table.mouseout(THIS); } })() this._dom.onclick=(function(){ return function (){ // window.event.preventDefault() // window.event.stopPropagation() // console.log(THIS); //点击选中 if( (window.event.ctrlKey||window.event.shiftKey)&&window.event.button==0 ){ if(THIS.checked==false){ THIS.check() }else{ THIS.uncheck() } }else{ var allcheck=THIS._table.cells; // for(var i=0; i< allcheck.length;i++){ // allcheck[i].uncheck(); // } if(THIS.checked==false){ THIS.check() }else if(THIS.checked==true){ THIS.uncheck() } } THIS._click(); } })() this._dom.onmousedown=(function(){ return function(){ if(window.event.which==3){ THIS._table.rightClick(THIS); // console.log(THIS) } } })() this._dom.ondblclick=(function(){ return function (){ var e=window.event; e.stopPropagation() e.preventDefault(); console.log(this) } })() } this._click=function(){ // e.which==3// 1 = 鼠标左键 left; 2 = 鼠标中键; 3 = 鼠标右键 if(this._table._isMouseMove){ return; } this._table.leftClick(this); // var which=window.event.which; //// console.log("click "+which) // switch (which){ // case 1: // this._table.leftClick(this); // break; //// case 3: //// this._table.rightClick(this) //// break; // } } this._setProfile=function(profile,certeria){ this._certeria=certeria; if(this._certeria.length==2){ // console.log(this._certeria) // this.lineNum=profile.lineNum; // this.columnNum=profile.columnNum; }else if(this._certeria.length==1){ if(this._certeria[0]=="ID"){ // this.ID=profile.ID; }else if(this._certeria[0]=="NO"){ // this.code=profile.code; }else{ console.log("出问题了!") } }else{ console.log("出问题了!") } // console.log(profile) // this.state=profile.state?profile.state:null; this.objectState=profile.objectState?profile.objectState:null; this.usageState=profile.usageState?profile.usageState:null; this.text=profile.text?profile.text:null; this.image=profile.image?profile.image:null; // console.log(JSON.parse(profile.data)) // var data=eval(profile.data.replace(/\"/g,"'")); // this.data=profile.data?(JSON.parse(profile.data)):null; this.data=profile.data?((typeof profile.data=="object")?profile.data:JSON.parse(profile.data)):null; } this._render=function(){ this._table._setCellContent(this); this._table._setCellClass(this); }; } wd.form._cell.prototype.check=function(){ this.checked=true; var className=this._dom.getAttribute("class"); if(className.indexOf(" checked")==-1){ className+=" checked"; } this._dom.setAttribute("class",className); this._dom.setAttribute("checked","true"); // this._dom.style.border="solid thin #ff0000"; } wd.form._cell.prototype.uncheck=function(){ var className=this._dom.getAttribute("class"); className=className.replace(" checked",""); this._dom.setAttribute("class",className); this.checked=false; this._dom.setAttribute("checked","false"); // this._dom.style.border="solid thin #909090"; } //点在面上 function pointInArea(point,area){ var xx=point[0]; var yy=point[1]; if(xx>=area[0][0]&&xx<=area[1][0] && yy>=area[0][1]&&yy<=area[1][1]){ return "true"; }else{ return "false"}; } /////////////////////////////// //线经过区域边界 function lineInArea(line,area){ var x1=line[0][0]; var x2=line[1][0]; var y1=line[0][1]; var y2=line[1][1]; var a=area; //x轴平行 if(y1==y2){ var ll=Math.abs(x2-x1); if(y1>=a[0][1]&&y1<=a[1][1]&&x1>=(a[0][0]-ll)&&x1<=a[1][0]&&x2>=a[0][0]&&x2<=(a[1][0]+ll)){return "true"}; }; //y轴平行 if(x1==x2){ var ll=Math.abs(y2-y1); if(x1>=a[0][0]&&x1<=a[1][0]&&y1>=(a[0][1]-ll)&&y1<=a[1][1]&&y2>=a[0][1]&&y2<=(a[1][1]+ll)){return "true"} }; return "false"; } //////////////////////////////////////////////// function areaInArea(A,B){ var x_s1=A[0][0]; var x_e1=A[1][0]; var x_s2=B[0][0]; var x_e2=B[1][0]; var y_s1=A[0][1]; var y_e1=A[1][1]; var y_s2=B[0][1]; var y_e2=B[1][1]; var x_overlap=!(x_e1 <= x_s2 || x_e2 <= x_s1); var y_overlap=!(y_e1 <= y_s2 || y_e2 <= y_s1); return x_overlap&&y_overlap?"true":"false"; }