利用js的闭包原理做对象封装及调用方法(2)

(function(){ //____________________________批量修改的基类_________________________________ function BatchModify(){} //选择了什么id BatchModify.prototype.numIids=null; BatchModify.prototype.addis=null; BatchModify.prototype.oneIid=null; BatchModify.prototype.skuIds=null; BatchModify.prototype.selectedItemData=null; BatchModify.prototype.maxHeightVal=$(window).height()*0.9; // 完全克隆一个数组 BatchModify.prototype.cloneArr=function(arr) { var arrNew = []; for(var i=0;i<arr.length;i++) { arrNew.push(arr[i]); } return arrNew; } // 通过jqGrid('getGridParam','selarrrow');取值是不可靠的,经常会变动 // 在设置jqGrid('setSelection',bindedArr[i]);之后取出来的值经常会变化,要么长度变化,要么顺序变化 BatchModify.prototype.cancelBindedItem=function() { var tempNumIids=jQuery("#listItemDefine").jqGrid('getGridParam','selarrrow'); var tempNumIidsClone = this.cloneArr(tempNumIids); var isAlert=false; for(var i=0;i<bindedArr.length;i++) { for(var j=0;j<tempNumIidsClone.length;j++) { if(tempNumIidsClone[j]==bindedArr[i]) { isAlert=true; jQuery("#listItemDefine").jqGrid('setSelection',bindedArr[i]); break; } } } if(isAlert) alert("已经绑定了数据来源的宝贝不能修改宝贝设置,如果需要修改请先点击宝贝最右栏的解绑按钮解绑!"); } BatchModify.prototype.setNumIids=function() { this.numIids=jQuery("#listItemDefine").jqGrid('getGridParam','selarrrow'); }; //拼装addi的json串并赋值给addi BatchModify.prototype.setAddis=function() { var _addis="{rows:{"; for(var i=0;i<this.numIids.length;i++) { _addis+='"'+this.numIids[i]+'":"'; var tempVal=$("#addiTextId"+this.numIids[i]).val(); var val=tempVal.replace(/\"/ig,"\'"); _addis+=val; _addis+='"' if(i!=this.numIids.length-1) { _addis+=','; } } _addis+="}}"; this.addis=_addis; }; //(单个)修改页面传进来的一个id BatchModify.prototype.setOneIid=function() { this.oneIid=$("#"+itemEditVars.itemEditClientId.HfNumIid).val(); }; //sku的所有已选id(一个字符串) BatchModify.prototype.setSkuIds=function() { this.skuIds=jQuery("#listSkuDefine").jqGrid('getGridParam','selarrrow'); }; //设置numIids的值到服务器组件 BatchModify.prototype.setNumIidsToCom=function() { $("#"+globalVars.serverComClientId.HfItemDefineIdsSelect).val(this.numIids); }; //设置addis的值到服务器组件 BatchModify.prototype.setAddisToCom=function() { $("#"+globalVars.serverComClientId.HfAddiStr).val(this.addis); }; //检查是否有勾选宝贝 BatchModify.prototype.checkIsSelected=function() { if (this.numIids == "") { alert("请选中要批量修改的行!"); return false; } return true; }; //批量生成描述 BatchModify.prototype.batchGenerateDesc=function(alertResult) { this.setNumIidsToCom(); var urledit = "x.aspx?method=BatchGenerateDesc&rdm=" + Math.random(); if (alertResult) urledit += "&generateByManual=true"; this.postData(urledit,alertResult); }; //post数据 BatchModify.prototype.postData=function(urledit,alertResult) { $.post( urledit, $("#"+globalVars.serverComClientId.formAldsItemDefine1).serialize()) .done(function(myJsonResult) { var data = $.evalJSON(myJsonResult); ajaxResponseResult(data); if (data.IsSuccess) { if (!data.rows) showPrompt("宝贝描述生成修改成功!"); } if(alertResult && data.ErrMsg && $.trim(data.ErrMsg) != "") alert("提醒:\n\n" + data.ErrMsg); }) .fail(function(data) { ajaxResponseResult(data); }) .always(function(myJsonResult) { }); }; BatchModify.prototype.removeDialog=function() { try{ $("#descTempDiv").remove(); } catch(e){} } function myInherits(Child,Parent) { function F(){} F.prototype=Parent.prototype; Child.prototype=new F(); Child.prototype.constructor=Child; } function createobject(proto) { function F(){} F.prototype=proto; return new F(); } //_________________________批量修改(附言,确认收货后发消息,好评后发消息)类_________________________________ function BatchMsgModify(title,tableId,paperId,fieldName,editUrl,containerDivStr) { BatchModify.call(); this.title=title; this.tableId=tableId; this.paperId=paperId; this.fieldName=fieldName; this.editUrl=editUrl; this.containerDivStr=containerDivStr; } myInherits(BatchMsgModify,BatchModify); //弹窗 BatchMsgModify.prototype.popUpDialog=function() { $(this.containerDivStr).dialog({ title: this.title, closeText: '关闭', width: 980, maxHeight: $(window).height() * 0.98, minHeight: $(window).height() * 0.7, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 确定: function() { currentInstance.confirmCallback(this); }, 关闭: function() { $(this).dialog("close"); } } }); }; //创建表格 BatchMsgModify.prototype.createTable=function() { $("#"+this.tableId).jqGrid({ viewrecords: true, // show the current page, data rang and total records on the toolbar datatype: 'local', rowNum:100, rowList:[100], height: "auto", pager: "#"+this.paperId, colNames:['主图','宝贝','NumIid','Price','OuterId',this.title.indexOf("批量修改")>=0?this.title.substring(4):this.title], colModel:[ {name:'PicUrl', index: 'PicUrl', width: 60, align: "center", sortable: false, formatter: imgFormatter, unformat:imgUnFormat}, {name:'Title',index:'OuterId', width:430, sortable: true, formatter: itemDescFormatter, unformat:itemDescUnFormat}, {name:'NumIid',index:'NumIid', width:100, hidden:true, key:true}, {name:'Price',index:'Price', width:100, hidden:true}, {name: 'OuterId', index: 'OuterId', width: 100, hidden: true }, {name: this.fieldName, index: this.fieldName, width: 440, sortable: true, hidden: false, formatter:this.formatter} ] }); }; //把表格填充进数据 BatchMsgModify.prototype.initTable=function() { var gridArrayData=[]; for(var i=0;i<this.numIids.length;i++) { var curRowData=jQuery("#listItemDefine").jqGrid('getRowData',this.numIids[i]); var obj=new Object(); obj["PicUrl"]=curRowData.PicUrl; obj["Title"]=curRowData.Title; obj["NumIid"]=curRowData.NumIid; obj["Price"]=curRowData.Price; obj["OuterId"]=curRowData.OuterId; obj[this.fieldName]=curRowData[this.fieldName]; gridArrayData.push(obj); } $("#"+this.tableId).jqGrid('setGridParam',{data:gridArrayData}); $("#"+this.tableId).trigger('reloadGrid'); }; //格式化字段 BatchMsgModify.prototype.formatter=function(cellvalue,options,rowdata) { return "<TextArea rows='4'>"+rowdata[currentInstance.fieldName]+"</TextArea>"; }; //重写post函数 BatchMsgModify.prototype.postData=function(urledit,sender) { $.post( urledit, $("#"+globalVars.serverComClientId.formAldsItemDefine1).serialize()) .done(function(myJsonResult) { var data = $.evalJSON(myJsonResult); ajaxResponseResult(data); if (data.IsSuccess) { if (!data.rows) showPrompt(currentInstance.title+"成功"+currentInstance.numIids.length+"个!"); $("#listItemDefine").trigger('reloadGrid'); setTimeout(function () { $(sender).dialog("close"); }, 0); setTimeout(function () { $(sender).dialog("destroy"); }, 1000); } if(data.ErrMsg && $.trim(data.ErrMsg) != "") alert(currentInstance.title+"出错:\n\n" + data.ErrMsg); }) .fail(function(data) { ajaxResponseResult(data); }) .always(function(myJsonResult) { }); }; //确认按钮的回调函数 BatchMsgModify.prototype.confirmCallback=function(sender) { this.setAddis(); this.setNumIidsToCom(); this.setAddisToCom(); this.postData(this.editUrl+"&rdm=" + Math.random(),sender); }; //实例 var batchAddi=null; var batchMsgTradeSuccess=null; var batchMsgRatedGood=null; var currentInstance=null;//指向当前对象,当this指向失效的时候可以使用这个 openBatchMsgDialogType={batchAddi:0,batchMsgTradeSuccess:1,batchMsgRatedGood:2}; openBatchMsgDialog=function(typeCode) { if(typeCode==openBatchMsgDialogType.batchAddi) { if (batchAddi==null) batchAddi=new BatchMsgModify("批量修改附言","tableEditContent","tablePaper","Additional","x.aspx?method=UpdateMsgAdditional","<div><table></table><div></div></div>"); currentInstance=batchAddi; batchAddi.cancelBindedItem(); batchAddi.setNumIids(); if(!batchAddi.checkIsSelected()) return; batchAddi.popUpDialog(); batchAddi.createTable(); batchAddi.initTable(); }else if (typeCode==openBatchMsgDialogType.batchMsgTradeSuccess) { if (batchMsgTradeSuccess==null) batchMsgTradeSuccess=new BatchMsgModify("批量修改确认收货后发消息","tableEditMsgTradeSuccessContent","tableMsgTradeSuccessPaper","MsgTradeSuccess","x.aspx?method=UpdateMsgTradeSuccess","<div><table></table><div></div></div>"); currentInstance=batchMsgTradeSuccess; batchMsgTradeSuccess.cancelBindedItem(); batchMsgTradeSuccess.setNumIids(); if(!batchMsgTradeSuccess.checkIsSelected()) return; batchMsgTradeSuccess.popUpDialog(); batchMsgTradeSuccess.createTable(); batchMsgTradeSuccess.initTable(); }else if (typeCode==openBatchMsgDialogType.batchMsgRatedGood) { if (batchMsgRatedGood==null) batchMsgRatedGood=new BatchMsgModify("批量修改好评后发消息","tableEditMsgRatedGoodContent","tableMsgRatedGoodPaper","MsgRatedGood","x.aspx?method=UpdateMsgRatedGood","<div><table></table><div></div></div>"); currentInstance=batchMsgRatedGood; batchMsgRatedGood.cancelBindedItem(); batchMsgRatedGood.setNumIids(); if(!batchMsgRatedGood.checkIsSelected()) return; batchMsgRatedGood.popUpDialog(); batchMsgRatedGood.createTable(); batchMsgRatedGood.initTable(); } } //_______________________________批量修改宝贝类(弹出单独页面,只要弹窗即可)_________________________________ function BatchItemModify(){} myInherits(BatchItemModify,BatchModify); //重写 BatchItemModify.prototype.popUpDialog=function() { var urledit = "./x.aspx?NumIids="+this.numIids+"&rdm="+Math.random(); $.get(urledit, {}, function (data, textStatus, object) { var str = "<div>" + object.responseText + "</div>"; $(str).dialog({ dialogClass: "untitle", closeText: '关闭', width: 800, height: 400, maxHeight: $(window).height() * 0.9, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 确定: function() { submitAldsItemEditBatch(this, $("#listItemDefine")); //在x.aspx定义 currentInstance.batchGenerateDesc(); }, 关闭: function() { $( this ).dialog( "close" ); } } }); }); } //实例 var batchItem=null; openBatchItemDialog=function() { if (batchItem==null) batchItem=new BatchItemModify(); currentInstance=batchItem; batchItem.cancelBindedItem(); batchItem.setNumIids(); if(!batchItem.checkIsSelected()) return; batchItem.popUpDialog(); } //_______________________________批量生成宝贝描述__________________________________________ function BatchDescModify(){} myInherits(BatchDescModify,BatchModify); BatchDescModify.prototype.generating=function() { if (!confirm("提醒。\n\n是否继续?")) return; this.batchGenerateDesc(true); }; //实例 var batchDesc=null; onBatchDesc=function() { if(batchDesc==null) batchDesc=new BatchDescModify(); currentInstance=batchDesc; batchDesc.setNumIids(); if(!batchDesc.checkIsSelected()) return; batchDesc.generating(); } //_____________________________________修改模板______________________________________________ onDescMouldDialog=function() { var urledit = "./x.aspx?rdm="+Math.random(); $.get(urledit,{},function(data,textStatus,object){ var str="<div>"+object.responseText+"</div>"; $(str).dialog({ title:'修改描述模板', closeText:'关闭', width:850, maxHeight:$(window).height() * 0.98, modal:true, show:{effect:"fade",duration:300}, hide:{effect:"fade",duration:300}, buttons:{ 确定:function() { onTempParaChangeHandler(this); }, 关闭:function() { $(this).dialog("close"); } } }); }); } //___________________________________批量修改sku_______________________________________ function BatchSkuModify(){} myInherits(BatchSkuModify,BatchModify); BatchSkuModify.prototype.popUpDialog=function() { var urledit = "./x.aspx?NumIids="+this.oneIid+"&SkuIds="+this.skuIds+"&IsSkuEditBatch=true&rdm="+Math.random(); $.get(urledit, {}, function (data, textStatus, object) { var str = "<div>" + object.responseText + "</div>"; $(str).dialog({ dialogClass: "untitle", closeText: '关闭', width: 800, height: 400, maxHeight: $(window).height() * 0.9, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 确定: function() { submitAldsItemEditBatch(this, $("#listSkuDefine")); //在x.aspx定义 }, 关闭: function() { $( this ).dialog( "close" ); } } }); }); }; BatchSkuModify.prototype.checkIsSelected=function() { if (this.skuIds == "") { alert("请选中要批量修改的SKU!"); return false; } return true; }; //实例 var batchSku=null; openBatchSkuDialog=function() { if(batchSku==null) batchSku=new BatchSkuModify(); currentInstance=batchSku; batchSku.setOneIid(); batchSku.setSkuIds(); batchSku.removeDialog(); if(!batchSku.checkIsSelected()) return; batchSku.popUpDialog(); } //_______________________________批量修改SKU附言__________________________________________________ function BatchSkuMsgModify(title,tableId,paperId,fieldName,editUrl,containerDivStr) { BatchModify.call(); this.title=title; this.tableId=tableId; this.paperId=paperId; this.fieldName=fieldName; this.editUrl=editUrl; this.containerDivStr=containerDivStr; } myInherits(BatchSkuMsgModify,BatchModify); BatchSkuMsgModify.prototype.popUpDialog=function() { $(this.containerDivStr).dialog({ title: this.title, closeText: '关闭', width: 980, maxHeight: this.maxHeightVal, // height: this.maxHeightVal>750 ? 750 : this.maxHeightVal, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 确定: function() { currentInstance.confirmCallback(this); }, 关闭: function() { $(this).dialog("close"); } } }); }; //重写-创建表格 BatchSkuMsgModify.prototype.createTable=function() { $("#"+this.tableId).jqGrid({ viewrecords: true, // show the current page, data rang and total records on the toolbar datatype: 'local', rowNum:100, rowList:[100], height: "auto", pager: "#"+this.paperId, colNames:['SkuId','属性名',this.title.indexOf("批量修改")>=0?this.title.substring(4):this.title], colModel:[ {name:'SkuId',index:'SkuId', width:400, hidden:true, key:true}, {name:'PropertiesName',index:'PropertiesName', width:400,sortable:false, editable: false, hiden:false}, {name: this.fieldName, index: this.fieldName, width: 440, sortable: true, hidden: false, formatter:this.formatter} ] }); }; //把表格填充进数据 BatchSkuMsgModify.prototype.initTable=function() { var gridArrayData=[]; for(var i=0;i<this.skuIds.length;i++) { var curRowData=jQuery("#listSkuDefine").jqGrid('getRowData',this.skuIds[i]); var obj=new Object(); obj["SkuId"]=curRowData.SkuId; obj["PropertiesName"]=curRowData.PropertiesName; obj[this.fieldName]=curRowData[this.fieldName]; gridArrayData.push(obj); } $("#"+this.tableId).jqGrid('setGridParam',{data:gridArrayData}); $("#"+this.tableId).trigger('reloadGrid'); }; //重写-格式化字段 BatchSkuMsgModify.prototype.formatter=function(cellvalue,options,rowdata) { return "<TextArea rows='4'>"+rowdata[currentInstance.fieldName]+"</TextArea>"; }; //重写post函数 BatchSkuMsgModify.prototype.postData=function(urledit,sender) { $.post( urledit, $("#"+itemEditVars.itemEditClientId.formAldsItemEdit1).serialize()) .done(function(myJsonResult) { var data = $.evalJSON(myJsonResult); ajaxResponseResult(data); if (data.IsSuccess) { if (!data.rows) showPrompt(currentInstance.title+"成功"+currentInstance.skuIds.length+"个!"); $("#listSkuDefine").trigger('reloadGrid'); setTimeout(function () { $(sender).dialog("close"); }, 0); setTimeout(function () { $(sender).dialog("destroy"); }, 1000); } if(data.ErrMsg && $.trim(data.ErrMsg) != "") alert(currentInstance.title+"出错:\n\n" + data.ErrMsg); }) .fail(function(data) { ajaxResponseResult(data); }) .always(function(myJsonResult) { }); }; //重写-拼装json BatchSkuMsgModify.prototype.setAddis=function() { var _addis="{rows:{"; for(var i=0;i<this.skuIds.length;i++) { _addis+='"'+this.skuIds[i]+'":"'; var tempVal=$("#addiTextId"+this.skuIds[i]).val(); var val=tempVal.replace(/\"/ig,"\'"); _addis+=val; _addis+='"' if(i!=this.skuIds.length-1) { _addis+=','; } } _addis+="}}"; this.addis=_addis; }; //重写-设置numIids到组件 BatchSkuMsgModify.prototype.setNumIidsToCom=function() { $("#"+itemEditVars.itemEditClientId.HfNumIid).val(this.oneIid); }; //新增-设置skuids到组件 BatchSkuMsgModify.prototype.setSkuIdsToCom=function() { $("#"+itemEditVars.itemEditClientId.HfSkuIds).val(this.skuIds); }; //重写 BatchSkuMsgModify.prototype.setAddisToCom=function() { $("#"+itemEditVars.itemEditClientId.HfSkuAddiStr).val(this.addis); }; //确认按钮的回调函数 BatchSkuMsgModify.prototype.confirmCallback=function(sender) { this.setAddis(); this.setNumIidsToCom(); this.setSkuIdsToCom(); this.setAddisToCom(); currentInstance.postData(this.editUrl+"&rdm=" + Math.random(),sender); }; // BatchSkuMsgModify.prototype.checkIsSelected=function() { if (this.skuIds == "") { alert("请选中要批量修改附言的SKU!"); return false; } return true; }; //实例 var batchSkuAddi=null; openBatchSkuMsgDialogType={batchSkuAddi:0}; openBatchSkuMsgDialog=function(typeCode) { if (typeCode==openBatchSkuMsgDialogType.batchSkuAddi) { if (batchSkuAddi==null) batchSkuAddi=new BatchSkuMsgModify("批量修改SKU附言","tableEditContent","tablePaper","Additional","x.aspx?method=UpdateMsgAdditional","<div><table></table><div></div></div>"); currentInstance=batchSkuAddi; batchSkuAddi.removeDialog(); batchSkuAddi.setOneIid(); batchSkuAddi.setSkuIds(); if(!batchSkuAddi.checkIsSelected()) return; batchSkuAddi.popUpDialog(); batchSkuAddi.createTable(); batchSkuAddi.initTable(); } } //_______________________________生成描述_________________________________________________ var descBatchModify=null; batchGenerateDesc=function(descNumIds,alertResult) { if(descBatchModify==null) descBatchModify=new BatchModify(); descBatchModify.numIids=descNumIds; descBatchModify.setNumIidsToCom(); descBatchModify.batchGenerateDesc(alertResult); } //_______________________________同步类(弹出单独页面,只要弹窗即可)_________________________________ function SyncModify(){} myInherits(SyncModify,BatchModify); //重写 SyncModify.prototype.popUpDialog=function() { var urledit="./x.aspx?rdm="+Math.random(); $.post(urledit,{numIids:this.numIids.toString()},function(data,textStatus,object){ var str = "<div>" + object.responseText + "</div>"; $(str).dialog({ title:"同步设置", closeText: '关闭', width: 1150, height: 800, maxHeight: $(window).height() * 0.9, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 同步: function() { onAldsItemSync(this, $("#listItemDefine")); //在x.aspx定义 }, 取消: function() { $( this ).dialog( "close" ); } } }); }); } var syncModify=null; openSyncDialog=function() { if(syncModify==null) syncModify=new SyncModify(); currentInstance=syncModify; syncModify.setNumIids(); if(!syncModify.checkIsSelected()) return; syncModify.removeDialog(); syncModify.popUpDialog(); } //____________________________同步SKU设置(弹出单独页面,只需弹窗)___________________________________ function SyncSkuModify(){} myInherits(SyncSkuModify,BatchModify); SyncSkuModify.prototype.popUpDialog=function() { var urledit="./x.aspx?rdm="+Math.random(); $.post(urledit,{numIid:currentInstance.oneIid.toString(),skuIds:currentInstance.skuIds.toString()},function(data,textStatus,object){ var str = "<div>" + object.responseText + "</div>"; $(str).dialog({ title:"同步SKU设置", closeText: '关闭', width: 1150, height: 800, maxHeight: $(window).height() * 0.9, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 同步: function() { onAldsSkuSync(this, $("#listSkuDefine")); //在x.aspx定义 }, 取消: function() { $( this ).dialog( "close" ); } } }); }); } SyncSkuModify.prototype.checkIsSelected=function() { if (this.skuIds == "") { alert("请选中要同步设置的SKU!"); return false; } return true; }; var syncSkuModify=null; openSkuSyncDialog=function() { if($("#"+itemEditVars.itemEditClientId.HfNumIidFrom).val()=="none") { alert("没有找到已经绑定的宝贝!要同步SKU设置,需要先绑定对应的宝贝,才能同步宝贝下面的SKU!"); return; } if(syncSkuModify==null) syncSkuModify=new SyncSkuModify(); currentInstance=syncSkuModify; syncSkuModify.setOneIid(); syncSkuModify.setSkuIds(); if (!syncSkuModify.checkIsSelected()) return; syncSkuModify.removeDialog(); syncSkuModify.popUpDialog(); } //__________________________item批量(及单独)解除绑定_________________________________ function BatchDisBindingItem(){} myInherits(BatchDisBindingItem,BatchModify); // 对非绑定item取消勾选,是为了下一步批量解除绑定 BatchDisBindingItem.prototype.cancelFreeItem=function() { var isAlert = false; var isBinded = false; var tempNumIids = jQuery("#listItemDefine").jqGrid('getGridParam', 'selarrrow'); var tempNumIidsClone = this.cloneArr(tempNumIids); for (var i = 0; i < tempNumIidsClone.length; i++) { var numIidTmp = tempNumIidsClone[i]; var curRowData = jQuery("#listItemDefine").jqGrid('getRowData', numIidTmp); if (curRowData.NumIidFrom == "none") { isAlert = true; jQuery("#listItemDefine").jqGrid('setSelection', numIidTmp); } } if (isAlert) { alert("未绑定的宝贝不能作解绑的动作!"); // return true 表示已经alert了 return true; } return false; } BatchDisBindingItem.prototype.popUpDialog=function() { var showStr='<div><span>注意:您正在批量解除绑定,如果您解除了绑定,今后数据源宝贝设置有更新您的宝贝设置将不会同步更新!</span></div>'; $(showStr).dialog({ title: "解除绑定", closeText: '关闭', width: 600, height:300, maxHeight: $(window).height() * 0.98, minHeight: $(window).height() * 0.7, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 解绑: function() { disBindingItem(currentInstance.numIids,this); }, 关闭: function() { $(this).dialog("close"); } } }); } var batchDisBindItemInstance = null; batchDisBindingItem=function() { var isAlerted = false; if(batchDisBindItemInstance==null) batchDisBindItemInstance=new BatchDisBindingItem(); currentInstance=batchDisBindItemInstance; if(batchDisBindItemInstance.cancelFreeItem()) isAlerted = true; batchDisBindItemInstance.setNumIids(); if(isAlerted) { if(currentInstance.numIids=="") return; } if(!batchDisBindItemInstance.checkIsSelected()) return; batchDisBindItemInstance.removeDialog(); batchDisBindItemInstance.popUpDialog(); } disBindingItem=function(myNumIids,sender) { var urledit = "./x.aspx?method=DisBinding&NumIids="+myNumIids+"&rdm="+Math.random(); $.get(urledit, {}, function (dataString, status, object) { var data = $.evalJSON(dataString); ajaxResponseResult(data); if(data.IsSuccess==true) { $(sender).dialog("close"); $("#listItemDefine").trigger("reloadGrid"); } }); } //____________________________sku批量及单独解除绑定____________________________________________ function BatchDisBindingSku(){} myInherits(BatchDisBindingSku,BatchSkuModify); BatchDisBindingSku.prototype.cancelFreeItem=function() { var tempNumIids = jQuery("#listSkuDefine").jqGrid('getGridParam','selarrrow'); var tempNumIidsClone = this.cloneArr(tempNumIids); var isAlert=false; var isBinded = false; for(var i=0;i<tempNumIidsClone.length;i++) { isBinded = false; for(var j=0;j<bindedSkuArr.length;j++) { if(tempNumIidsClone[i]==bindedSkuArr[j]) { isBinded = true; break; } } if(!isBinded) { isAlert = true; jQuery("#listSkuDefine").jqGrid('setSelection',tempNumIidsClone[i]); } } if(isAlert) { alert("未绑定的SKU不能作解绑的动作!"); // 返回true表示已经弹出alert了 return true; } return false; } BatchDisBindingSku.prototype.popUpDialog=function() { var showStr='<div><span>注意:您正在批量解除SKU绑定,如果您解除了绑定,今后数据源宝贝设置有更新您的宝贝设置将不会同步更新!</span></div>'; $(showStr).dialog({ title: "解除绑定", closeText: '关闭', width: 600, height:300, maxHeight: $(window).height() * 0.98, minHeight: $(window).height() * 0.7, modal: true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 }, buttons: { 解绑: function() { disBindingSku(currentInstance.oneIid,currentInstance.skuIds,this); }, 关闭: function() { $(this).dialog("close"); } } }); } var batchDisBindSkuInstance = null; // 批量 batchDisBindingSku=function() { var isAlerted = false; if(batchDisBindSkuInstance==null) batchDisBindSkuInstance=new BatchDisBindingSku(); currentInstance=batchDisBindSkuInstance; if(batchDisBindSkuInstance.cancelFreeItem()) isAlerted = true; batchDisBindSkuInstance.setOneIid(); batchDisBindSkuInstance.setSkuIds(); // 如果已经弹过一次了,那再次判断是否没有勾选的时候,就不要再弹了 if(isAlerted) { if(currentInstance.skuIds == "") return; } if(!batchDisBindSkuInstance.checkIsSelected()) return; batchDisBindSkuInstance.removeDialog(); batchDisBindSkuInstance.popUpDialog(); } // 单独 disBindingSku=function(numIid, skuIds, sender) { var urledit = "./x.aspx?method=DisBinding&NumIid=" + numIid + "&SkuIds="+skuIds+"&rdm=" + Math.random(); $.get(urledit, {}, function (dataString, status, object) { var data = $.evalJSON(dataString); ajaxResponseResult(data); if (data.IsSuccess == true) { $(sender).dialog("close"); $("#listSkuDefine").trigger("reloadGrid"); } }); } })();

以上这篇利用js的闭包原理做对象封装及调用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwyzdj.html