jeecg3.8popup添加選擇後的回調事件

第一步:web

項目名\src\main\webapp\plug-in\tools\curdtools.js找到數據庫

popupClick(pobj,tablefield,inputnames,pcode,params) 方法,修改如下*括起來的加粗部分

function popupClick(pobj,tablefield,inputnames,pcode,params) {
if(inputnames==""||pcode==""){
alert($.i18n.prop('popup.param.error.msg'));
return;
}
console.log(111);
// var content = "url:cgReportController.do?popup&id="+pcode;
// if (params) content += "&" + params;
if(typeof(windowapi) == 'undefined'){
$.dialog({
content: "url:cgReportController.do?popup&id="+pcode,
zIndex: getzIndex(),
lock : true,
title:$.i18n.prop('common.select'),
width:800,
height: 400,
cache:false,
ok: function(){
iframe = this.iframe.contentWindow;
var selected = iframe.getSelectRows();
if (selected == '' || selected == null ){
alert($.i18n.prop('common.select.please'));
return false;
}else {
//對應數據庫字段不爲空的狀況下,根據表單中字典TEXT的值來取popup的值
if(tablefield != "" && tablefield != null){
var fields = tablefield.split(",");
var inputfield = inputnames.split(",");
for(var i1=0;i1<fields.length;i1++){
var str = "";
$.each( selected, function(i, n){
if (i==0)
str+= n[fields[i1]];
else{
str+= ",";
str+=n[fields[i1]];
}
});
var inputname = $(pobj).attr("name");
var inputs = inputname.split(".");
//判斷傳入的this格式是否爲 "AA[#index#].aa"的形式
if(str.indexOf("undefined")==-1){
if(inputs.length>1){
//update--begin--author:scott date:20171031 for:TASK #2385 online和代碼生成器 一對多行popup多字段賦值問題解決-----------
var inpu = inputs[0]+"."+inputfield[i1];

$("input[name='"+inpu+"']").val(str);
}else{
$("input[name='"+inputfield[i1]+"']").val(str);
}
}else{
if(inputs.length>1){

var inpu = inputs[0]+"."+inputfield[i1];

$("input[name='"+inpu+"']").val("");
}else{
$("input[name='"+inputfield[i1]+"']").val("");
}
}
}
}else{
//對應數據庫字段爲空的狀況下而且字典CODE傳入多個值時,根據表單中字典CODE的值從popup中來取值
var inputfield = inputnames.split(",");
if(inputfield.length>1){
for(var i1=0;i1<inputfield.length;i1++){
var str = "";
$.each( selected, function(i, n){
if (i==0)
str+= n[inputfield[i1]];
else{
str+= ",";
str+=n[inputfield[i1]];
}
});
var inputname = $(pobj).attr("name");
var inputs = inputname.split(".");
if(str.indexOf("undefined")==-1){
if(inputs.length>1){
var inpu = inputs[i1]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val(str);
}else{
$("input[name='"+inputfield[i1]+"']").val(str);
}
}else{
if(inputs.length>1){
var inpu = inputs[i1]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val("");
}else{
$("input[name='"+inputfield[i1]+"']").val("");
}
}
}
}else{
//對應數據庫字段爲空的狀況下而且字典CODE傳入一個值時,根據表單中字典TEXT的值從popup中來取值
var str = "";
$.each( selected, function(i, n){
if (i==0)
str+= n[inputfield];
else
str+= ","+n[inputfield];
});
var inputname = $(pobj).attr("name");
var inputs = inputname.split(".");
if(str.indexOf("undefined")==-1){
if(inputs.length>1){

var inpu = inputs[0]+"."+inputfield[i1];

$("input[name='"+inpu+"']").val(str);
}else{
$("input[name='"+inputfield+"']").val(str);
}
}else{
if(inputs.length>1){

var inpu = inputs[0]+"."+inputfield[i1];

$("input[name='"+inpu+"']").val("");
}else{
$("input[name='"+inputfield+"']").val("");
}
}
}
}
return true;
}

},
cancelVal: $.i18n.prop('dialog.close'),
cancel: true // 爲true等價於function(){}
});
}else{
$.dialog({
content: "url:cgReportController.do?popup&id="+pcode,
zIndex: getzIndex(),
lock : true,
title:$.i18n.prop('common.select'),
width:800,
height: 400,
parent:windowapi,
cache:false,
ok: function(){
iframe = this.iframe.contentWindow;
var selected = iframe.getSelectRows();
if (selected == '' || selected == null ){
alert($.i18n.prop('common.select.please'));
return false;
}else {
//對應數據庫字段不爲空的狀況下,根據表單中字典TEXT的值來取popup的值
if(tablefield != "" && tablefield != null){
var fields = tablefield.split(",");
var inputfield = inputnames.split(",");
for(var i1=0;i1<fields.length;i1++){
var str = "";
$.each( selected, function(i, n){
if (i==0)
str+= n[fields[i1]];
else{
str+= ",";
str+=n[fields[i1]];
}
});
var inputname = $(pobj).attr("name");
var inputs = inputname.split(".");
//判斷傳入的this格式是否爲 "AA[#index#].aa"的形式
if(str.indexOf("undefined")==-1){
if(inputs.length>1){
var inpu = inputs[0]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val(str);
}else{
// $("input[name='"+inputfield[i1]+"']").val(str);
                  //*****************************************************************************************************************
$("input[name='"+inputfield[i1]+"']").val(str).change();//回顯完調用元素的onchange事件
                  
//*****************************************************************************************************************
                            }
}else{
if(inputs.length>1){
var inpu = inputs[0]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val("");
}else{
$("input[name='"+inputfield[i1]+"']").val("");
}
}
}
}else{
//對應數據庫字段爲空的狀況下而且字典CODE傳入多個值時,根據表單中字典CODE的值從popup中來取值
var inputfield = inputnames.split(",");
if(inputfield.length>1){
for(var i1=0;i1<inputfield.length;i1++){
var str = "";
$.each( selected, function(i, n){
if (i==0)
str+= n[inputfield[i1]];
else{
str+= ",";
str+=n[inputfield[i1]];
}
});
var inputname = $(pobj).attr("name");
var inputs = inputname.split(".");
if(str.indexOf("undefined")==-1){
if(inputs.length>1){
var inpu = inputs[i1]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val(str);
}else{
$("input[name='"+inputfield[i1]+"']").val(str);
}
}else{
if(inputs.length>1){
var inpu = inputs[i1]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val("");
}else{
$("input[name='"+inputfield[i1]+"']").val("");
}
}
}
}else{
//對應數據庫字段爲空的狀況下而且字典CODE傳入一個值時,根據表單中字典TEXT的值從popup中來取值
var str = "";
$.each( selected, function(i, n){
if (i==0)
str+= n[inputfield];
else
str+= ","+n[inputfield];
});
var inputname = $(pobj).attr("name");
var inputs = inputname.split(".");
if(str.indexOf("undefined")==-1){
if(inputs.length>1){
var inpu = inputs[i1]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val(str);
}else{
$("input[name='"+inputfield+"']").val(str);
}
}else{
if(inputs.length>1){
var inpu = inputs[i1]+"."+inputfield[i1];
$("input[name='"+inpu+"']").val("");
}else{
$("input[name='"+inputfield+"']").val("");
}
}
}
}
return true;
}

},
cancelVal: $.i18n.prop('dialog.close'),
cancel: true // 爲true等價於function(){}
});
}
}

第二步:
  
找到使用popup的id元素,這裏是appIds,添加onchange事件
<input type="hidden" id="appIds" name="appIds" onchange="popupCallBack();"/>
<input id="ai" readonly placeholder="請點擊後選擇" name="ai" style="width: 85%" type="text" class="form-control" datatype="*" ignore="checked" onclick="popupClick(this,'id,name','appIds,ai','app_id')"/>

第三步:
  js代碼:
//popup選擇應用後觸發function popupCallBack() {  //拿到popup選擇完畢後回顯的id      var appIdtemp=$("#appIds").val();    //寫本身的業務邏輯    }
相關文章
相關標籤/搜索