dhtmlxCombo(非数据库取值),通过getActualValue()利用ajax传值作为鉴别条件,后台判断,encodeURI防止乱码
前台jsp页面代码:(引入文件及其他不相关略)
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="txt_disp">收费时间:</td>
<td colspan="3">
<input id="chgdateStart" name="chgdateStart" class="txt_field" style="width: 106px" οnkeydοwn="clearDate(event)" value="${today}"/><label class="txt_disp" style="margin: 0 12px">~</label><input id="chgdateEnd" name="chgdateEnd" class="txt_field" style="width: 106px" οnkeydοwn="clearDate(event)" value="${today}"/>
</td>
<td class="txt_disp" height="40">类别:</td>
<td><div id="ptype" name="ptype" ></div></td>
<td class="txt_disp" height="40">病人姓名:</td>
<td><input id="patname" name="patname" class="txt_field" maxlength="5"/></td>
<td class="txt_disp" height="40">收费员:</td>
<td width="*" >
<input id="chgman" name="chgman" class="txt_field" maxlength="5"/>
</td>
<td colspan="2" style="text-align: center;"><input type="button" class="new_btn" value="清空" style="visibility: hidden;" οnclick="clearCondition()" /><input type="button" class="new_btn" value="搜索" οnclick="loadCount()"/></td>
</tr>
</table>
js文件代码:
var combo_instype,combo_discountname,combo_ptype;
var calendar = new dhtmlXCalendarObject(["chgdateStart", "chgdateEnd"]);
combo_ptype=new dhtmlXCombo("ptype","alfa2",110);
combo_ptype.addOption("Q","全部病人");
combo_ptype.addOption("Z","在院病人");
combo_ptype.addOption("C","出院病人");
//hostypecombo.addOption("A","全部");
combo_ptype.setComboValue("Q"); //让combo默认值为“全部病人”
var chgdateStart = $("#chgdateStart").val();
var chgdateEnd = $("#chgdateEnd").val();
var patname = $("#patname").val();
var chgman = $("#chgman").val();
patname = encodeURI(encodeURI(patname)); //防止中文传到后台乱码的前台包装
chgman = encodeURI(encodeURI(chgman));
var ptype=combo_ptype.getActualValue(); //取出combo的getActualValue()
if(chgdateStart!='' && chgdateEnd!='' && chgdateStart>chgdateEnd){
alert("起始时间不能大于结束时间!");
return ;
}
//var formdata = $("#search_form").serialize();
$.ajax({
async: false,
cache: false,
ifModified: true,
type: "GET",
url: "inp/prepayCount.htm",
data: "chgdateStart="+chgdateStart+"&chgdateEnd="+chgdateEnd+"&patname="+patname+"&chgman="+chgman+"&now="+new Date().getMilliseconds()+"&hosnum="+$("#hosnum").val()+"&nodecode="+$("#nodecode").val()+"&ptype="+ptype,
dataType: "json",
error:function(){
alert("服务器内部错误!");
},
success: function(data){
if(data!="fail"){
alert(data);
}else{
alert("获取数据失败!");
}
}
});
后台java代码,通过穿过来的getActualValue()作为条件判断,代码如下:
@RequestMapping(value = "/prepayCount", method = RequestMethod.GET)
public void loadPrepayCount(HttpServletRequest request, HttpServletResponse response) throws Exception {
Bas_hospitals basHospitals = (Bas_hospitals)request.getSession().getAttribute("login_hospital");
response.setContentType("text/html;charset=utf-8");
PrintWriter pw = response.getWriter();
String hosnum = basHospitals.getHosnum();
String nodecode = basHospitals.getNodecode();
Map<String,String> returnMap = new HashMap();
DBOperator db = new DBOperator();
String startdate = "";
startdate = request.getParameter("chgdateStart");
String enddate = "";
enddate = request.getParameter("chgdateEnd");
String patname = "";
patname = request.getParameter("patname");
String chgman = "";
chgman = request.getParameter("chgman");
String sql = "";
String ptype = "";
ptype = request.getParameter("ptype"); //取出combo的getActualValue()值
try{
sql = "select count(t.prepayid) as count,sum(t.amt) as sum from pat_prepay t join bas_patients p on t.patientid=p.patientid join inp_regist i on t.inpno=i.inpno where t.hosnum=?";
if(startdate!=null&&enddate!=null&&!startdate.equals("")&&!enddate.equals("")){
sql += " and to_char(t.prepaydate,'yyyy-mm-dd')>='"+startdate+"' and to_char(t.prepaydate,'yyyy-mm-dd')<='"+enddate+"'";
}
if(patname!=null&&!patname.equals("")){
patname = URLDecoder.decode(patname, "utf-8"); //取出防止乱码包装的值
sql += " and p.patname like '%"+patname+"%'";
}
if(chgman!=null&&!chgman.equals("")){
chgman = URLDecoder.decode(chgman, "utf-8");
sql += " and t.operator like '%"+chgman+"%'";
}
if(ptype!=null&&"Z".equals(ptype)){ //根据combo的getActualValue()值判断
sql += " and i.out_date is null ";
}
if(ptype!=null&&"C".equals(ptype)){
sql += " and i.out_date is not null ";
}
sql += " order by t.prepaydate desc";
returnMap = (Map<String,String>) db.findOne(sql, new Object[]{hosnum});
pw.print(JSONObject.fromObject(returnMap).toString());
}catch (Exception e) {
e.printStackTrace();
db.rollback();
pw.print("fail");
} finally {
db.freeCon();
pw.flush();
pw.close();
}
}