FineReport 动态传入参数的查询js事件

在帆软报表开发时,会有按照日周月展示,分别对应日表周表和月表,如何用一个数据集实现三个表的数据切换,就需要用到js动态传入参数。例如写一个数据集:

SELECT
    a.volume1
   ,a.volume2
   ,a.volume3
   ,a.${pt}     as    time
from  ${tablename} a

WHERE ${pt}>='${startdate}' and ${pt}<='${enddate}'

此处定义了四个控件,空间名分别为pt,tablename,startdate,enddate

如实现切换需要定义点击的js事件,如下

function getWeek(adate){

    var week = adate.getDay();
    var monday=new Date();
    var sunday = new Date();
    if(week==0){
        monday.setTime(adate.getTime()-6*24*3600*1000);
        sunday.setTime(adate.getTime());
    }else{
        monday.setTime(adate.getTime()-(week-1)*24*3600*1000);
        sunday.setTime(monday.getTime()+6*24*3600*1000);
    }
    return monday.getFullYear()+""+((monday.getMonth()+1)>=10?monday.getMonth()+1:"0"+(monday.getMonth()+1))+""+(monday.getDate()>=10?monday.getDate():"0"+monday.getDate())+"-"+sunday.getFullYear()+""+((sunday.getMonth()+1)>=10?sunday.getMonth()+1:"0"+(sunday.getMonth()+1))+""+(sunday.getDate()>=10?sunday.getDate():"0"+sunday.getDate());
}


function getM(adate){
    return adate.getFullYear()+""+((adate.getMonth()+1)>=10?adate.getMonth()+1:"0"+(adate.getMonth()+1));
}


var date_from = this.options.form.getWidgetByName("datefrom");
var date_to = this.options.form.getWidgetByName("dateto");
var type = this.options.form.getWidgetByName("periodtype").getValue();
var table_Name = this.options.form.getWidgetByName("tableName");
var pt = this.options.form.getWidgetByName("pt");
var start_date = this.options.form.getWidgetByName("startdate");
var end_date = this.options.form.getWidgetByName("enddate");


if(date_from == "" || date_from == null)
{
  alert("请选择开始日期");
  return false;
}
if(date_to == "" || date_to == null)
{
  alert("请选择结束日期");
  return false;
}
var starttime=new Date(date_from.getValue().split("-")[0],date_from.getValue().split("-")[1]-1,date_from.getValue().split("-")[2]);
var starttimes=starttime.getTime()/24/3600/1000;


var lktime=new Date(date_to.getValue().split("-")[0],date_to.getValue().split("-")[1]-1,date_to.getValue().split("-")[2]);
var lktimes=lktime.getTime()/24/3600/1000;


if(lktimesalert('结束日期必须大于等于开始日期');
return false;
}
if(lktimes - starttimes >=90&&type=="day")
{
alert('时间范围应在90天内,请检查');
return false;
}
if(lktimes - starttimes >=180&&type=="week")
{
alert('时间范围应在24周内,请检查');
return false;
}
if(lktimes - starttimes >=365&&type=="month")
{
alert('时间范围应在12月内,请检查');
return false;
}


if (type=='day'){ 
  start_date.setValue(date_from.getValue().split("-")[0]+""+date_from.getValue().split("-")[1]+""+date_from.getValue().split("-")[2]);
  end_date.setValue(date_to.getValue().split("-")[0]+""+date_to.getValue().split("-")[1]
  +""+date_to.getValue().split("-")[2]);
  pt.setValue("pt_d");
  table_Name.setValue("ads_smarthome_app_user_attr_dm");
}else if (type=='week'){
  start_date.setValue(getWeek(starttime));
  end_date.setValue(getWeek(lktime));
  pt.setValue("pt_w");
  table_Name.setValue("ads_smarthome_app_user_attr_wm");
}else if(type=='month'){
  start_date.setValue(getM(starttime));
  end_date.setValue(getM(lktime));
  pt.setValue("pt_m");
  table_Name.setValue("ads_smarthome_app_user_attr_mm");
}

你可能感兴趣的:(hive)