index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <section class="catalog section">
  3. <div class="catalog__wrapper section-wrapper">
  4. <div class="catalog__container">
  5. <CatalogMenu />
  6. <main class="catalog__main">
  7. <div class="catalog-main">
  8. <div class="catalog-main__wrapper">
  9. <div class="catalog-main__topic">
  10. <ul class="catalog-main__topic-list">
  11. <li class="catalog-main__topic-item">
  12. <nuxt-link
  13. to="/news"
  14. class="catalog-main__topic-link">
  15. Новости
  16. </nuxt-link>
  17. </li>
  18. <li
  19. class="catalog-main__topic-item"
  20. v-for="category in breadcrumbs"
  21. :key="category.alias"
  22. >
  23. <nuxt-link
  24. :to="{
  25. name: 'news-category',
  26. params: {
  27. category: category.alias,
  28. },
  29. }"
  30. class="catalog-main__topic-link"
  31. href="javascript:void(0)"
  32. >{{ category.name }}</nuxt-link
  33. >
  34. </li>
  35. </ul>
  36. </div>
  37. <div class="catalog-main__header">
  38. <h1>
  39. {{
  40. categoryNewsList.category
  41. ? categoryNewsList.category.name
  42. : "Новости"
  43. }}
  44. </h1>
  45. <div
  46. class="catalog-main__filter"
  47. @click="$modal.show('filter-modal')"
  48. >
  49. <BaseIcon name="filter"></BaseIcon>
  50. </div>
  51. <!-- <a
  52. class="
  53. catalog-main__subscribe
  54. button button_grey-dark button_grey-dark-short
  55. "
  56. ><span class="button__text">Подписаться</span></a
  57. > -->
  58. </div>
  59. <div class="catalog-main__list">
  60. <div class="catalog-list">
  61. <CatalogList
  62. :categoryNewsList="categoryNewsList.news"
  63. :pages="categoryNewsList.total_pages"
  64. @loadMore="onLoadMore"
  65. />
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </main>
  71. </div>
  72. </div>
  73. <CatalogFilter @apply="onApplyFilter" :filter="filter"></CatalogFilter>
  74. </section>
  75. </template>
  76. <script>
  77. import { mapGetters } from "vuex";
  78. export default {
  79. watchQuery: ["pagination", "date_start", "date_end"],
  80. data: () => ({
  81. filter: {
  82. activity: [],
  83. },
  84. }),
  85. computed: {
  86. ...mapGetters({
  87. newsItem: "modules/news/newsItem",
  88. categoryNewsList: "modules/news/categoryNewsList",
  89. }),
  90. breadcrumbs() {
  91. let current = this.categoryNewsList.category;
  92. if(!current) return [];
  93. const categories = [current];
  94. while (current.parent) {
  95. current = current.parent;
  96. categories.push(current);
  97. }
  98. return categories.reverse();
  99. },
  100. },
  101. props: {
  102. category: {
  103. type: Object,
  104. },
  105. },
  106. head() {
  107. return {
  108. title:
  109. "Амик - " +
  110. (this.categoryNewsList.category
  111. ? this.categoryNewsList.category.name
  112. : " "),
  113. meta: [
  114. {
  115. name: "description",
  116. content: this.categoryNewsList.category
  117. ? this.categoryNewsList.category.meta.description
  118. : "",
  119. },
  120. {
  121. name: "keys",
  122. content: this.categoryNewsList.category
  123. ? this.categoryNewsList.category.meta.key
  124. : "",
  125. },
  126. ],
  127. link: [
  128. {rel: 'canonical', href: this.categoryNewsList.category ? 'https://www.amic.ru/news/' + this.categoryNewsList.category.alias : ''}
  129. ]
  130. };
  131. },
  132. methods: {
  133. onApplyFilter() {
  134. const [date_start = "", date_end = ""] = this.filter.activity;
  135. this.$router.push({
  136. name: this.$route.name,
  137. query: { pagination: 1, date_start, date_end },
  138. });
  139. this.$modal.hide("filter-modal");
  140. },
  141. async onLoadMore(loadMoreCounter) {
  142. await this.$store.dispatch("modules/news/loadCategoryNews", {
  143. category: this.$route.params.category,
  144. pagination: loadMoreCounter,
  145. filter: {
  146. date_start: this.$route.query.date_start || null,
  147. date_end: this.$route.query.date_end || null,
  148. },
  149. });
  150. },
  151. },
  152. async fetch({ store, route }) {
  153. await store.dispatch("modules/news/setCategoryNewsList", {
  154. category: route.params.category,
  155. pagination: route.query.pagination || 1,
  156. filter: {
  157. date_start: route.query.date_start || null,
  158. date_end: route.query.date_end || null,
  159. },
  160. });
  161. await store.dispatch("modules/news/setCategoriesList");
  162. },
  163. };
  164. </script>
  165. <style lang="less">
  166. @media screen and (max-width: 900px) {
  167. .detail {
  168. &__wrapper {
  169. flex-direction: column-reverse;
  170. }
  171. &__side {
  172. margin-bottom: 20px;
  173. display: none;
  174. }
  175. }
  176. .detail-top {
  177. &__header {
  178. display: block;
  179. }
  180. &__footer {
  181. display: block;
  182. }
  183. &__footer-side {
  184. display: flex;
  185. margin-top: 20px;
  186. }
  187. }
  188. }
  189. </style>