输入框搜索功能的实现

先写输入框:


    

按钮触发事件及function方法(window.open为打开新的页面具体页面后续):

$("#btnRDSearch").click(reserveDetail.loadReserve);

//搜索关键字
reserveDetail.loadReserve = function(){
    var sUrl = "reserveAction_loadReserve";
    var objParams = { "hasLoading": false, "cvoParameter.keyWord": $("#txtRDKeyWord").val()};
        commonJs.openAjax(sUrl, objParams,function(data){
            if (!data.success) {
                commonJs.openDialog("error", data.message);
            } else {
                var lstResult = data.lstResult;
                if (typeof(lstResult) =="undefined") {
                    commonJs.openDialog("error", "无查询结果请重新输入!");
                } else {
                    if (lstResult.length == 1) {
                        var sId = lstResult[0].id;
                        var sMrn = lstResult[0].medicalRecordNumber;
                        var sCn = lstResult[0].clinicNumber;
                        var sOrderId = lstResult[0].orderId;
                        var sTargetId = lstResult[0].targetId;
                        window.open(BASE_PATH + "/spv2/nurse/reserve/reserve_detail.jsp?id="+sId+"&mrn="+sMrn+"&cn="+sCn+"&oid="+sOrderId+"&tid="+sTargetId);
                    } else if (lstResult.length > 1){
                        commonJs.openDialog("warning","查询数据条数为"+lstResult.length+",请重新输入!");
                        return;
                    }
                }
            }
        });
}

在commonJs中已经封装好openAjax、openDialog方法了:

//打开ajax请求(请求地址, 参数, 成功后回调的函数, 失败后回调的函数)
commonJs.openAjax = function(sUrl, vParams, funSuccess, funError) {
    if (sUrl == null || sUrl == '') return false;
    // 默认显示加载层,如果不需要,请设置vParams.hasLoading为false
    var hasLoading = true;
    if (vParams != null && vParams.hasLoading == false) { hasLoading = false; }
    if (hasLoading) { commonJs.openLoadDialog(); }
    $.ajax({
        url:        sUrl,
        data:       vParams,
        type:       'POST',
        dataType:   'json',// xml,html,script,json,jsonp
        timeout:    30 * 60 * 1000,
        success:    function(data) {
            if (hasLoading) { commonJs.closeLoadDialog(); }
            if (data != null && data.code == "login"){
                commonJs.openDialog("error", data.message, function(){
                    location.href = BASE_PATH + "/spv2/login.jsp?returnUrl=" + commonJs.enReturnUrl();
                });
            }else{
                funSuccess(data);
            }
        },
        error:      funError
    });
};

// 打开页面对话框
commonJs.openPageDialog = function(par) {
    if (par != null && par.closable == null) { par.closable = false; }
    if (par != null && par.lg != null && par.lg == true) {
        par.lg = BootstrapDialog.SIZE_WIDE;
    } else {
        par.lg = BootstrapDialog.SIZE_NORMAL;
    }
    var dialog = new BootstrapDialog({
        id:     par.id,// 窗口id
        title:  par.title,// 标题
        size:   par.lg,// 是否大窗口
        closable: par.closable,// 是否可关闭(默认为不关闭)
        closeByKeyboard: par.closable,// 是否可用Esc关闭窗口(与closable一致)
        message: function(dialog) {
            var $message = $('
 加载中,请稍候...
'); setTimeout(function() { if (par.url == null || par.url == '') return; if (par.url.indexOf('?') > -1) { // par.url += '&ran=' + Math.random(); } else { // par.url += '?ran=' + Math.random(); } $message.load(par.url, par.data, function() { }); }, 500); return $message; }, buttons: par.buttons }).open(); return dialog; }

编写action方法:

    IReserve funReserve = FunFactory.getReserve();
    /**
     * 加载预约就诊客户
     * @return
     */
    @IAccess(competenceNumber = { GlobalCache.UserRole.SPD }, returnFormat = GlobalCache.JSON)
    public void loadReserve() {
        MessageVo mvoResult = new MessageVo();
        CommonVo cvoParams = getCvoParameter();
        if ("".equals(cvoParams.getKeyWord()) || cvoParams.getKeyWord() == null) {
            mvoResult.setSuccess(false);
            mvoResult.setMessage("输入关键字不能为空!");
        } else {
            mvoResult = funReserve.pageListReserve(cvoParams);
        }
        this.outJson(mvoResult);
    }

commonVo为公共值对象,MessageVo 为返回值对象,立面包含你所要传输的值对象。
funReserve 为FunFactory的获取对象。
pageListReserve方法为:

/**
     * 获取预约确认列表
     */
    public MessageVo pageListReserve(CommonVo cvoParams) {
        String sSql = "";
        cvoParams.setIsPay("1");// 已付款
        sSql += CommonBean.getRangeCondition(cvoParams.getRange(), "reserve_date", "4");
        if (!"".equals(cvoParams.getKeyWord()) && cvoParams.getKeyWord() != null) {
            sSql += " and (CLINIC_NUMBER LIKE '%" + cvoParams.getKeyWord() + "%' OR MEDICAL_RECORD_NUMBER LIKE '%" + cvoParams.getKeyWord() + "%' OR TARGET_NAME LIKE '%" + cvoParams.getKeyWord()
                    + "%')";
            sSql += " and (DOCTOR_ID = '" + cvoParams.getDoctorId() + "' OR DOCTOR_ID IS NULL)";
        }
        cvoParams.setSql(sSql);
        cvoParams.setOrderBy("order by DOCTOR_ID,RESERVE_DATE,QUEUE_ID");
        return tdoReserveOrder.getList(cvoParams);
    }

封装好的dao包(尽量不要修改这文件):

@Repository("VReserveOrderViewDao")
public class VReserveOrderViewDao extends DaoSupport implements IViewDao {
    private static String TABLE_NAME = "VReserveOrder";

    public MessageVo getList(CommonVo cvoSelect) {
        String sHql = "from " + TABLE_NAME + " where 1=1 ";// 查询语句
        String sCount = "select count(*) from " + TABLE_NAME + " where 1=1 ";// 分页语句
        MessageVo mvoResult = new MessageVo();
        try {
            Object[] objParameter = null;
            ArrayList arrParameter = new ArrayList();
            // 设置搜索条件
            objParameter = new Object[] { " and id = ? ", cvoSelect.getId() };
            arrParameter.add(objParameter);// 编号
            objParameter = new Object[] { " and order_number like ? ", "%" + cvoSelect.getOrderNumber() + "%" };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and medical_record_number like ? ", "%" + cvoSelect.getMedicalRecordNumber() + "%" };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and target_id = ? ", cvoSelect.getTargetId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and customer_id = ? ", cvoSelect.getCustomerId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and target_name like ? ", "%" + cvoSelect.getTargetName() + "%" };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and room_id = ? ", cvoSelect.getRoomId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and room_name like ? ", "%" + cvoSelect.getRoomName() + "%" };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and doctor_name like ? ", "%" + cvoSelect.getDoctorName() + "%" };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and reserve_type = ? ", cvoSelect.getReserveType() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and order_status = ? ", cvoSelect.getOrderStatus() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and evaluate_status = ? ", cvoSelect.getEvaluateStatus() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and is_pay = ? ", cvoSelect.getIsPay() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and reserve_mode = ? ", cvoSelect.getReserveMode() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and create_time >= ? ", cvoSelect.getBeginTime() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and create_time <= ? ", cvoSelect.getEndTime() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and sp_id = ? ", cvoSelect.getSpId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and service_mode = ? ", cvoSelect.getServiceMode() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and is_book_time = ? ", cvoSelect.getIsBookTime() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and is_deduct = ? ", cvoSelect.getIsDeduct() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and clinic_type = ? ", cvoSelect.getClinicType() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and create_name like ? ", "%" + cvoSelect.getCreateName() + "%" };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and is_delete = ? ", cvoSelect.getIsDelete() };
            arrParameter.add(objParameter);// 是否已删除

            // 将参数传入到分页Bean中
            String[] sHqlArr = { sHql, sCount, cvoSelect.getSql(), cvoSelect.getOrderBy() };
            int[] iInfoArr = { cvoSelect.getPageNum(), cvoSelect.getLimitNum(), cvoSelect.getForUpdateWait() };
            SpringPageBean spbQuery = new SpringPageBean(sHqlArr, iInfoArr, arrParameter, getCustomSession());;
            List lstResult = (List) getHibernateTemplate().execute(spbQuery);
            mvoResult.setSuccess(true);
            mvoResult.setLstResult(lstResult);
            mvoResult.setTotalPage(spbQuery.getTotalPage());
            mvoResult.setTotalSize(spbQuery.getTotalNum());
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 返回搜索结果
        return mvoResult;
    }

    public CommonVo getOne(CommonVo cvoSelect) {
        String sHql = "from " + TABLE_NAME + " where 1=1 ";// 查询语句
        CommonVo cvoResult = null;
        try {
            Object[] objParameter = null;
            ArrayList arrParameter = new ArrayList();
            // 设置排序和是否删除的默认值
            if (cvoSelect.getOrderBy() == null || "".equals(cvoSelect.getOrderBy())) {
                cvoSelect.setOrderBy(" order by id desc");
            }
            // 设置搜索条件
            objParameter = new Object[] { " and id = ? ", cvoSelect.getId() };
            arrParameter.add(objParameter);// 编号
            objParameter = new Object[] { " and order_number = ? ", cvoSelect.getOrderNumber() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and medical_record_number = ? ", cvoSelect.getMedicalRecordNumber() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and target_id = ? ", cvoSelect.getTargetId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and room_id = ? ", cvoSelect.getRoomId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and sp_id = ? ", cvoSelect.getSpId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and doctor_id = ? ", cvoSelect.getDoctorId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and doctor_name like ? ", "%" + cvoSelect.getDoctorName() + "%" };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and reserve_type = ? ", cvoSelect.getReserveType() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and order_status = ? ", cvoSelect.getOrderStatus() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and customer_id = ? ", cvoSelect.getCustomerId() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and service_mode = ? ", cvoSelect.getServiceMode() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and clinic_type = ? ", cvoSelect.getClinicType() };
            arrParameter.add(objParameter);//
            objParameter = new Object[] { " and is_delete = ? ", cvoSelect.getIsDelete() };
            arrParameter.add(objParameter);// 是否已删除
            // 将参数传入到分页Bean中
            String[] sHqlArr = { sHql, null, cvoSelect.getSql(), cvoSelect.getOrderBy() };
            int[] iInfoArr = { 1, 1 };
            SpringPageBean spbQuery = new SpringPageBean(sHqlArr, iInfoArr, arrParameter, getCustomSession());;
            // 搜索数据
            List lstResult = (List) getHibernateTemplate().execute(spbQuery);
            if (lstResult != null && lstResult.size() > 0) {
                cvoResult = (CommonVo) lstResult.get(0);
                getHibernateTemplate().evict(cvoResult);// 分离对象
                lstResult.clear();
            }
            // 清空参数
            lstResult = null;
            arrParameter.clear();
            arrParameter = null;
            objParameter = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 返回搜索结果
        return cvoResult;
    }

}

你可能感兴趣的:(输入框搜索功能的实现)