123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <template>
- <section class="catalog section">
- <div class="catalog__wrapper section-wrapper">
- <div class="catalog__container">
- <CatalogMenu />
- <main class="catalog__main">
- <div class="catalog-main">
- <div class="catalog-main__wrapper">
- <div class="catalog-main__topic">
- <ul class="catalog-main__topic-list">
- <li class="catalog-main__topic-item">
- <a
- class="catalog-main__topic-link"
- href="javascript:void(0)"
- >Новости</a
- >
- </li>
- <li class="catalog-main__topic-item">
- <nuxt-link
- :to="{
- name: 'news-category',
- params: {
- category: categoryNewsList.category
- ? categoryNewsList.category.alias
- : '',
- },
- }"
- class="catalog-main__topic-link"
- href="javascript:void(0)"
- >
- Поиск</nuxt-link
- >
- </li>
- </ul>
- </div>
- <div class="catalog-main__header">
- <h1>Поиск</h1>
- </div>
- <div class="catalog-main__list">
- <div class="catalog-list" id="catalogList">
- <BaseInput
- class="search__input"
- v-model="string"
- @input="searchTrigger"
- ></BaseInput>
- <li class="catalog-list__item" v-for="searchItem in searchList" :key="searchItem.id">
- <div class="catalog-item">
- <nuxt-link
- :to="{
- name: 'news-category-alias',
- params: {
- category: searchItem.category.alias,
- alias: searchItem.alias,
- },
- }"
- class="catalog-item__link"
- >
- <main class="catalog-item__main">
- <div class="catalog-item__main-top">
- <div class="catalog-item__main-title" v-html="searchItem.title"></div>
- </div>
- <div class="catalog-item__main-bottom">
- <div class="catalog-item__main-info">
- <div class="catalog-item__main-info-element">
- {{ searchItem.start_activity ? convertDate(searchItem.start_activity) : ''}}
- </div>
- </div>
- </div>
- </main></nuxt-link>
- </div>
- </li>
- </div>
- </div>
- <Pagination
- v-if="searchList.length"
- v-model="curPage"
- :length="paginationLength"
- @input="nextPage"
- :visible="10"
- ></Pagination>
- </div>
- </div>
- </main>
- </div>
- </div>
- </section>
- </template>
- <script>
- import { mapGetters } from "vuex";
- let delayTimer;
- export default {
- props: {
- query: {
- type: String
- }
- },
- data() {
- return {
- string: "",
- searchList: [],
- curPage: 1,
- totalPages: null
- };
- },
- computed: {
- ...mapGetters({
- categoryNewsList: "modules/news/categoryNewsList",
- }),
- paginationLength() {
- if(this.curPage < 10) return 10;
- return this.curPage + 5;
- }
- },
- props: {
- category: {
- type: Object,
- },
- },
- mounted() {
- this.string = this.$route.params.query
- this.searchTrigger()
- },
- methods: {
- nextPage() {
- this.searchTrigger();
- this.scrollTop();
- },
- scrollTop() {
- const element = document.getElementById("catalogList");
- const top = element.offsetTop;
- window.scrollTo(0, top - 230);
- },
- searchTrigger() {
- clearTimeout(delayTimer);
- delayTimer = setTimeout(() => {
- this.$axios
- .post("search", {
- request: this.string,
- page: this.curPage
- })
- .then((res) => {
- if (res.status == 200) {
- const { items, total_pages } = res.data.data;
- this.searchList = items;
- this.totalPages = total_pages;
- }
- });
- }, 600);
- },
- convertDate(dateTampstamp) {
- const date = new Date(dateTampstamp * 1000);
- const dateString =
- date.toLocaleString("ru", {
- day: 'numeric',
- month: 'long'
- }) +
- " " +
- date.getFullYear()
- + ", " +
- ("0" + date.getHours()).slice(-2) +
- ":" +
- ("0" + date.getMinutes()).slice(-2);
- return dateString;
- },
- },
- async fetch({ store, route }) {
- await store.dispatch("modules/news/setCategoriesList");
- },
- async asyncData({ store }) {
- await store.dispatch("modules/ads/getAds");
- },
- head() {
- return {
- title: 'Поиск по сайту — Амик.ру'
- }
- }
- };
- </script>
- <style lang="less" scoped>
- .catalog-list{
- list-style: none;
- &__item{
- }
- }
- .search {
- &__input {
- width: 100%;
- max-width: 100%;
- height: 41px;
- display: flex;
- align-items: center;
- margin-bottom: 20px;
- input {
- width: 100%;
- outline: none;
- height: 100%;
- }
- }
- }
- </style>
|