输入框搜索功能的实现

先写输入框:

<label class="col-md-1 control-label" for="txtRDKeyWord">关键字</label>
    <div class="col-md-9">
        <input type="text" id="txtRDKeyWord" class="form-control" autocomplete="off" placeholder="请输入病历号/门诊号关键字"/>
    </div>
    <div class="col-sm-2">
        <button id="btnRDSearch" class="btn btn-block btn-pink">搜索</button>
    </div>

按钮触发事件及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 = $('<div><i class="fa fa-spinner fa-spin loading" style="font-size:24px;"></i><span style="font-size:16px;"> 加载中,请稍候...</span></div>');
            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<Object[]> arrParameter = new ArrayList<Object[]>();
            // 设置搜索条件
            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<Object[]> arrParameter = new ArrayList<Object[]>();
            // 设置排序和是否删除的默认值
            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;
    }

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,772评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,458评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,610评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,640评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,657评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,590评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,962评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,631评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,870评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,611评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,704评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,386评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,969评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,944评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,179评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,742评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,440评论 2 342

推荐阅读更多精彩内容