| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- function wdRecord(bjid) {
-
- try{
- //if(true)return;
-
- //回显个人选值数据
- if("0"==window.loginStatus)
- return;
- if(window.wdRecordValue&&!document.querySelector("ssDlg[setPval=false]")){ // ("wdDialog[setValue=。Lin
- if(typeof wdRecordValue=="string")
- wdRecordValue=eval("("+wdRecordValue+")")
-
- for(var key in wdRecordValue){
- // var ele= document.querySelector("[name="+key+"]");
- // if(!ele||ele.value)continue;
- //
- // ele.value=wdRecordValue[key]["value"];
- // $(ele).trigger("change")
- var box=wd.display.getInputBox(key);
- if(!box||box.getValue())continue;
- box.setValue(wdRecordValue[key]["value"]);
-
- }
- }
-
- if(window.wdRecordValue){
- window.wdRecordValue=(typeof wdRecordValue=="object")?window.wdRecordValue: eval("("+wdRecordValue+")")
- var thisEle=document.querySelector("[name=wdComponentID]");
- var wdComponentID=window.wdRecordValue["wdComponentID"];
- if(wdComponentID&&thisEle){
- thisEle.value=wdComponentID.value;
- }
- }
-
-
- /**
- * 根据是否找到wdDialogId判断当前页面在弹窗中或应用页面
- *
- */
- var wdDialogId = wd.display.getwdDialogId();
-
-
- //当前窗口在弹出窗口中
- if(wdDialogId){
- var win=wd.topWindow.dhxWins.window(wdDialogId);
- var allWindows= wd.display.getwdDialogWindowObjects(wdDialogId);
- var targetWindows=[];
- for(var i=0;i<allWindows.length;i++){
- if(!allWindows[i].document.querySelector("ssDlg[setPval=false]")){ // ("wdDialog[setValue=。Lin
- targetWindows.push(allWindows[i]);
- }
- }
-
-
- if(targetWindows.length>0){
- win.button("wdRecord").show();
- win.button("wdRecord_save").hide();
- //编辑个人选值和保存个人选值切换
- win.button("wdRecord").onclick = function() {
-
- for(var i=0;i<targetWindows.length;i++){
- try{
- targetWindows[i].wd.record.show();
- }catch(e){
- console.log(e);
- }
-
- }
-
- win.button("wdRecord").hide();
- win.button("wdRecord_save").show();
- }
- win.button("wdRecord_save").onclick = function() {
-
- for(var i=0;i<targetWindows.length;i++){
- try{
- targetWindows[i].wd.record.hide();
- }catch(e){
- console.log(e);
- }
-
- }
-
-
- win.button("wdRecord_save").hide();
- win.button("wdRecord").show();
- }
-
-
-
-
-
- }else if(win.button("wdRecord")){
-
- win.button("wdRecord").onclick=null;
- win.button("wdRecord").hide();
- win.button("wdRecord_save").hide();
-
- }
- }else if(wd.topWindow.wdRecordIcon){
-
- if(!document.querySelector("ssDlg[setPval=false]")){ // ("wdDialog[setValue=。Lin
- wd.topWindow.wdRecordIcon.style.display=""
- // var className= wd.topWindow.wdRecordIcon.getAttribute("class");
- var settingClass="largeIcon-set";
- var okClass="largeInvertIcon-save";
- wd.topWindow.wdRecordIcon.parentNode.setAttribute("class",settingClass);
- // largeIcon-set invertIcon-save
- // if(/.*\_save/.test(className)){
- // wd.topWindow.wdRecordIcon.setAttribute("class",className.replace(/\_save/,""))
- // }else{
- //
- // }
-
-
- //表示当前是编辑或是保存按钮
- wd.topWindow.wdRecordIcon.isSaveButton=false;
-
- wd.topWindow.wdRecordIcon.onclick=function(){
- var thiswindow=wd.topWindow.wd.base.applyIframeElement.contentWindow;
- while(thiswindow){
- try{
-
- if(this.isSaveButton){
- thiswindow.wd.record.hide();
- this.isSaveButton=false;
- wd.topWindow.wdRecordIcon.parentNode.setAttribute("class",settingClass);
- }else{
- thiswindow.wd.record.show();
- this.isSaveButton=true;
- wd.topWindow.wdRecordIcon.parentNode.setAttribute("class",okClass);
- }
-
-
-
- }catch(e){
- console.error(e);
- }
- var iframe= thiswindow.document.querySelector("iframe");
- thiswindow=iframe?iframe.contentWindow:null;
- }
- }
-
- }
- // else if(win&&win.button("wdRecord")){
- // wd.topWindow.wdRecordIcon.onclick=null;
- // wd.topWindow.wdRecordIcon.style.display="none";
- //
- // win.button("wdRecord").hide();
- // }
-
- }
-
-
-
-
-
- }catch(e){
- console.log(e)
- }
-
-
-
-
-
- }
- wd.record={
- dialogClassName:"wdRecord"
- ,
- secondClick:false
- ,
- wdRecordValue:{}
- ,
- /*
- * 第一次点击:设置个人选值,第二次:点击保存
- */
- show: function(div){
-
- if(document.querySelectorAll(("ssDlg[setPval=false]")).length==1){ // (("wdDialog[setValue=。Lin
- alert("无法设置个人选值!");
- return ;
- }
-
- var wdRecordList=this.findWdRecord();
- if(wdRecordList.length==0){
- console.log("找不到元素设置个人选值")
- return;
- }
-
-
- // if(this.findDialog().length>0){//第二次点击
- // this.hide();
- // return;
- // }
-
- if(window.wdRecordValue){
- this.wdRecordValue=(typeof wdRecordValue=="object")?wdRecordValue: eval("("+wdRecordValue+")")
- }
-
- for(var key in wdRecordList){
- this.showDialog(wdRecordList[key])
- }
-
- }
- ,
- hide:function(){
-
- var recordZhi=this.getRecordData();
-
- // if(!document.querySelector("#wdComponentID"))return;
-
- // console.log(recordZhi)
- // var bjid= document.getElementsByName("wdComponentID")[0].value
- this.insertRecordsService(recordZhi);
- this.removeDialog()
-
- }
- ,
- showDialog:function(inputbox){
-
- var ele=inputbox.container;
- if(!ele)return;
-
- var eleName=inputbox.name
- var topDoc = window.document;
- var chartDiv =$("<div class=\""+this.dialogClassName+"\" style='display: inline-block; position: absolute;z-index:1;'></div>")
- var status="0";
- if(this.wdRecordValue[eleName]){
- status=("true"==this.wdRecordValue[eleName].default)?"1":"2";
- }
- var rule={"0":{class:"icon-empty",status:"0",next:"1",title:"未启用"},
- "1":{class:"icon-warningFull",status:"1",next:"2",title:"填左边录入的值"},
- "2":{class:"icon-copy",status:"2",next:"0",title:"填上次录入的值"}}
-
- $(chartDiv).html("<div title=\""+rule[status].title+"\" status=\""+status+"\" wdrecordcheckbox=\"true\" class=\""+rule[status].class+"\" style=\"display: inline-block; position: absolute;\"></div>")
-
- $(ele).after(chartDiv);
- chartDiv.css({width:chartDiv.children().css("width"),height:chartDiv.children().css("height")})
- chartDiv[0].inputbox=inputbox;
-
- // var bounding=ele.getBoundingClientRect();
- // var $p=$(ele).parents().filter(function(){
- // if($(this).css("position")=="relative"|| $(this).css("position") == "absolute"|| $(this).css("position") == "fixed")return true;
- // }).first()
- // var $p=$(ele).offsetParent();
- // if($p.length==0)$p=null
- //
- // var chartDivWidth=chartDiv.width();
- // var chartDivHeight=chartDiv.height();
- // var pbounding=$p? $p[0].getBoundingClientRect():null;
- //
- // chartDiv.css("left" ,(bounding.width+bounding.left-(pbounding?pbounding.left:0) )+"px")
- // chartDiv.css("top" ,(bounding.top-(pbounding?pbounding.top:0)+(bounding.height-chartDivHeight)*0.5)+"px")
- var pos=$(ele).position();
- var bounding=ele.getBoundingClientRect();
- console.log(pos.left+bounding.width);
-
- chartDiv.css("left",pos.left+bounding.width)
- chartDiv.css("top",pos.top+(bounding.height-bounding.height)*0.5)
- var leftx=chartDiv.offset().left+chartDiv.width()-$(window).width();
- if(leftx>0){
- chartDiv.animate({left:"-="+leftx});
- }
-
-
-
-
- $(chartDiv).on("click","[wdrecordcheckbox=true]",function(){
- var thisstatus= $(this).attr("status");
- var nextrule=rule[rule[thisstatus].next];
-
-
- $(this).attr("class","").addClass(nextrule.class).attr("title",nextrule.title).attr("status",nextrule.status);
-
- })
-
- },
- recursionIframe:function(win){
-
- if(win.parent==top&&win.parent==win){
- // var xy = this.getAbsPoint(win);
- return {"x": 0, "y": 0 , "w" : 0 , "h" : 0 };
- }
- var winPar = win.parent;// .opener
- var iframeArr = winPar.document.getElementsByTagName('IFRAME');
- var targetIframe;
- for(var i=0;i<iframeArr.length;i++){
- var iframeElem = iframeArr[i];
- if(iframeElem.contentWindow==win){
- targetIframe = iframeElem;
- break;
- }
- }
- // alert(targetIframe==null)
- // var xy = this.getAbsPoint(targetIframe);
- var xy={x:this.getLeft(targetIframe),y:this.getTop(targetIframe)}
-
- if(winPar.parent!=winPar){
- var xy2 =this.recursionIframe(winPar);
- xy.x += xy2.x;
- xy.y += xy2.y;
- }
-
- return xy
- }
- ,
- getTop: function (e){
- var offset=e.offsetTop;
- if(e.offsetParent!=null) offset+=this.getTop(e.offsetParent);
- return offset;
- }
- ,
- getLeft:function (e){
- var offset=e.offsetLeft;
- if(e.offsetParent!=null) offset+=this.getLeft(e.offsetParent);
- return offset;
- }
- ,
- /*
- * 返回页面所有带wdRecord="true"的元素
- */
- findWdRecord:function(){
- var wdRecordList=[]
-
- var groups= wd.display.getInputsGroups();
- for(var key in groups){
- if("ueditor"==groups.type||"onoffbutton"==groups.type)
- continue;
-
- wdRecordList.push(groups[key])
-
- }
-
-
-
-
- return wdRecordList;
-
- }
- ,findDialog:function(){
- return document.getElementsByClassName(this.dialogClassName)
- }
- /*删除勾选框*/
- ,removeDialog:function(){
-
- while(this.findDialog().length>0){
- var record={}
- var removeEle= this.findDialog()[0];
- // console.log(removeEle.record)
- removeEle.parentNode.removeChild(removeEle)
- }
-
-
- }
- ,
- /*获得部件ID:bjid */
- getBjid:function(){
- var con=document.getElementsByName("wdComponentID");
- if(con.length==0)return;
- return con[0].value;
-
- }
- /*根据勾选框+元素值生成数据 */
- ,getRecordData:function(){
- var recordZhi={};
- var cancelZhi={};//删除
-
- if(window.wdRecordValue&&typeof wdRecordValue=="string"){
-
- recordZhi=eval("("+wdRecordValue+")")
- }else if(window.wdRecordValue&&typeof wdRecordValue=="object"){
- recordZhi=wdRecordValue;
- }
- console.log(recordZhi);
-
-
- var dialogList=this.findDialog();
- // {"nrid": {value:"440120001400",defualt:true},"bt":{"nrid": {value:"标题",defualt:false} }
- for(var i=0;i<dialogList.length;i++){
- var inputbox=dialogList[i].inputbox;
-
- var recordName=inputbox.name;
- var recordValue=inputbox.getValue();
- var status=dialogList[i].querySelector("[wdrecordcheckbox=true]").getAttribute("status");
-
- //value空清除选值
- recordZhi[recordName]={value:(status=="0")?"":recordValue,default:("1"==status?true:false)}
- }
-
-
-
-
- return recordZhi;
-
- }
- ,
- insertRecordsService:function(recordZhi){
- var THIS=this;
- var token;
- var ps=window.location.href.replace(/.*\?/,"").split("&");
-
- for(var i=0;i<ps.length;i++){
- if(ps[i].indexOf("ssToken=")>-1){ // ("token=")>。Lin
- token=ps[i].replace("ssToken\=",''); // ("token\=",。Lin
- break;
- }
- }
- // if(!THIS.getBjid()){
- // console.log("找不到bjid!")
- // return;
- // }
-
-
-
- $.ajax({
- type:"post",
- url:"/service?ssServ=insertRecords",
- async:true,
- data:{
- // bjid:THIS.getBjid(),
- zhi:JSON.stringify(recordZhi),
- tokenstring:token
- },
- success:function(data){
- // alert(data)
- THIS.removeDialog()
-
- },error:function(){
- alert("保存选值失败")
- }
- });
-
-
- }
- }
|