Advertisement
GAsdeX

Untitled

Mar 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 16.83 KB | None | 0 0
  1. <template>
  2.     <div class="wContainer">
  3.         <catalog-breadcrumbs></catalog-breadcrumbs>
  4.         <div class="innerContainer size">
  5.             <div class="row">
  6.                 <!--catalog filters-->
  7.                 <div class="col-xs-3">
  8.                     <!--for instruments-->
  9.                     <div class="sidebarFilters">
  10.                         <div class="sidebarFilters__wrapper" v-if="sidebarFilters">
  11.                             <div class="sideFilterBlock" v-for="filterItem in sidebarFilters">
  12.                                 <catalog-checkboxes-component :key="selectedFiltersNumber"
  13.                                                               :is="filterItem.component"
  14.                                                               :slug="filterItem.slug"
  15.                                                               :name="filterItem.name"
  16.                                                               :filters="filterItem.data"
  17.                                                               :parameteres = "catalogFilters"
  18.                                                               @setFilters="setCatalogFilters($event)"/>
  19.                                
  20.                                 <catalog-range v-if="filterItem.data"
  21.                                                :is="filterItem.component"
  22.                                                :max="filterItem.data.max"
  23.                                                :min="filterItem.data.min"
  24.                                
  25.                                                @filter="priceAmount = $event"/>
  26.                             </div>
  27.                         </div>
  28.                         <div class="sidebarFilters__clear" @click="resetFilter"><span class="js-resetAll">Сбросить фильтр</span></div>
  29.                     </div>
  30.                    
  31.                     <!--for breaks -->
  32.                 </div>
  33.                
  34.                 <!--catalog view-->
  35.                 <div class="col-xs-9">
  36.                     <div class="categoryBlock">
  37.                         <div class="categoryBlock__titleLine">
  38.                             <h1 v-if="category == 'tire'" class="mainContentTitle">Легковые шины</h1>
  39.                             <h1 v-if="category == 'discs'" class="mainContentTitle">Диски</h1>
  40.                             <h1 v-if="category == 'brake'" class="mainContentTitle">Тормозная система</h1>
  41.                             <h1 v-if="category == 'instruments'" class="mainContentTitle">Наборы инструментов</h1>
  42.                             <div class="categoryBlock__sort">
  43.                                 <label>Сортировать</label>
  44.                                 <select-component :title="'Сортировать'" :options="['по стоимости', '215 / 65/ R17 V', '225 / 55/ R17 V']"></select-component>
  45.                                
  46.                             </div>
  47.                         </div>
  48.                        
  49.                         <div class="categoryBlock__list row" v-if="getCargoPerPage">
  50.                             <div class="col-xs-4" v-for="item in getCargoPerPage">
  51.                                 <catalog-card :cat="category" :description="item" :key="item['Product ID']"></catalog-card>
  52.                             </div>
  53.                         </div>
  54.                         <div class="pagination" v-if="catalog && pages">
  55.                             <paginator v-if="pages.length > 1" @pagination="page = $event" :page="page" :amount="pages" :key="pages.length"></paginator>
  56.                         </div>
  57.                         <div class="info-box info green" v-if="getCargoPerPage.length == 0 && sidebarFilters">
  58.                             <p>По заданой фильтрации, список пуст.</p>
  59.                         </div>
  60.                        
  61.                     </div>
  62.                 </div>
  63.             </div>
  64.         </div>
  65.         <div class="favoritePage">
  66.             <div class="favoritePage__inner">
  67.                 <div class="favoritePage__topLine">
  68.                     <h1 class="mainContentTitle">Просмотренные товары</h1>
  69.                 </div>
  70.                 <div class="favoritePage__list" v-if="visitedProducts">
  71.                     <!--Temp solution-->
  72.                     <div class="col-xs-3" v-for="item in visitedProducts">
  73.                         <catalog-card :cat="category" :description="item" :key="item.product_id"></catalog-card>
  74.                     </div>
  75.                    
  76.                     <!--flexbox fix add this blocks =(countItemsInRow - 1)-->
  77.                     <div class="sellItem hidden"></div>
  78.                     <div class="sellItem hidden"></div>
  79.                     <div class="sellItem hidden"></div>
  80.                 </div>
  81.             </div>
  82.         </div>
  83.         <!-- .wConteiner -->
  84.     </div>
  85. </template>
  86.  
  87. <script>
  88.     var CheckboxFilter = require('../components/catalog-checkboxes-component.vue');
  89.     var RangeFilter    = require('../components/catalog-range.vue');
  90.    
  91.     module.exports = {
  92.         data: function(){
  93.             return {
  94.                 page: 1,
  95.                 priceAmount: false,
  96.                 isFiltering: false,
  97.                 catalogFilters : {},
  98.                 selectedFiltersNumber: false
  99.             }
  100.         },
  101.         // Do not like this solution. Need to be fixed
  102.         created: function (){
  103.             this.getFilteringData();
  104.            
  105.            
  106.             if (Object.keys(this.$route.query).length) {
  107.                 this.catalogFilters = this.$route.query;
  108.                
  109.                
  110.                 if (this.$route.params.category == 'tire') {
  111.                     this.catalogFilters = {
  112.                         brand: [],
  113.                         width: [],
  114.                         height: [],
  115.                         price: {}
  116.                     };
  117.                     this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_tires_products' ,
  118.                         filtration: $.param(this.catalogFilters),
  119.                         offset: 0,
  120.                         limit: 18});
  121.                    
  122.                 }
  123.                 if (this.$route.params.category == 'discs') {
  124.                     this.catalogFilters = {
  125.                         brand: [],
  126.                         width: [],
  127.                         krepezh: [],
  128.                         diameter: [],
  129.                         pcd1: [],
  130.                         et: [],
  131.                         dia: [],
  132.                         price: {}
  133.                     };
  134.                     this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_discs_products' ,
  135.                         filtration: $.param(this.catalogFilters),
  136.                         offset: 0,
  137.                         limit: 18});
  138.                 }
  139.             } else {
  140.                 this.$store.dispatch('catalog/updateVisitedProducts');
  141.                
  142.                 if (this.$route.params.category == 'tire') {
  143.                     this.$store.dispatch('catalog/updateCatalogFilters', {category: 'get_tires_filters'});
  144.                     this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_tires_products' , offset: 0, limit: 18});
  145.                 }
  146.                 if (this.$route.params.category == 'discs') {
  147.                     this.$store.dispatch('catalog/updateCatalogFilters', {category: 'get_discs_filters'});
  148.                     this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_discs_products' , offset: 0, limit: 18});
  149.                 }
  150.             }
  151.         },
  152.         mounted: function(){
  153.             var that = this;
  154.             var catalogCategory = that.$route.params.category;
  155.            
  156.            
  157.             if (this.$route.params.category == 'tire') {
  158.                 this.catalogFilters = {
  159.                     brand: [],
  160.                     width: [],
  161.                     height: [],
  162.                     price: {}
  163.                 };
  164.            
  165.                
  166.             }
  167.             if (this.$route.params.category == 'discs') {
  168.                 this.catalogFilters = {
  169.                     brand: [],
  170.                     width: [],
  171.                     krepezh: [],
  172.                     diameter: [],
  173.                     pcd1: [],
  174.                     et: [],
  175.                     dia: [],
  176.                     price: {}
  177.                 };
  178.                
  179.             }
  180.            
  181.            
  182.         },
  183.         computed: {
  184.             category: function(){
  185.                 return this.$route.params.category;
  186.             },
  187.             categoryInfo: function() {
  188.                
  189.                 if (this.category == 'tire') {
  190.                    
  191.                     return this.$store.state.catalog.tiresFilters;
  192.                 }
  193.                 if (this.category == 'discs') {
  194.                     return this.$store.state.catalog.discsFilters;
  195.                 }
  196.             },
  197.             sidebarFilters: function() {
  198.                 if (this.category === 'tire' && this.categoryInfo && this.categoryInfo['prices']) {
  199.                    
  200.                     return [
  201.                         {
  202.                             slug: 'brand',
  203.                             name: 'Производители',
  204.                             data:  this.categoryInfo.brands,
  205.                             component: CheckboxFilter
  206.                         }, {
  207.                             slug: 'prices',
  208.                             name: 'Цена',
  209.                             data:  this.categoryInfo['prices'],
  210.                             component: RangeFilter
  211.                         }, {
  212.                             slug: 'width',
  213.                             name: 'Ширина',
  214.                             data:  this.categoryInfo.widths,
  215.                             component: CheckboxFilter
  216.                         }, {
  217.                             slug: 'height',
  218.                             name: 'Высота профиля',
  219.                             data:  this.categoryInfo.heights,
  220.                             component: CheckboxFilter
  221.                         }, {
  222.                             slug: 'season',
  223.                             name: 'Сезонность',
  224.                             data:  this.categoryInfo.seasons,
  225.                             component: CheckboxFilter
  226.                         }
  227.                     ];
  228.                 }
  229.                 if (this.category === 'discs' && this.categoryInfo) {
  230.                     return [
  231.                         {
  232.                             slug: 'brand',
  233.                             name: 'Производители',
  234.                             data:  this.categoryInfo.brands,
  235.                             component: CheckboxFilter
  236.                         }, {
  237.                             slug: 'prices',
  238.                             name: 'Цена',
  239.                             data:  this.categoryInfo['prices'],
  240.                             component: RangeFilter
  241.                         }, {
  242.                             slug: 'width',
  243.                             name: 'Ширина',
  244.                             data:  this.categoryInfo.widths,
  245.                             component: CheckboxFilter
  246.                         }, {
  247.                             slug: 'krepezh',
  248.                             name: 'Крепеж',
  249.                             data:  this.categoryInfo.krepezh,
  250.                             component: CheckboxFilter
  251.                         }, {
  252.                             slug: 'diameter',
  253.                             name: 'Диаметр диска',
  254.                             data:  this.categoryInfo.diameters,
  255.                             component: CheckboxFilter
  256.                         }, {
  257.                             slug: 'pcd1',
  258.                             name: 'PCD',
  259.                             data:  this.categoryInfo.pcd1,
  260.                             component: CheckboxFilter
  261.                         }, {
  262.                             slug: 'et',
  263.                             name: 'ET',
  264.                             data:  this.categoryInfo.et,
  265.                             component: CheckboxFilter
  266.                         }, {
  267.                             slug: 'dia',
  268.                             name: 'DIA',
  269.                             data:  this.categoryInfo.dia,
  270.                             component: CheckboxFilter
  271.                         },
  272.                     ];
  273.                 }
  274.                
  275.             },
  276.             getCargoPerPage: function(){
  277.                 return this.$store.getters['catalog/getCatalogPerPage'];
  278.             },
  279.             getPriceAmount: function(){
  280.                 return this.$store.state.catalog.priceAmount;
  281.             },
  282.            
  283.             pages: function() {
  284.                 var content  = parseInt(this.$store.state.catalog.pageAmount);
  285.                
  286.                 var total= [];
  287.                 var total_amount = content;
  288.                
  289.                 if (content) {
  290.                     for(var i = 0; i < content / 18; i++) {
  291.                         total.push(i +1);
  292.                     }
  293.                     return total;
  294.                 }
  295.             },
  296.             visitedProducts: function(){
  297.                 return this.$store.state.catalog.visitedProducts;
  298.             }
  299.             // FILTERING
  300.            
  301.         },
  302.         methods: {
  303.             checkboxFilter : function(products, filters, param) {
  304.                 return products.filter(function(item){
  305.                     return filters.find(function(filteringItem) {
  306.                         return filteringItem === item[param];
  307.                     })
  308.                 });
  309.             },
  310.             resetPrice: function() {
  311.                 var catalogCategory = this.$route.params.category;
  312.                 var that = this;
  313.                 if (catalogCategory == 'tire') {
  314.                     if (that.$store.getters['catalog/getTirePriceAmount']) {
  315.                         that.priceAmount = that.$store.getters['catalog/getTirePriceAmount'];
  316.                     }
  317.                 }
  318.                 if (catalogCategory == 'discs') {
  319.                     if (that.$store.getters['catalog/getTirePriceAmount']) {
  320.                         that.priceAmount = that.$store.getters['catalog/getDiscsPriceAmount'];
  321.                     }
  322.                 }
  323.                
  324.                 this.$forceUpdate();
  325.                
  326.             },
  327.             getFilteringData: function(){
  328.                 if (this.$route.params.category == 'tire') {
  329.                     this.$store.dispatch('catalog/updateCatalogFilters', {category: 'get_tires_filters'});
  330.                 }
  331.                 if (this.$route.params.category == 'discs') {
  332.                     this.$store.dispatch('catalog/updateCatalogFilters', {category: 'get_discs_filters'});
  333.                 }
  334.             },
  335.             resetFilter: function() {
  336.                 this.resetPrice();
  337.                 this.resetCargoPerPage();
  338.                 this.getFilteringData();
  339.                 this.selectedFiltersNumber = this.selectedFiltersNumber + 1;
  340.                 this.catalogFilters = {};
  341.             },
  342.             resetCargoPerPage: function() {
  343.                 if (this.$route.params.category == 'tire') {
  344.                     this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_tires_products',
  345.                         offset: 0,
  346.                         limit: 18});
  347.                 }
  348.                 if (this.$route.params.category == 'discs') {
  349.                     this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_discs_products' ,
  350.                         offset: 0,
  351.                         limit: 18});
  352.                 }
  353.             },
  354.             // filters
  355.             setCatalogFilters: function(e){
  356.                 this.page = 1;
  357.                
  358.                 // Get Filtered Products
  359.                 this.catalogFilters = e;
  360.                
  361.                 // Is filtering now
  362.                 this.isFiltering = this.isFilteringNow();
  363.                
  364.                 if (this.$route.query) {
  365.                     var that = this;
  366.                     console.log(this.$route.query);
  367.                    
  368.                     Object.keys(this.$route.query).forEach(function(item){
  369.                        
  370.                         var index = Object.keys(that.$route.query).indexOf(item);
  371.                        
  372.                         that.catalogFilters[item] = [Object.values(that.$route.query)[index]];
  373.                         console.log(item);
  374.                     });
  375.                     console.log(this.catalogFilters);
  376.                 }
  377.                
  378.                 // Get products depending on filtration
  379.                 if (this.isFiltering) {
  380.                     if (this.$route.params.category == 'tire') {
  381.                         console.log(this.catalogFilters);
  382.                         console.log($.param(this.catalogFilters));
  383.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_tires_products' ,
  384.                             filtration: $.param(this.catalogFilters),
  385.                             offset: 0,
  386.                             limit: 18});
  387.                     }
  388.                     if (this.$route.params.category == 'discs') {
  389.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_discs_products' ,
  390.                             filtration: $.param(this.catalogFilters),
  391.                             offset: 0,
  392.                             limit: 18});
  393.                     }
  394.                    
  395.                 } else {
  396.                     if (this.$route.params.category == 'tire') {
  397.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_tires_products' ,
  398.                             offset: 0,
  399.                             limit: 18});
  400.                     }
  401.                     if (this.$route.params.category == 'discs') {
  402.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_discs_products' ,
  403.                             offset: 0,
  404.                             limit: 18});
  405.                     }
  406.                    
  407.                 }
  408.             },
  409.             isFilteringNow: function() {
  410.                 var result = false;
  411.                
  412.                 Object.values(this.catalogFilters).forEach(function(item){
  413.                     console.log(item);
  414.                     console.log(typeof(item));
  415.                     console.log(!isEmpty(item));
  416.                     result = result || !isEmpty(item);
  417.                 });
  418.                
  419.                 return result;
  420.             },
  421.             updateCatalogContent: function() {
  422.                 console.log(this.catalogFilters);
  423.                 console.log(this.catalogFilters.length);
  424.                
  425.             }
  426.         },
  427.         watch: {
  428.             page: function(changed) {
  429.                 this.updateCatalogContent();
  430.                 if (this.priceAmount) {
  431.                     this.catalogFilters.price = {from: Math.round(changed.from), to: Math.round(changed.to)};
  432.                 }
  433.                
  434.                 console.log(this.catalogFilters.length != 0);
  435.                 console.log(this.catalogFilters);
  436.                
  437.                
  438.                 if (this.catalogFilters.length != 0) {
  439.                     if (this.$route.params.category == 'tire') {
  440.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_tires_products' ,
  441.                             filtration: $.param(this.catalogFilters),
  442.                             offset: this.page * 18 -18,
  443.                             limit: 18});
  444.                     }
  445.                     if (this.$route.params.category == 'discs') {
  446.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_discs_products' ,
  447.                             filtration: $.param(this.catalogFilters),
  448.                             offset: this.page * 18 -18,
  449.                             limit: 18});
  450.                     }
  451.                    
  452.                 } else {
  453.                     if (this.$route.params.category == 'tire') {
  454.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_tires_products' ,
  455.                             offset: this.page * 18 -18,
  456.                             limit: 18});
  457.                     }
  458.                     if (this.$route.params.category == 'discs') {
  459.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_discs_products' ,
  460.                             offset: this.page * 18 -18,
  461.                             limit: 18});
  462.                     }
  463.                    
  464.                 }
  465.             },
  466.             category: function(updated){
  467.                 if (updated) {
  468.                     this.resetFilter();
  469.                 }
  470.             },
  471.             '$route' : function () {
  472.                 this.getFilteringData();
  473.                 this.resetFilter();
  474.                 if (this.$route.query) {
  475.                     console.log(this.$route.query);
  476.                     for(var item in this.$route.query) {
  477.                         console.log(item);
  478.                     }
  479.                 }
  480.             },
  481.             priceAmount: function(changed) {
  482.                 this.catalogFilters.price = {from: Math.round(changed.from), to: Math.round(changed.to)};
  483.                
  484.                 if (Object.keys(this.catalogFilters).length ) {
  485.                     this.isFiltering = true;
  486.                     if (this.$route.params.category == 'tire') {
  487.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_tires_products' ,
  488.                             filtration: $.param(this.catalogFilters),
  489.                             offset: this.page * 18 -18,
  490.                             limit: 18});
  491.                     }
  492.                     if (this.$route.params.category == 'discs') {
  493.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'filter_discs_products' ,
  494.                             filtration: $.param(this.catalogFilters),
  495.                             offset: this.page * 18 -18,
  496.                             limit: 18});
  497.                     }
  498.                    
  499.                 } else {
  500.                     this.isFiltering = false;
  501.                     if (this.$route.params.category == 'tire') {
  502.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_tires_products' ,
  503.                             offset: 0,
  504.                             limit: 18});
  505.                     }
  506.                     if (this.$route.params.category == 'discs') {
  507.                         this.$store.dispatch('catalog/updateCargoPerPage',   {category: 'get_discs_products' ,
  508.                             offset: 0,
  509.                             limit: 18});
  510.                     }
  511.                 }
  512.             },
  513.             isProductsloaded: function(changed) {
  514.                 var that = this;
  515.                 var catalogCategory = that.$route.params.category;
  516.                 if (catalogCategory == 'tire') {
  517.                     if (that.$store.getters['catalog/getTirePriceAmount']) {
  518.                         that.priceAmount = that.$store.getters['catalog/getTirePriceAmount'];
  519.                     }
  520.                 }
  521.                 if (catalogCategory == 'discs') {
  522.                     if (that.$store.getters['catalog/getTirePriceAmount']) {
  523.                         that.priceAmount = that.$store.getters['catalog/getDiscsPriceAmount'];
  524.                     }
  525.                 }
  526.             },
  527.            
  528.             // filters
  529.  
  530.             isFiltering: function(changed) {
  531.            
  532.             }
  533.         },
  534.         components: {
  535.             'catalog-card':        require('../components/catalog-card.vue'),
  536.             'catalog-breadcrumbs': require('../components/catalog-breadcrumbs.vue'),
  537.             'catalog-range':       require('../components/catalog-range.vue'),
  538.             'select-component':    require('../components/select.vue'),
  539.             'paginator':           require('../components/paginator.vue'),
  540.             'catalog-checkboxes-component':           require('../components/catalog-checkboxes-component.vue')
  541.         }
  542.     };
  543.    
  544.     function isEmpty(obj) {
  545.         for(var key in obj) {
  546.             if(obj.hasOwnProperty(key))
  547.                 return false;
  548.         }
  549.         return true;
  550.     }
  551. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement