22 * Инициализируем переменные
33 */
44let currentPage = 1 ;
5+ let lastPage = 1 ;
56let currentObjectId = 0 ;
67let currentDate = 0 ;
78
@@ -30,6 +31,7 @@ $(document).ready(function(){
3031 date . setSeconds ( 0 ) ;
3132
3233 currentDate = parseInt ( date . getTime ( ) / 1000 ) ;
34+ currentPage = 1 ;
3335 loadData ( ) ;
3436 }
3537 } ) ;
@@ -41,6 +43,7 @@ $(document).ready(function(){
4143 // Устанавливаем текст выбранного города
4244 loadCity ( ) ;
4345 // Перезагружаем данные
46+ currentPage = 1 ;
4447 loadData ( ) ;
4548 } ) ;
4649
@@ -75,6 +78,7 @@ $(document).ready(function(){
7578 } ) ;
7679
7780 setCookie ( 'guru_selected_types' , types . join ( ',' ) ) ;
81+ currentPage = 1 ;
7882 loadData ( ) ;
7983 } ) ;
8084
@@ -109,28 +113,50 @@ $(document).ready(function(){
109113 loadSessions ( ) ;
110114 } ) ;
111115
116+ /**
117+ * Метод загрузки данных при смене страницы
118+ */
119+ $ ( '.js-load-next-page' ) . on ( 'click' , function ( e ) {
120+ e . preventDefault ( ) ;
121+
122+ currentPage += 1 ;
123+ loadData ( true ) ;
124+ } ) ;
112125} ) ;
113126
114127/**
115128 * Метод загрузки данных при событии
116129 */
117- function loadData ( ) {
130+ function loadData ( isSave ) {
118131 $ . ajax ( {
119132 url : $config . server + $config . prefix + "/sellers/performance/distibution" ,
120133 data : {
121134 lang : $config . language ,
122135 cityId : getCookie ( 'guru_selected_city_id' ) ,
123136 typeIds : getCookie ( 'guru_selected_types' ) ,
124137 date : currentDate ,
138+ page : currentPage ,
125139 'per-page' : $config . perPage
126140 } ,
127141 success : function ( data ) {
128142 // Чистим блок с карточками мероприятий
129- $ ( '.events-block' ) . html ( '' ) ;
143+ if ( ! isSave ) {
144+ $ ( '.events-block' ) . html ( '' ) ;
145+ }
130146
131147 if ( data && data . data && data . data . length ) {
132148 $ ( '.js-no-result' ) . addClass ( 'd-none' ) ;
133149
150+ if ( data . pagination ) {
151+ lastPage = data . pagination . pageCount ;
152+
153+ if ( lastPage > currentPage ) {
154+ $ ( '.js-load-next-page' ) . show ( ) ;
155+ } else {
156+ $ ( '.js-load-next-page' ) . hide ( ) ;
157+ }
158+ }
159+
134160 data . data . forEach ( function ( event ) {
135161 let el = $ ( '#js-event-poster-template .event-poster' ) . clone ( ) ;
136162
0 commit comments