form.js 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. if(!wd.form){
  2. wd.form={};
  3. }
  4. function divShow(){}
  5. function loadBgbj(){}
  6. wd.form._table=function(){
  7. this.cells=null;//单元格集合
  8. this.allcells=null;//除了录入单元格,包括图片,文字
  9. this.tableId=null;
  10. this.assignField=null;
  11. this._dom=null;
  12. this.exportDataToField=function(){};
  13. this._isMouseMove=false;
  14. this._dragKey=null;
  15. this._zoom=1;
  16. this._minZoom=1;
  17. this._maxZoom=1;
  18. this._certify=function(data){
  19. if(!data){alert("nonononono");return}
  20. for(var i=0;i<data.length;i++){
  21. // console.log(data[i])
  22. this._tryCertify(data[i]);
  23. }
  24. }
  25. this._tryCertify=function(cell){
  26. if(cell){
  27. for(var i=0;i<this.cells.length;i++){
  28. if(this.cells[i].ID==cell.ID){
  29. this.cells[i]._setProfile(cell,["ID"]);
  30. return this.cells[i];
  31. }else if(this.cells[i].NO&&this.cells[i].NO==cell.NO){
  32. this.cells[i]._setProfile(cell,["NO"]);
  33. return this.cells[i];
  34. }else if(this.cells[i].objectName&&this.cells[i].objectName==cell.objectName){
  35. this.cells[i]._setProfile(cell,["objectName"]);
  36. return this.cells[i];
  37. }else if(this.cells[i].objectID&&this.cells[i].objectID==cell.objectID){
  38. this.cells[i]._setProfile(cell,["objectID"]);
  39. return this.cells[i];
  40. }else if((this.cells[i].lineNum==cell.lineNum&&this.cells[i].columnNum==cell.columnNum)){
  41. this.cells[i]._setProfile(cell,["lineNum","columnNum"]);
  42. return this.cells[i];
  43. }else{
  44. }
  45. }
  46. }
  47. return null;
  48. }
  49. this._zoomAllCell=function(minZoom){
  50. for(var i=0;i<this.allcells.length;i++){
  51. var position=this.allcells[i]._originSize;
  52. var $cell=$(this.allcells[i]._dom);
  53. // $cell.css({left:position.left*minZoom+"px",top:position.top*minZoom+"px",width:position.width*minZoom+"px",height:position.height*minZoom+"px"});
  54. this.allcells[i]._currentSize={left:position.left*minZoom,top:position.top*minZoom,width:position.width*minZoom,height:position.height*minZoom};
  55. $cell.css({left:position.left*minZoom+"px",top:position.top*minZoom+"px",transform:"scale("+minZoom+")",transformOrigin:"left top"});
  56. }
  57. try{
  58. loadScorll(this._dom);
  59. }catch(e){
  60. console.log(e);
  61. }
  62. }
  63. this.init=function(mark,loadurl,editurl){
  64. var THIS=this;
  65. THIS.cells=[];
  66. THIS.allcells=[];
  67. $(document).ready(function(){
  68. if(THIS.preLoad){
  69. THIS.preLoad(mark);
  70. }
  71. //绑定编辑按钮
  72. var allhiddeninput=document.querySelectorAll("input[type=hidden][name$=id]");
  73. $("[name="+mark+"Edit]").attr("disabled",true)
  74. for(var i=0;i<allhiddeninput.length;i++){
  75. var name=allhiddeninput[i].getAttribute("name");
  76. var reg=new RegExp(mark+"[0-9]+id");
  77. if(reg.test(name)){
  78. var id=allhiddeninput[i].value;
  79. var edits=document.querySelectorAll("[name="+mark+id+"Edit]");
  80. var pmtcodebook= document.querySelector("[name="+mark+id+"codebook]");
  81. var codebook=pmtcodebook?pmtcodebook.value:"";
  82. if(edits.length==0)continue;
  83. for(var j=0;j<edits.length;j++){
  84. console.log(edits[j])
  85. edits[j].onclick=(function(){
  86. var bgmbid=id;
  87. var c=codebook;
  88. return function(){
  89. var code="";
  90. if(c&&c.indexOf(":") >= 0){
  91. code="dynamic&codebookstr="+encodeURIComponent(c);
  92. }else{
  93. code=c;
  94. }
  95. var url=wd.display.replaceDynamicParam(editurl,{bgmbid:bgmbid,codebook:code});
  96. eval(url);
  97. }
  98. })()
  99. }
  100. }
  101. }
  102. THIS._dragKey=mark+"drag";
  103. if(document.querySelector("[name="+mark+"id]")){
  104. THIS.tableId=document.querySelector("[name="+mark+"id]").value;
  105. }
  106. if(!THIS.tableId){
  107. console.log(mark+"id为空");
  108. return;
  109. }
  110. THIS._dom=document.querySelector("#"+mark+"Edit");
  111. $.ajax({
  112. type:"post",
  113. data:{
  114. pmtid:THIS.tableId
  115. },
  116. url:loadurl,
  117. async:false,
  118. success:function(re){
  119. THIS._dom.innerHTML=re;
  120. }
  121. });
  122. /*//
  123. var colNum = $("div[hl^='1_']").length;
  124. var rowNum = $("div[hl*='_']").length / colNum
  125. //
  126. var containerWidth = $(THIS._dom).width() - 30
  127. var containerHeight = $(THIS._dom).height() - 30
  128. var wr = containerWidth / ($("div[hl='1_1']").outerWidth() * colNum)
  129. var hr = containerHeight / ($("div[hl='1_1']").outerHeight() * rowNum)
  130. $("div[hl^='4_']").each(function (idx) {
  131. var preWidth = $(this).width()
  132. $(this).width(preWidth * wr)
  133. var afterWidth = $(this).width()
  134. var preHeight = $(this).height()
  135. $(this).height(preHeight * hr)
  136. var afterHeight = $(this).height()
  137. if ($(this).attr("hl") != "4_1") {
  138. $(this).css({"left": parseFloat($(this).css("left")) + (afterWidth - preWidth) * idx})
  139. // $(this).css({"top": parseFloat($(this).css("top")) + (preHeight - afterHeight) * idx})
  140. }
  141. })
  142. for (var i = 1; i<=rowNum; i++) {
  143. $("div[hl^='" + i + "_']").each(function (idx) {
  144. $(this).width($("div[hl='4_" + (idx + 1) + "']").width())
  145. $(this).height($("div[hl='4_" + (idx + 1) + "']").height())
  146. $(this).css({ "left": parseFloat($("div[hl='4_" + (idx + 1) + "']").css("left")) })
  147. if (i > 1) {
  148. $(this).css({ "top": parseFloat($("div[hl='" + (i-1) + "_1']").position().top + $("div[hl='" + (i-1) + "_1']").height()) })
  149. }
  150. })
  151. }*/
  152. //全部单元格
  153. var allcells = $(THIS._dom).find("[bgbjlbm]");
  154. allcells.each(function(){
  155. var c=new wd.form._cell();
  156. c._load(THIS,this);
  157. if(this.getAttribute("bgbjlbm")==1){
  158. THIS.cells.push(c);
  159. }
  160. THIS.allcells.push(c);
  161. })
  162. THIS.assignField=document.querySelector("[name="+mark+"data]");
  163. var c=THIS.assignField.value;
  164. if(c&&c.length>0){
  165. var j=JSON.parse(c);
  166. THIS._certify(j);
  167. }
  168. THIS.refresh();
  169. THIS._dom.style.position="relative";
  170. // THIS._dom.style.overflow="hidden";
  171. var setwidth=false;
  172. var setheight=false;
  173. if(!THIS._dom.style.width){
  174. THIS._dom.style.width="95%"
  175. setwidth=true;
  176. }
  177. if(!THIS._dom.style.height){
  178. THIS._dom.style.height="95%";
  179. setheight=true;
  180. }
  181. THIS._dom.style.zoom=1;
  182. THIS._dom.style.transform = "scale(1)";
  183. THIS._dom.style.transformOrigin = "left top";
  184. THIS._dom.style.overflow = null;
  185. THIS._dom.style.border = "none"
  186. var minZoom=1;
  187. var zoomcount = 0;
  188. // while(document.documentElement.clientHeight<document.documentElement.scrollHeight){
  189. // zoomcount++;
  190. // if(zoomcount>1000){
  191. // console.log("zooom count fail");
  192. // THIS._dom.style.zoom = 1;
  193. // THIS._zoom=1;
  194. // THIS._minZoom = 1;
  195. //
  196. // break;
  197. // }
  198. // // var zoom=parseFloat( THIS._dom.style.zoom);
  199. // var zoom = parseFloat($(THIS._dom).css("transform").replace(/[^0-9\\.]*/ig,""));
  200. //
  201. // minZoom=zoom-0.05;
  202. // // THIS._dom.style.zoom=minZoom;
  203. // THIS._dom.style.transform = "scale(" + minZoom + ")";
  204. // THIS._zoom=minZoom;
  205. // THIS._minZoom = minZoom;
  206. //
  207. // }
  208. THIS._zoom=1;
  209. THIS._minZoom = 1;
  210. var dWidth=$(THIS._dom).width();
  211. var dHeight=$(THIS._dom).height();
  212. var mWidth=0;
  213. var mHeight=0;
  214. for(var i=0;i<THIS.allcells.length;i++){
  215. var $cell=$(THIS.allcells[i]._dom);
  216. var position=$cell.position();
  217. mWidth=Math.max(position.left+$cell.width(),mWidth);
  218. mHeight=Math.max(position.top+$cell.height(),mHeight);
  219. }
  220. var z1=dHeight/mHeight;
  221. var z2=dWidth/mWidth;
  222. minZoom=Math.min(z1,z2);
  223. if(minZoom<1){
  224. THIS._zoom=minZoom;
  225. THIS._minZoom=minZoom;
  226. THIS._zoomAllCell(minZoom);
  227. // THIS._dom.style.transform = "scale(" + minZoom + ")";
  228. }
  229. // THIS._dom.style.width=THIS._dom.clientWidth;
  230. // THIS._dom.style.height=THIS._dom.clientHeight;
  231. var shrinkButton=document.createElement("button");
  232. shrinkButton.style.cssText="position: relative;display: none;z-index: 10;";
  233. shrinkButton.style.left=shrinkButton.clientWidth+"px"
  234. shrinkButton.style.top=shrinkButton.clientHeight+"px"
  235. shrinkButton.type="button";
  236. shrinkButton.innerHTML="缩小";
  237. THIS._dom.onscroll=function(){
  238. var e=window.event;
  239. shrinkButton.style.left=this.scrollLeft+"px";
  240. shrinkButton.style.top=this.scrollTop+"px"
  241. }
  242. shrinkButton.onclick=function(){
  243. window.event.stopPropagation();
  244. this.style.display="none";
  245. THIS._zoom=THIS._minZoom;
  246. // THIS._dom.style.zoom=THIS._minZoom;
  247. THIS._zoomAllCell(THIS._minZoom);
  248. }
  249. THIS._dom.appendChild(shrinkButton);
  250. // THIS._dom.onmousewheel=function(){
  251. // var e=window.event;
  252. // e.preventDefault();
  253. // var e=window.event;
  254. // var x=THIS.findx(e);
  255. // var y=THIS.findy(e);
  256. //
  257. // if(e.wheelDelta>0){
  258. // THIS._zoom=THIS._maxZoom;
  259. // }else{
  260. // THIS._zoom=THIS._minZoom;
  261. // }
  262. // if(this.style.zoom==THIS._zoom){return};
  263. // this.style.zoom=THIS._zoom;
  264. // this.scrollLeft=x/THIS._zoom-this.clientWidth/2;
  265. // this.scrollTop=y/THIS._zoom-this.clientHeight/2;
  266. //
  267. // if(THIS._maxZoom==THIS._minZoom||THIS._minZoom==THIS._zoom){
  268. // shrinkButton.style.display="none";
  269. // }else{
  270. // shrinkButton.style.display="";
  271. // }
  272. //
  273. // }
  274. THIS._dom.ondblclick=function(){
  275. var e=window.event;
  276. var x=THIS.findx(e);
  277. var y=THIS.findy(e);
  278. if(THIS._zoom!=THIS._maxZoom){
  279. THIS._zoom=THIS._maxZoom;
  280. this.style.cursor="-webkit-grab"
  281. }else{
  282. THIS._zoom=THIS._minZoom;
  283. this.style.cursor="default";
  284. }
  285. // this.style.zoom=THIS._zoom;
  286. THIS._zoomAllCell(THIS._zoom);
  287. this.scrollLeft=x/THIS._zoom-this.clientWidth/2;
  288. this.scrollTop=y/THIS._zoom-this.clientHeight/2;
  289. if(THIS._maxZoom==THIS._minZoom||THIS._minZoom==THIS._zoom){
  290. shrinkButton.style.display="none"
  291. }else{
  292. shrinkButton.style.display=""
  293. }
  294. }
  295. // document.oncontextmenu=function(){
  296. // window.event.preventDefault()
  297. // };
  298. // console.log(THIS._zoom+" "+THIS._maxZoom)
  299. THIS._dom.onmousedown=function(){
  300. THIS._isMouseMove=false;
  301. var that=this;
  302. var e=window.event;
  303. // console.log(THIS)
  304. //缩小状态
  305. if(THIS._zoom!=THIS._maxZoom){
  306. THIS._dom.onmousemove=function(){
  307. THIS._bindRegionSelectEvent();
  308. }
  309. THIS._dom.onmouseup=function(){
  310. shrinkButton.style.display="";
  311. THIS._zoom=THIS._maxZoom;
  312. THIS._dom.style.zoom=THIS._maxZoom;
  313. THIS._dom.onmousemove=null;
  314. }
  315. //正常状态
  316. }else{
  317. //没有缩小状态,变成拖选
  318. if(THIS._minZoom==THIS._maxZoom){
  319. // console.log("cc")
  320. THIS._bindRegionSelectEvent();
  321. }else{
  322. THIS._bindClimbEvent();
  323. }
  324. }
  325. //
  326. }
  327. THIS._findDragItem();
  328. if(THIS.loadFinish){
  329. THIS.loadFinish();
  330. }
  331. })
  332. }
  333. this._findDragItem=function(){
  334. var items=document.querySelectorAll("["+this._dragKey+"=true]");
  335. for(var i=0;i<items.length;i++){
  336. var item=items[i];
  337. this._bindItemDragEvent(item)
  338. // console.log(item)
  339. }
  340. }
  341. this._findPosX=function(obj) {//辅助函数 得到元素左边与浏览器左边的边距
  342. var curleft = 0;
  343. if (obj && obj.offsetParent) {
  344. while (obj.offsetParent) {
  345. curleft += obj.offsetLeft;
  346. obj = obj.offsetParent;
  347. }
  348. } else if (obj && obj.x) curleft += obj.x;
  349. return curleft;// + document.body.scrollLeft - document.body.clientLeft;
  350. }
  351. this._findPosY=function(obj) {//辅助函数 得到元素上边与浏览器上边的边距
  352. var curtop = 0;
  353. if (obj && obj.offsetParent) {
  354. while (obj.offsetParent) {
  355. console.log(obj.scrollTop)
  356. curtop += obj.offsetTop;
  357. obj = obj.offsetParent;
  358. }
  359. } else if (obj && obj.y) curtop += obj.y;
  360. return curtop;// + document.body.scrollTop - document.body.clientTop;
  361. }
  362. this._bindItemDragEvent=function(item){
  363. if(item.getAttribute("id")!=null){
  364. return
  365. }
  366. item.setAttribute("id",new Date().getTime());
  367. var THIS=this;
  368. $(item).on("mousedown",function(){
  369. // console.log(THIS._zoom);
  370. var e=window.event;
  371. var ghost=item.cloneNode(true);
  372. ghost.style.borderStyle="dashed";
  373. ghost.style.cursor="all-scroll";
  374. ghost.style.zIndex=1111;
  375. $("body").append(ghost)
  376. // item.parentNode.insertBefore(ghost,item);
  377. ghost.style.position="absolute";
  378. ghost.innerHTML=item.innerHTML;
  379. var startx=e.pageX;
  380. var starty=e.pageY;
  381. var position=$(item).offset();
  382. var startleft=position.left;
  383. var starttop=position.top;
  384. ghost.style.left=startleft;
  385. ghost.style.top=starttop;
  386. $(ghost).addClass("wdformghost").on("click",function(){
  387. $(ghost).remove();
  388. item.style.display="";
  389. });
  390. item.style.display="none";
  391. var cells=THIS.cells;
  392. for(var i=0;i<cells.length;i++){
  393. cells[i].uncheck();
  394. }
  395. var selectedCell=null;
  396. var positionlist=[];
  397. for(var i=0;i<THIS.cells.length;i++){
  398. var $cell=$(THIS.cells[i]._dom);
  399. var position=$cell.position();
  400. var offset=$cell.offsetParent().offset();
  401. var cleft=offset.left+position.left;
  402. var ctop=offset.top+position.top;
  403. var cwidth=$cell.width();
  404. var cheight=$cell.height();
  405. positionlist.push({left:cleft,top:ctop,width:cwidth,height:cheight,cell:THIS.cells[i]});
  406. }
  407. $(document).on("mousemove.wdform",function(){
  408. var e=window.event;
  409. var x=e.pageX;
  410. var y=e.pageY;
  411. // console.log(x+","+y);
  412. ghost.style.left=startleft+x-startx;
  413. ghost.style.top=starttop+y-starty;
  414. selectedCell=null;
  415. for(var i=0;i<positionlist.length;i++){
  416. var pos=positionlist[i];
  417. var cell=positionlist[i].cell;
  418. if(pos.top<=y&&(pos.top+pos.height)>=y&&pos.left<=x&&(pos.left+pos.width)>=x){
  419. cell.check();
  420. selectedCell=cell;
  421. }else{
  422. cell.uncheck();
  423. }
  424. }
  425. })
  426. $(document).on("mouseup.wdform",function(){
  427. $(".wdformghost").remove();
  428. item.style.cursor="pointer";
  429. item.style.display="";
  430. if(selectedCell){
  431. var result=THIS.dragToCell(item,selectedCell)
  432. selectedCell=null;
  433. $(item).remove();
  434. THIS.refresh()
  435. }
  436. $(document).off("mousemove.wdform");
  437. $(document).off("mouseup.wdform");
  438. setTimeout(function(){
  439. $(document).off("mousemove.wdform");
  440. $(document).off("mouseup.wdform");
  441. },500);
  442. })
  443. })
  444. }
  445. this.findx=function(event){
  446. var a=event.srcElement;
  447. var result=event.offsetX;
  448. var c=0;
  449. while(a!=this._dom){
  450. if(c==10){console.log("mmmm");break;}
  451. c++;
  452. result+=a.offsetLeft
  453. a=a.offsetParent;
  454. }
  455. return result;
  456. }
  457. this.findy=function(event){
  458. var a=event.srcElement;
  459. var result=event.offsetY;
  460. var c=0;
  461. while(a!=this._dom){
  462. if(c==10){console.log("mmmm");break;}
  463. c++;
  464. result+=a.offsetTop
  465. a=a.offsetParent;
  466. }
  467. return result;
  468. }
  469. this._bindRegionSelectEvent=function(){
  470. var e=window.event;
  471. var THIS=this;
  472. var selectDiv;
  473. if(!document.getElementById("selContainer")){
  474. selectDiv = document.createElement("div");
  475. 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:'';";
  476. selectDiv.id = "selContainer";
  477. THIS._dom.appendChild(selectDiv);
  478. }else{
  479. selectDiv = document.getElementById("selContainer");
  480. }
  481. var startX=THIS.findx(e);
  482. var startY=THIS.findy(e);
  483. selectDiv.style.display="none";
  484. THIS._isMouseMove=false;
  485. if(e.which!=1){
  486. return ;
  487. }
  488. var count=0;
  489. THIS._dom.onmousemove=null;
  490. THIS._dom.onmouseup=null;
  491. THIS._dom.onmouseout=null;
  492. THIS._dom.onmousemove=function(){
  493. count++;
  494. if(count<5)return
  495. THIS._isMouseMove=true;
  496. var e=window.event;
  497. e.preventDefault();
  498. var poxX=THIS.findx(e);
  499. var poxY=THIS.findy(e);
  500. selectDiv.style.display=""
  501. selectDiv.style.left = Math.min(poxX, startX)+"px";
  502. selectDiv.style.top = Math.min(poxY, startY)+"px";
  503. selectDiv.style.width = Math.abs(poxX - startX)+"px";
  504. selectDiv.style.height = Math.abs(poxY - startY)+"px";
  505. var s=[];
  506. s[0]=[parseInt(selectDiv.style.left),parseInt(selectDiv.style.top)];
  507. s[1]=[parseInt(selectDiv.style.left)+parseInt(selectDiv.style.width),parseInt(selectDiv.style.top)+parseInt(selectDiv.style.height)];
  508. for(var i=0;i<THIS.cells.length;i++){
  509. var csize=THIS.cells[i]._currentSize
  510. var cell=THIS.cells[i]._dom;
  511. var c=[];
  512. c[0]=[csize.style.left,csize.style.top];
  513. c[1]=[csize.left+csize.width,csize.top+csize.height];
  514. if(areaInArea(s,c)=="true"){
  515. THIS.cells[i].check();
  516. }else{
  517. THIS.cells[i].uncheck();
  518. }
  519. }
  520. }
  521. THIS._dom.onmouseup=function(){
  522. selectDiv.style.left=0;
  523. selectDiv.style.top=0;
  524. selectDiv.style.width = 0;
  525. selectDiv.style.height = 0;
  526. selectDiv.style.display="none"
  527. THIS._dom.onmousemove=null;
  528. THIS._dom.onmouseup=null;
  529. THIS._dom.onmouseout=null;
  530. }
  531. }
  532. this._bindClimbEvent=function(){
  533. //拖动页面
  534. if(true)return;
  535. }
  536. }
  537. //公共接口
  538. wd.form._table.prototype.refresh=function(){
  539. for(var i=0;i<this.cells.length;i++){
  540. // console.log(this.cells[i])
  541. this.cells[i]._render();
  542. }
  543. this._findDragItem()
  544. }
  545. wd.form._table.prototype.dragToCell=function(dragitem,cell){
  546. // console.log(arguments);
  547. cell.text=dragitem.innerHTML;
  548. return true;
  549. }
  550. wd.form._table.prototype.preLoad=null;
  551. wd.form._table.prototype.loadFinish=null;
  552. wd.form._table.prototype._setCellContent=function(cell){
  553. var result=cell.text;
  554. if(!result){result=""}
  555. result=result.replace(/\[code\]/,cell.code);
  556. result=result.replace(/\[lineNum\]/,cell.lineNum);
  557. result=result.replace(/\[columnNum\]/,cell.columnNum);
  558. // if(!cell._dom.querySelector("table")){
  559. // return
  560. // }
  561. // cell._dom.querySelector("td").innerHTML=result;
  562. cell._dom.innerHTML=result;
  563. if(cell.image&&result.length>0){
  564. var imageEle=document.createElement("img");
  565. imageEle.setAttribute("src",cell.image);
  566. imageEle.style.maxHeight=50;
  567. imageEle.style.maxHeight=50;
  568. // cell._dom.querySelector("td").style.maxWidth="auto";
  569. // cell._dom.querySelector("td").style.height="auto";
  570. // cell._dom.querySelector("td").appendChild(imageEle);
  571. cell._dom.appendChild(imageEle);
  572. }
  573. }
  574. wd.form._table.prototype._setCellClass=function(cell){
  575. // wd.form.pmt.cellClass={
  576. //objectState:{“1”:” “.clean”,”2”:” .broken”},
  577. //usageState:{“1”:” “.freeed”,”3”:” .using”},
  578. //}
  579. var cellclass=this.cellClass;
  580. var classValue="";
  581. // for(var key in cellclass){
  582. // if(key==cell.state){
  583. // classValue=cellclass[key];
  584. // }
  585. // }
  586. if(cellclass.objectState&&cell.objectState){
  587. for(var key in cellclass.objectState){
  588. if(key==cell.objectState){
  589. classValue+=" "+cellclass.objectState[key];
  590. }
  591. }
  592. }
  593. if(cellclass.usageState&&cell.usageState){
  594. for(var key in cellclass.usageState){
  595. if(key==cell.usageState){
  596. classValue+=" "+cellclass.usageState[key];
  597. }
  598. }
  599. }
  600. if(classValue&&classValue.length>0){
  601. cell._dom.setAttribute("class",classValue);
  602. }else{
  603. cell._dom.setAttribute("class",cell._dom.getAttribute("class")||"default");
  604. }
  605. }
  606. wd.form._table.prototype.getCurrCells=function(){
  607. var a=[];
  608. for(var i=0;i<this.cells.length;i++){
  609. if(this.cells[i].checked){
  610. a.push(this.cells[i]);
  611. }
  612. }
  613. return a;
  614. }
  615. wd.form._table.prototype.getAllCells=function(){
  616. return this.cells;
  617. }
  618. wd.form._table.prototype.rightClick=function(){
  619. console.log("rightclick");
  620. }
  621. wd.form._table.prototype.leftClick=function(cell){
  622. // console.log("leftclick");
  623. // console.log(cell)
  624. }
  625. wd.form._table.prototype.cellClass=[];
  626. wd.form._table.prototype.hover=function(cell){
  627. // console.log("hover")
  628. // console.log(cell)
  629. }
  630. wd.form._table.prototype.mouseenter=function(cell){
  631. // console.log("hover")
  632. // console.log(cell)
  633. }
  634. wd.form._table.prototype.mouseout=function(cell){
  635. // console.log("mouseout")
  636. // console.log(cell)
  637. }
  638. wd.form._table.prototype.input=function(cell,callback){
  639. var THIS=this;
  640. // var td=cell._dom.querySelector("td");
  641. // td.innerHTML=""
  642. cell._dom.innerHTML="<input type='text' placeholder='请输入...' autofocus='autofocus' value='"+(cell.text?cell.text:"")+"'>"
  643. var inp=cell._dom.querySelector("input");
  644. function _inputFinish(){
  645. cell._dom.removeChild(inp);
  646. if(inp.value&&inp.value.length>0){
  647. if(callback){
  648. callback.call(THIS,inp.value,cell);
  649. }else{
  650. cell.text=inp.value;
  651. }
  652. THIS.refresh()
  653. }
  654. }
  655. inp.onkeyup=function(){
  656. // window.event.preventDefault();
  657. var e=window.event;
  658. e.stopPropagation();
  659. if(e.keyCode==13){
  660. _inputFinish()
  661. }
  662. }
  663. inp.onblur=function(){
  664. _inputFinish()
  665. }
  666. inp.select();
  667. }
  668. //[
  669. //
  670. //{
  671. //ID:单元格ID,
  672. //NO:单元格序号,
  673. //lineNum: 行号,
  674. //columnNum:列号,//对于特定的单元格数据,单元格ID、单元格编号、行列号这三者必需至少有其中一项,否则程序无法得知是那个单元格
  675. //text: 单元格中的文字
  676. //image: “\abc\123.jsp”//单元格中的图片路径(在页面显示时会被转换为token)
  677. //objectName:单元格关联的对象名(现在座位号床位号也放这)
  678. //objectID: 单元格关联的对象ID
  679. //state:状态值,例如1代表空闲、2代表已预订、3代表已入住等
  680. //objectState
  681. //usageState
  682. //data:{业务数据}
  683. //},
  684. //{//另一单元格数据
  685. //}
  686. //]
  687. wd.form._cell=function(){
  688. this._certeria=null;
  689. this.ID=null;//单元格ID
  690. this.NO=null;//单元格序号
  691. this.lineNum=null;//行号
  692. this.columnNum=null;//列号
  693. this.objectID=null;//单元格关联的对象ID
  694. this.objectName=null;//状态值,例如1代表空闲、2代表已预订、3代表已入住等
  695. this.text=null;//单元格中的文字
  696. this.image=null;//单元格中的图片路径(在页面显示时会被转换为token)
  697. // this.state=null;
  698. this.objectState=null;
  699. this.usageState=null;
  700. this.data=null;//业务数据
  701. this._table=null;
  702. this._dom=null;
  703. this.checked=false;
  704. this._originSize=null;
  705. this._currentSize=null
  706. this._load=function(table,dom){
  707. var THIS=this;
  708. this._table=table;
  709. this._dom=dom;
  710. var position=$(dom).position();
  711. this._originSize={
  712. left:position.left,
  713. top:position.top,
  714. width:$(dom).width(),
  715. height:$(dom).height()
  716. };
  717. this._currentSize={
  718. left:position.left,
  719. top:position.top,
  720. width:$(dom).width(),
  721. height:$(dom).height()
  722. };
  723. var id=dom.getAttribute("id");
  724. var name=dom.getAttribute("name");
  725. var xh=dom.getAttribute("xh");
  726. var hl=dom.getAttribute("hl");
  727. var dxm=dom.getAttribute("dxm");
  728. var dxid=dom.getAttribute("dxid");
  729. this.ID=id.replace(/[^0-9]/,"");
  730. if(hl){
  731. this.lineNum=parseInt(hl.split("_")[0]) ;
  732. this.columnNum=parseInt(hl.split("_")[1]) ;
  733. }
  734. if(dxm){
  735. this.objectName=dxm;
  736. }
  737. if(xh){
  738. this.NO=parseInt(xh)
  739. }
  740. if(dxid){
  741. this.objectID=dxid;
  742. }
  743. this._dom.onmouseenter=(function(){
  744. return function(){
  745. if(THIS._table._isMouseMove){
  746. return;
  747. }
  748. THIS._table.hover(THIS)
  749. THIS._table.mouseenter(THIS);
  750. }
  751. })()
  752. this._dom.onmouseout=(function(){
  753. return function(){
  754. if(THIS._table._isMouseMove){
  755. return;
  756. }
  757. THIS._table.mouseout(THIS);
  758. }
  759. })()
  760. this._dom.onclick=(function(){
  761. return function (){
  762. // window.event.preventDefault()
  763. // window.event.stopPropagation()
  764. // console.log(THIS);
  765. //点击选中
  766. if( (window.event.ctrlKey||window.event.shiftKey)&&window.event.button==0 ){
  767. if(THIS.checked==false){
  768. THIS.check()
  769. }else{
  770. THIS.uncheck()
  771. }
  772. }else{
  773. var allcheck=THIS._table.cells;
  774. // for(var i=0; i< allcheck.length;i++){
  775. // allcheck[i].uncheck();
  776. // }
  777. if(THIS.checked==false){
  778. THIS.check()
  779. }else if(THIS.checked==true){
  780. THIS.uncheck()
  781. }
  782. }
  783. THIS._click();
  784. }
  785. })()
  786. this._dom.onmousedown=(function(){
  787. return function(){
  788. if(window.event.which==3){
  789. THIS._table.rightClick(THIS);
  790. // console.log(THIS)
  791. }
  792. }
  793. })()
  794. this._dom.ondblclick=(function(){
  795. return function (){
  796. var e=window.event;
  797. e.stopPropagation()
  798. e.preventDefault();
  799. console.log(this)
  800. }
  801. })()
  802. }
  803. this._click=function(){
  804. // e.which==3// 1 = 鼠标左键 left; 2 = 鼠标中键; 3 = 鼠标右键
  805. if(this._table._isMouseMove){
  806. return;
  807. }
  808. this._table.leftClick(this);
  809. // var which=window.event.which;
  810. //// console.log("click "+which)
  811. // switch (which){
  812. // case 1:
  813. // this._table.leftClick(this);
  814. // break;
  815. //// case 3:
  816. //// this._table.rightClick(this)
  817. //// break;
  818. // }
  819. }
  820. this._setProfile=function(profile,certeria){
  821. this._certeria=certeria;
  822. if(this._certeria.length==2){
  823. // console.log(this._certeria)
  824. // this.lineNum=profile.lineNum;
  825. // this.columnNum=profile.columnNum;
  826. }else if(this._certeria.length==1){
  827. if(this._certeria[0]=="ID"){
  828. // this.ID=profile.ID;
  829. }else if(this._certeria[0]=="NO"){
  830. // this.code=profile.code;
  831. }else{
  832. console.log("出问题了!")
  833. }
  834. }else{
  835. console.log("出问题了!")
  836. }
  837. // console.log(profile)
  838. // this.state=profile.state?profile.state:null;
  839. this.objectState=profile.objectState?profile.objectState:null;
  840. this.usageState=profile.usageState?profile.usageState:null;
  841. this.text=profile.text?profile.text:null;
  842. this.image=profile.image?profile.image:null;
  843. // console.log(JSON.parse(profile.data))
  844. // var data=eval(profile.data.replace(/\"/g,"'"));
  845. // this.data=profile.data?(JSON.parse(profile.data)):null;
  846. this.data=profile.data?((typeof profile.data=="object")?profile.data:JSON.parse(profile.data)):null;
  847. }
  848. this._render=function(){
  849. this._table._setCellContent(this);
  850. this._table._setCellClass(this);
  851. };
  852. }
  853. wd.form._cell.prototype.check=function(){
  854. this.checked=true;
  855. var className=this._dom.getAttribute("class");
  856. if(className.indexOf(" checked")==-1){
  857. className+=" checked";
  858. }
  859. this._dom.setAttribute("class",className);
  860. this._dom.setAttribute("checked","true");
  861. // this._dom.style.border="solid thin #ff0000";
  862. }
  863. wd.form._cell.prototype.uncheck=function(){
  864. var className=this._dom.getAttribute("class");
  865. className=className.replace(" checked","");
  866. this._dom.setAttribute("class",className);
  867. this.checked=false;
  868. this._dom.setAttribute("checked","false");
  869. // this._dom.style.border="solid thin #909090";
  870. }
  871. //点在面上
  872. function pointInArea(point,area){
  873. var xx=point[0];
  874. var yy=point[1];
  875. if(xx>=area[0][0]&&xx<=area[1][0] && yy>=area[0][1]&&yy<=area[1][1]){
  876. return "true";
  877. }else{
  878. return "false"};
  879. }
  880. ///////////////////////////////
  881. //线经过区域边界
  882. function lineInArea(line,area){
  883. var x1=line[0][0];
  884. var x2=line[1][0];
  885. var y1=line[0][1];
  886. var y2=line[1][1];
  887. var a=area;
  888. //x轴平行
  889. if(y1==y2){
  890. var ll=Math.abs(x2-x1);
  891. 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"};
  892. };
  893. //y轴平行
  894. if(x1==x2){
  895. var ll=Math.abs(y2-y1);
  896. 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"}
  897. };
  898. return "false";
  899. }
  900. ////////////////////////////////////////////////
  901. function areaInArea(A,B){
  902. var x_s1=A[0][0];
  903. var x_e1=A[1][0];
  904. var x_s2=B[0][0];
  905. var x_e2=B[1][0];
  906. var y_s1=A[0][1];
  907. var y_e1=A[1][1];
  908. var y_s2=B[0][1];
  909. var y_e2=B[1][1];
  910. var x_overlap=!(x_e1 <= x_s2 || x_e2 <= x_s1);
  911. var y_overlap=!(y_e1 <= y_s2 || y_e2 <= y_s1);
  912. return x_overlap&&y_overlap?"true":"false";
  913. }