panhui 4 gadi atpakaļ
vecāks
revīzija
22eb4079fa
2 mainītis faili ar 30 papildinājumiem un 21 dzēšanām
  1. 13 11
      src/views/product/List.vue
  2. 17 10
      src/views/product/Search.vue

+ 13 - 11
src/views/product/List.vue

@@ -15,14 +15,8 @@
             >
                 <van-tab
                     :title="item.label"
-                    :name="
-                        item.type === 'select'
-                            ? sort.split(',')[1] === 'desc'
-                                ? item.value[1]
-                                : item.value[0]
-                            : item.value
-                    "
-                    :title-class="item.type === 'select' && sort === item.value[0] ? '' : 'asc'"
+                    :name="item.value"
+                    :title-class="item.type === 'select' && sortDes ? sortDes : ''"
                     :key="index"
                     v-for="(item, index) in selectOptions"
                 >
@@ -69,6 +63,7 @@ export default {
             empty: false,
             beforeSort: '',
             sort: 'id,desc',
+            sortDes: '',
             type: '',
             source: '',
             minterId: '',
@@ -87,7 +82,7 @@ export default {
                 },
                 {
                     label: '价格',
-                    value: ['price,desc', 'price,asc'],
+                    value: 'price',
                     type: 'select'
                 }
             ],
@@ -132,12 +127,19 @@ export default {
         }
     },
     methods: {
-        changeTab() {
+        changeTab(info) {
             this.$nextTick(() => {
+                if (info.name === 'price') {
+                    this.sortDes = this.sortDes == 'desc' ? 'asc' : 'desc';
+                }
                 this.getData(true);
             });
         },
         beforeData() {
+            let sort = this.sort;
+            if (sort == 'price') {
+                sort = 'price,' + this.sortDes;
+            }
             return {
                 query: {
                     type: this.type,
@@ -147,7 +149,7 @@ export default {
                     minterId: this.minterId,
                     salable: this.salable || ''
                 },
-                sort: this.sort === 'id,desc' ? this.sortOptions[this.title] || this.sort : this.sort
+                sort: this.sort === 'id,desc' ? this.sortOptions[this.title] || sort : sort
             };
         },
         goSearch() {

+ 17 - 10
src/views/product/Search.vue

@@ -27,11 +27,10 @@
             >
                 <van-tab
                     :title="item.label"
-                    :name="
-                        item.type === 'select' ? (sort === item.value[0] ? item.value[1] : item.value[0]) : item.value
-                    "
-                    :title-class="item.type === 'select' && sort === item.value[0] ? '' : 'asc'"
+                    :name="item.value"
+                    :title-class="item.type === 'select' && sortDes ? sortDes : ''"
                     :key="index"
+                    :lazy-render="false"
                     v-for="(item, index) in selectOptions"
                 >
                     <template v-if="item.type === 'select'" #title>
@@ -105,6 +104,7 @@ export default {
             url: '/collection/all',
             scrollTop: 0,
             sort: 'id,desc',
+            sortDes: '',
             title: '',
             selectOptions: [
                 {
@@ -121,7 +121,7 @@ export default {
                 },
                 {
                     label: '价格',
-                    value: ['price,desc', 'price,asc'],
+                    value: 'price',
                     type: 'select'
                 }
             ],
@@ -148,12 +148,19 @@ export default {
         }
     },
     methods: {
-        changeTab() {
+        changeTab(info) {
             this.$nextTick(() => {
+                if (info.name === 'price') {
+                    this.sortDes = this.sortDes == 'desc' ? 'asc' : 'desc';
+                }
                 this.getData(true);
             });
         },
         beforeData() {
+            let sort = this.sort;
+            if (sort == 'price') {
+                sort = 'price,' + this.sortDes;
+            }
             return {
                 query: {
                     onShelf: true,
@@ -164,7 +171,7 @@ export default {
                     salable: this.salable || ''
                 },
                 search: this.search,
-                sort: this.sort === 'id,desc' ? this.sortOptions[this.title] || this.sort : this.sort
+                sort: this.sort === 'id,desc' ? this.sortOptions[this.title] || sort : sort
             };
         }
     },
@@ -172,9 +179,9 @@ export default {
         this.$nextTick(() => {
             this.changeScroll(this.scrollTop);
 
-            setTimeout(() => {
-                this.sort = this.beforeSort;
-            }, 1000);
+            // setTimeout(() => {
+            //     this.sort = this.beforeSort;
+            // }, 1000);
         });
     },
     beforeRouteLeave(to, from, next) {