| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181 |
- 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<data.length;i++){
- // console.log(data[i])
- this._tryCertify(data[i]);
- }
- }
-
-
-
- this._tryCertify=function(cell){
- if(cell){
- for(var i=0;i<this.cells.length;i++){
- if(this.cells[i].ID==cell.ID){
- this.cells[i]._setProfile(cell,["ID"]);
- return this.cells[i];
- }else if(this.cells[i].NO&&this.cells[i].NO==cell.NO){
- this.cells[i]._setProfile(cell,["NO"]);
- return this.cells[i];
- }else if(this.cells[i].objectName&&this.cells[i].objectName==cell.objectName){
- this.cells[i]._setProfile(cell,["objectName"]);
- return this.cells[i];
- }else if(this.cells[i].objectID&&this.cells[i].objectID==cell.objectID){
- this.cells[i]._setProfile(cell,["objectID"]);
- return this.cells[i];
- }else if((this.cells[i].lineNum==cell.lineNum&&this.cells[i].columnNum==cell.columnNum)){
- this.cells[i]._setProfile(cell,["lineNum","columnNum"]);
- return this.cells[i];
- }else{
- }
- }
- }
- return null;
- }
-
- this._zoomAllCell=function(minZoom){
- for(var i=0;i<this.allcells.length;i++){
- var position=this.allcells[i]._originSize;
- var $cell=$(this.allcells[i]._dom);
- // $cell.css({left:position.left*minZoom+"px",top:position.top*minZoom+"px",width:position.width*minZoom+"px",height:position.height*minZoom+"px"});
- this.allcells[i]._currentSize={left:position.left*minZoom,top:position.top*minZoom,width:position.width*minZoom,height:position.height*minZoom};
- $cell.css({left:position.left*minZoom+"px",top:position.top*minZoom+"px",transform:"scale("+minZoom+")",transformOrigin:"left top"});
- }
- try{
- loadScorll(this._dom);
- }catch(e){
- console.log(e);
- }
-
-
- }
-
- this.init=function(mark,loadurl,editurl){
- var THIS=this;
- THIS.cells=[];
- THIS.allcells=[];
-
- $(document).ready(function(){
- if(THIS.preLoad){
- THIS.preLoad(mark);
- }
-
- //绑定编辑按钮
- var allhiddeninput=document.querySelectorAll("input[type=hidden][name$=id]");
- $("[name="+mark+"Edit]").attr("disabled",true)
-
- for(var i=0;i<allhiddeninput.length;i++){
- var name=allhiddeninput[i].getAttribute("name");
-
- var reg=new RegExp(mark+"[0-9]+id");
- if(reg.test(name)){
- var id=allhiddeninput[i].value;
- var edits=document.querySelectorAll("[name="+mark+id+"Edit]");
- var pmtcodebook= document.querySelector("[name="+mark+id+"codebook]");
- var codebook=pmtcodebook?pmtcodebook.value:"";
- if(edits.length==0)continue;
- for(var j=0;j<edits.length;j++){
- console.log(edits[j])
- edits[j].onclick=(function(){
- var bgmbid=id;
- var c=codebook;
- return function(){
- var code="";
- if(c&&c.indexOf(":") >= 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.clientHeight<document.documentElement.scrollHeight){
- // zoomcount++;
- // if(zoomcount>1000){
- // 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;i<THIS.allcells.length;i++){
- var $cell=$(THIS.allcells[i]._dom);
- var position=$cell.position();
- mWidth=Math.max(position.left+$cell.width(),mWidth);
- mHeight=Math.max(position.top+$cell.height(),mHeight);
- }
- var z1=dHeight/mHeight;
- var z2=dWidth/mWidth;
- minZoom=Math.min(z1,z2);
- if(minZoom<1){
- THIS._zoom=minZoom;
- THIS._minZoom=minZoom;
- THIS._zoomAllCell(minZoom);
- // THIS._dom.style.transform = "scale(" + minZoom + ")";
- }
-
-
-
- // THIS._dom.style.width=THIS._dom.clientWidth;
- // THIS._dom.style.height=THIS._dom.clientHeight;
-
-
- var shrinkButton=document.createElement("button");
- shrinkButton.style.cssText="position: relative;display: none;z-index: 10;";
- shrinkButton.style.left=shrinkButton.clientWidth+"px"
- shrinkButton.style.top=shrinkButton.clientHeight+"px"
- shrinkButton.type="button";
- shrinkButton.innerHTML="缩小";
-
- THIS._dom.onscroll=function(){
- var e=window.event;
-
- shrinkButton.style.left=this.scrollLeft+"px";
- shrinkButton.style.top=this.scrollTop+"px"
- }
- shrinkButton.onclick=function(){
- window.event.stopPropagation();
- this.style.display="none";
- THIS._zoom=THIS._minZoom;
- // THIS._dom.style.zoom=THIS._minZoom;
- THIS._zoomAllCell(THIS._minZoom);
-
- }
- THIS._dom.appendChild(shrinkButton);
-
-
- // THIS._dom.onmousewheel=function(){
- // var e=window.event;
- // e.preventDefault();
- // var e=window.event;
- // var x=THIS.findx(e);
- // var y=THIS.findy(e);
- //
- // if(e.wheelDelta>0){
- // 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<items.length;i++){
- var item=items[i];
- this._bindItemDragEvent(item)
- // console.log(item)
- }
- }
- this._findPosX=function(obj) {//辅助函数 得到元素左边与浏览器左边的边距
- var curleft = 0;
- if (obj && obj.offsetParent) {
- while (obj.offsetParent) {
-
- curleft += obj.offsetLeft;
- obj = obj.offsetParent;
- }
- } else if (obj && obj.x) curleft += obj.x;
- return curleft;// + document.body.scrollLeft - document.body.clientLeft;
- }
- this._findPosY=function(obj) {//辅助函数 得到元素上边与浏览器上边的边距
- var curtop = 0;
- if (obj && obj.offsetParent) {
- while (obj.offsetParent) {
- console.log(obj.scrollTop)
- curtop += obj.offsetTop;
- obj = obj.offsetParent;
- }
- } else if (obj && obj.y) curtop += obj.y;
-
- return curtop;// + document.body.scrollTop - document.body.clientTop;
- }
- this._bindItemDragEvent=function(item){
- if(item.getAttribute("id")!=null){
- return
- }
- item.setAttribute("id",new Date().getTime());
- var THIS=this;
-
- $(item).on("mousedown",function(){
-
- // console.log(THIS._zoom);
-
- var e=window.event;
- var ghost=item.cloneNode(true);
- ghost.style.borderStyle="dashed";
- ghost.style.cursor="all-scroll";
- ghost.style.zIndex=1111;
-
-
- $("body").append(ghost)
- // item.parentNode.insertBefore(ghost,item);
- ghost.style.position="absolute";
- ghost.innerHTML=item.innerHTML;
-
- var startx=e.pageX;
- var starty=e.pageY;
-
- var position=$(item).offset();
- var startleft=position.left;
- var starttop=position.top;
- ghost.style.left=startleft;
- ghost.style.top=starttop;
-
- $(ghost).addClass("wdformghost").on("click",function(){
- $(ghost).remove();
- item.style.display="";
- });
-
- item.style.display="none";
- var cells=THIS.cells;
- for(var i=0;i<cells.length;i++){
- cells[i].uncheck();
- }
-
- var selectedCell=null;
-
- var positionlist=[];
- for(var i=0;i<THIS.cells.length;i++){
- var $cell=$(THIS.cells[i]._dom);
- var position=$cell.position();
- var offset=$cell.offsetParent().offset();
- var cleft=offset.left+position.left;
- var ctop=offset.top+position.top;
- var cwidth=$cell.width();
- var cheight=$cell.height();
- positionlist.push({left:cleft,top:ctop,width:cwidth,height:cheight,cell:THIS.cells[i]});
- }
-
- $(document).on("mousemove.wdform",function(){
- var e=window.event;
- var x=e.pageX;
- var y=e.pageY;
- // console.log(x+","+y);
- ghost.style.left=startleft+x-startx;
- ghost.style.top=starttop+y-starty;
- selectedCell=null;
- for(var i=0;i<positionlist.length;i++){
- var pos=positionlist[i];
- var cell=positionlist[i].cell;
- if(pos.top<=y&&(pos.top+pos.height)>=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;i<THIS.cells.length;i++){
- var csize=THIS.cells[i]._currentSize
- var cell=THIS.cells[i]._dom;
- var c=[];
- c[0]=[csize.style.left,csize.style.top];
- c[1]=[csize.left+csize.width,csize.top+csize.height];
- if(areaInArea(s,c)=="true"){
- THIS.cells[i].check();
- }else{
- THIS.cells[i].uncheck();
- }
- }
-
- }
- THIS._dom.onmouseup=function(){
- selectDiv.style.left=0;
- selectDiv.style.top=0;
- selectDiv.style.width = 0;
- selectDiv.style.height = 0;
- selectDiv.style.display="none"
- THIS._dom.onmousemove=null;
- THIS._dom.onmouseup=null;
- THIS._dom.onmouseout=null;
- }
-
-
-
-
-
-
-
-
- }
-
- this._bindClimbEvent=function(){
- //拖动页面
- if(true)return;
-
- }
-
-
-
- }
- //公共接口
- wd.form._table.prototype.refresh=function(){
- for(var i=0;i<this.cells.length;i++){
- // console.log(this.cells[i])
- this.cells[i]._render();
- }
- this._findDragItem()
-
-
- }
- wd.form._table.prototype.dragToCell=function(dragitem,cell){
- // console.log(arguments);
- cell.text=dragitem.innerHTML;
- return true;
- }
- wd.form._table.prototype.preLoad=null;
- wd.form._table.prototype.loadFinish=null;
- wd.form._table.prototype._setCellContent=function(cell){
- var result=cell.text;
- if(!result){result=""}
- result=result.replace(/\[code\]/,cell.code);
- result=result.replace(/\[lineNum\]/,cell.lineNum);
- result=result.replace(/\[columnNum\]/,cell.columnNum);
- // if(!cell._dom.querySelector("table")){
- // return
- // }
-
- // cell._dom.querySelector("td").innerHTML=result;
- cell._dom.innerHTML=result;
- if(cell.image&&result.length>0){
- 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<this.cells.length;i++){
- if(this.cells[i].checked){
- a.push(this.cells[i]);
- }
- }
- return a;
- }
- wd.form._table.prototype.getAllCells=function(){
- return this.cells;
- }
- wd.form._table.prototype.rightClick=function(){
- console.log("rightclick");
-
- }
- wd.form._table.prototype.leftClick=function(cell){
- // console.log("leftclick");
- // console.log(cell)
- }
- wd.form._table.prototype.cellClass=[];
- wd.form._table.prototype.hover=function(cell){
- // console.log("hover")
- // console.log(cell)
- }
- wd.form._table.prototype.mouseenter=function(cell){
- // console.log("hover")
- // console.log(cell)
- }
- wd.form._table.prototype.mouseout=function(cell){
- // console.log("mouseout")
- // console.log(cell)
- }
- wd.form._table.prototype.input=function(cell,callback){
-
-
- var THIS=this;
- // var td=cell._dom.querySelector("td");
- // td.innerHTML=""
-
- cell._dom.innerHTML="<input type='text' placeholder='请输入...' autofocus='autofocus' value='"+(cell.text?cell.text:"")+"'>"
- 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";
-
-
- }
|