• 源码分页搜索公用


    //前台ajax
    //下一页
    $(document).on('click','.p', function () {
    var start = $(".start").val();
    if(start==''){
    start='';
    }
    var end = $(".end").val();
    if(end==''){
    end='';
    }
    p = $(this).attr('val');
    var str="";
    $.ajax({
    type: "GET",
    url: "<?php echo Yii::$app->urlManager->createUrl('yuyue/yulist')?>",
    data: {page:p,start:start,end:end},
    dataType : "json",//数据类型为jsonp
    success: function(msg){
    str+="<table border='1' id='box'>"+
    "<th>预约号</th><th>预约人</th><th>预约时间</th><th>预约座位</th><th>预约电影</th>";
    for(var i in msg['data']){
    str+="<tr><td><input type='hidden' name='eid' value="+msg['data'][i]['id']+" />"+msg['data'][i]['code']+"</td><td>"+msg['data'][i]['username']+"</td><td>"+msg['data'][i]['begintime']+"</td> <td>"+msg['data'][i]['zuowei']+"</td><td>"+msg['data'][i]['move']+"</td></tr>";
    }
    $("#box").html(str);
    $(".page_").html(msg['str']);
    $(".start").html(msg['start']);
    $(".end").html(msg['end']);
    }
    });
    });
    //搜索
    $(".but").click(function () {
    var p=1;
    var start = $(".start").val();
    if(start==''){
    start='';
    }
    var end = $(".end").val();
    if(end==''){
    end='';
    }
    var str="";
    $.ajax({
    type: "GET",
    url: "<?php echo Yii::$app->urlManager->createUrl('yuyue/yulist')?>",
    data: {start:start,end:end,page:p},
    dataType : "json",//数据类型为jsonp
    success: function(msg){
    str+="<table border='1' id='box'>"+
    "<th>预约号</th><th>预约人</th><th>预约时间</th><th>预约座位</th><th>预约电影</th>";
    for(var i in msg['data']){//for(var i=0;i<msg.length;i++) {
    str+="<tr><td><input type='hidden' name='eid' value="+msg['data'][i]['id']+" />"+msg['data'][i]['code']+"</td><td>"+msg['data'][i]['username']+"</td><td>"+msg['data'][i]['begintime']+"</td> <td>"+msg['data'][i]['zuowei']+"</td><td>"+msg['data'][i]['move']+"</td></tr>";
    }
    $("#box").html(str);
    $(".page_").html(msg['str']);
    $(".start").html(msg['start']);
    $(".end").html(msg['end']);
    }
    });
    });

    //控制器
    public function actionYulist(){
    $start = yii::$app->request->get('start');//接收要搜索的数据
    $end = yii::$app->request->get('end');//接收要搜索的数据
    $where = "1=1";//拼接条件
    if(!empty($start)&&!empty($end)){//拼接条件
    $where .= " and `begintime`>='$start' and `begintime`<='$end'";
    }
    if(!empty($start)){//拼接条件
    $where .= " and `begintime`>='$start'";
    }
    if(!empty($end)){//拼接条件
    $where .= " and `endtime`<='$end'";
    }

    $yuList = yii::$app->db->createCommand("select m.id,code,username,begintime,zuowei,move from yuyue as m inner join dingdan as o on m.uid=o.uid where $where")->queryAll();
    $count = count($yuList);//取整
    $pagesize = 2;//每页显示条数
    $pagesum=ceil($count/$pagesize);//向上取整
    $page=isset($_GET['page'])?$_GET['page']:1;//页数的取值
    $start=($page-1)*$pagesize;//数据的偏移量
    $data['data'] = yii::$app->db->createCommand("select m.id,code,username,begintime,zuowei,move from yuyue as m inner join dingdan as o on m.uid=o.uid where $where limit $start,$pagesize")->queryAll();//查询数据
    $data['start'] = $start;
    $data['end'] = $end;
    $pre=$page-1 < 1 ? 1 : $page-1;//上一页
    $next = $page+1>$pagesum ? $pagesum:$page+1;//下一页
    $data['str']="<a href='javascript:;' class='p' val='1'>首页</a>&nbsp;&nbsp;<a href='javascript:;' val=".$pre." class='p'>上一页</a>&nbsp;&nbsp;<a href='javascript:;' val=".$next." class='p'>下一页</a>";//页数
    if(yii::$app->request->isAjax){
    echo json_encode($data);
    }else{
    return $this->render('listPage',['str'=>$data['str'],'data'=>$data['data']]);
    }
    }

    $(document).on('change','#channelfather',function () {
    var channelval=$('#channelfather').val();
    $.ajax({
    type: "POST",
    url: "/stat/channelson",
    data: "channelint="+channelval,
    dataType: 'json',
    success: function(msg){
    if(msg==''){
    var channeldata='<select class="form-control" id="channelson" name="channelson" size="1"><option value="">无子渠道</option></select>';
    }
    else{
    // var channeldata='<select class="form-control" id="channelson" name="channelson" size="1"><option value="">请选择子渠道</option>';
    // for(var i=0;i<msg.length;i++) {
    // channeldata+='<option value="'+msg[i].cid+'">'+msg[i].promote_name+'</option>';
    // }
    // channeldata+='</select>';
    channeldata=sonchannel(msg);

    }
    $('#channelson').html(channeldata);
    }
    });
    });
    function sonchannel(msg) {

    var channeldata='<select class="form-control" id="channelson" name="channelson" size="1"><option value="">请选择子渠道</option>';
    for(var i=0;i<msg.length;i++) {
    channeldata+='<option value="'+msg[i].cid+'">'+msg[i].promote_name+'</option>';
    }
    channeldata+='</select>';
    return channeldata;
    }
  • 相关阅读:
    不用写代码的框架
    bat执行python脚本,执行多条命令
    VMware-workstation-full-15.1.0-13591040安装破解-附件密钥
    w10谷歌chrome关闭自动更新
    谷歌安装提示已经安装高版本解决
    python项目三方库导出导入 requirements.txt文件
    点阴影
    goto gamedev blog
    20135315-信息安全系统设计基础第五周学习总结
    win10 +python3.6环境下安装opencv以及pycharm导入cv2有问题的解决办法
  • 原文地址:https://www.cnblogs.com/zhanghuilong/p/6481023.html
Copyright © 2020-2023  润新知