懒人加载,点击加载更多

//js  
 //点击加载更多
    var page = 1;
    $(".load_more").on('click',function (){
        var thisID = $('.layui-this').attr("lay-id");
        setTimeout(function () {
                page++;
                $.ajax({
                    url: "/user/server/client_uid",
                    data: { client_uid: thisID, page: page,type:1},
                    success: function (data) {
                        var data = JSON.parse(data);
                        layui.each(data, function(index, item){
                            if(item.type==2){
                                $(".c_boom").prepend('
' + '' + ' ' + item.speaker + '' + '' + item.chatdate + '' + '
' + '
'); }else{ $(".c_boom").prepend('
' + '' + ' ' + item.speaker + '' + '' + item.chatdate + '' + '
' + item.speech + '
' + '
'); } }); } }) }, 300); }) //后台接收 public function client_uidOp() { $type = input('type'); $limit = input('limit',20); $status = input('status'); $client_uid = input('client_uid'); if(!$client_uid){ return false; } //将游客uid存入session session('s_to_c_uid',$client_uid); $server_uid = session('server_uid'); $date = strtotime("-1 day"); //客服对游客说的话 $data = model('chat')->whereOr(['listener'=>$client_uid , 'speaker'=>$client_uid])->where(['chatdate'=>['>',$date]])->order('chatdate desc')->paginate($limit, false, [ 'query' => request()->param(), ])->toArray(); $stoc=$data['data']; if($type != 1){ array_multisort(array_column($stoc,'chatdate'),SORT_ASC,$stoc); } //客服的 username $servername = model('server')->where(['uid'=>$server_uid])->value('username'); //客服头像信息 $img = $this->imgBase64(USER_HEAD_PATH.$this->img_path($server_uid)); if($status == ''){ //游客头像 $data = model('client')->where(['uid'=>$client_uid])->column('username,img'); $imgs= ''; foreach($data as $k => $v) { $imgs = $v; $clientname = $k ; } if ($imgs) { $imgs = $this->imgBase64(USER_HEAD_PATH.$imgs); } else { $imgs = model('conf')->where(['sysmark'=>'tourists_head'])->value('image'); } }else { $clientname = model('server')->where(['uid'=>$client_uid])->value('username'); //客服头像信息 $imgs = $this->imgBase64(USER_HEAD_PATH.$this->img_path($client_uid)); } //speaker 从 uid 改为 usernamer foreach($stoc as $key => $row) { if($stoc[$key]['speaker'] == $client_uid) { $stoc[$key]['speaker'] = $clientname; $stoc[$key]['img'] = $imgs; }else{ $stoc[$key]['speaker'] = $servername; $stoc[$key]['img'] = $img; } $stoc[$key]['type'] = $row['type']; if ($row['type'] == 2) { $stoc[$key]['speech'] = $this->imgBase64(UPLOADS_PATH.$row['speech']); } $stoc[$key]['chatdate'] = date('Y-m-d H:i:s', $row['chatdate']); } return json_encode($stoc); }

 

你可能感兴趣的:(懒人加载,点击加载更多)