layui页面跳转,带参数,跳到指定页laypage.render

JS部分

<script>
        var layer, form, laypage, index, newindex, laydate;
        var pageIndex = 1;
        var pageSize = 1;//页大小10
        var total;    //总条数
        var SearchId = "0";
        $(function () {
            layui.use(['layer', 'form', 'laypage', 'laydate'], function () {
                layer = layui.layer;
                form = layui.form;
                laypage = layui.laypage;
                laydate = layui.laydate;

                GetSubjectsList("");
            });

            $("body").on("click", ".AddBtn", function () {
                Add("");
            })
            $("body").on("click", ".editBtn", function () {
                Add($(this).attr("key"));
            })
        });
        Demo
        //layui.use('form', function () {
        //    var form = layui.form;

        //    //监听提交
        //    form.on('submit(formDemo)', function (data) {
        //        var titles = $("#titles").val();//题目
        //        var scores = $("#scores").val();//分值


        //        //layer.msg(JSON.stringify(data.field));
        //        return false;
        //    });
        //});

        function GetSubjectsList(page1) {
            //alert(page1);
            if (page1!="") {
                pageIndex = page1;
            }
            var loadid = layer.load(1, { shade: 0.1 });
            var url = "/YuanGongPingJia/Templates_SubjectsList.aspx?act=GetSubjectsList";
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: { pageIndex: pageIndex, pageSize: pageSize },
                success: function (r) {
                    try {
                        if (r.code > 0) {
                            total = r.RecordCount;  //设置总条数
                            $("#divResult").html(r.result);
                            PageInit(r.PageIndex, r.RecordCount);//调用分页控件
                        }
                        else {
                            layer.msg(r.ErrorMsg, { icon: 5 });
                            layer.close(loadid);
                        }
                    } catch (e) {
                        layer.close(loadid);
                    }
                }, complete: function (r) {
                    layer.close(loadid);
                }
            });
        }


        function PageInit(curr, RecordCount) {
            laypage.render({
                elem: 'page'
                , curr: curr//让起始页,也就是点击的页码
                , groups: 5// 默认的连续出现的页码数
                , limit: pageSize//每页展示条数
                , count: RecordCount//数据总数
                , layout: ['count','prev', 'page', 'next', 'skip']
                , jump: function (obj, first) {
                    if (!first) {
                        pageIndex = obj.curr;
                        GetSubjectsList(obj.curr);//obj.curr输入的要跳转的页码
                    }
                }
            });
            //laypage.render({
            //    elem: 'page'
            //    , curr: curr
            //    , limit: pageSize
            //    , count: RecordCount //数据总数,从服务端得到
            //    , jump: function (obj, first) {
            //        if (!first) {
            //            pageIndex = obj.curr;
            //            GetSubjectsList();
            //        }
            //    }
            //});
        }

        function Add(key) {
            $("#hdwonmanname").val(0);
            var title = "添加题目";
            if (key != "") {
                title = "修改题目";
            }
            index = layer.open({
                title: title,
                type: 2,
                area: ['680px', '680px'],
                btn: ['提交'],
                content: "/YuanGongPingJia/Templates_SubjectsEdit.aspx?key=" + key,
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                },
                yes: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var body = layer.getChildFrame('body', index);
                    save(body);
                    //var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    //alert(index);
                    //parent.layer.close(2);
                },
                cancel: function () {

                    //右上角关闭
                    layer.close(index);
                }

            })
        }

        function save(obj) {
            var titles = $(obj).find("#titles").val();
            var scores = $(obj).find("#scores").val();
            var key = $(obj).find("#key").val();//修改时的主键ID
            var errorMsg = "";

            if (titles == null) {
                errorMsg = "请输入题目";
            }
            if (scores == "") {
                errorMsg = "请输入分值";
            }
            if (errorMsg != "") {
                layer.msg(errorMsg, { time: 1500 });
                return;
            }
            loadIndex = layer.load(0);
            try {
                var url = "/YuanGongPingJia/Templates_SubjectsEdit.aspx?act=SubjectsEdit";
                $.ajax({
                    type: "post",
                    url: url,
                    dataType: "json",
                    data: { titles: titles, scores: scores, key: key },
                    success: function (r) {
                        try {
                            if (r.code > 0) {
                                layer.msg('操作成功', { icon: 6 });
                                layer.close(loadIndex);
                                layer.close(index);
                                GetSubjectsList();
                            }
                            else {
                                layer.msg(r.ErrorMsg, { icon: 5 });
                                layer.close(loadIndex);
                            }
                        } catch (e) {
                            layer.close(loadIndex);
                        }
                    }, complete: function (r) {
                        layer.close(loadIndex);
                    }
                });
                layer.close(loadIndex);
            } catch (e) {
                layer.msg(e.message);
                layer.close(loadIndex);
            }
        }


    </script>

页面部分

<form class="layui-form" action="">
        <div class="layui-inline">
            <a class="layui-btn AddBtn" lay-filter="Search" style="width: 100px;" lay-submit="">添加</a>
        </div>
        <div id="divResult">
        </div>
        <div id="page"></div>
    </form>

页面CS类部分

private void GetSubjectsList()
{
string searchStr = "";

            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]);
            pageIndex = pageIndex == 0 ? 1 : pageIndex;
            pageSize = pageSize == 0 ? 10 : pageSize;
            List<Templates_SubjectsModel> listtemp = Templates_SubjectsBLL.SelectByPage(searchStr, "id", (pageIndex - 1) * pageSize + 1, pageIndex * pageSize);//分页读取记录
}

DAL类

/// <summary>
        /// 根据条件查询分页数据
        /// </summary>
        /// <param name="sqlwhere">查询条件,以and开头</param>
        /// <returns></returns>
        public static List<Templates_SubjectsModel> SelectByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            
            List<Templates_SubjectsModel> list = new List<Templates_SubjectsModel>();

            StringBuilder builder = new StringBuilder();
            builder.Append("SELECT * FROM ( ");
            builder.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                builder.Append("order by T." + orderby);
            }
            else
            {
                builder.Append("order by T.ID desc");
            }
            builder.Append(")AS Row, T.*  from Templates_Subjects T  ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                builder.Append(" WHERE " + strWhere);
            }
            builder.Append("  ) TT");
            builder.AppendFormat(" WHERE TT.Row between {0} and {1}  ", startIndex, endIndex);

            DataTable table = SqlHelper.ExecuteReader(builder.ToString(), CommandType.Text);
            if (table == null || table.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                Templates_SubjectsModel templates_SubjectsModel = null;
                foreach (DataRow row in table.Rows)
                {
                    templates_SubjectsModel = new Templates_SubjectsModel();
                    templates_SubjectsModel.Id = (int)table.Rows[0]["ID"];
                    templates_SubjectsModel.Titles = (string)table.Rows[0]["titles"];
                    templates_SubjectsModel.Scores = (int)table.Rows[0]["scores"];
                    templates_SubjectsModel.AddTime = (DateTime)table.Rows[0]["addTime"];
                    templates_SubjectsModel.IsDel = (int)table.Rows[0]["isDel"];
                    list.Add(templates_SubjectsModel);
                }
                return list;
            }
        }

 

 

posted @ 2020-06-12 14:26  离。  阅读(174)  评论(0编辑  收藏