Browse Source

器件选型筛选

ouxq 8 years ago
parent
commit
c76edce10f

+ 8 - 7
components/product/CategoryProperty.vue

@@ -56,7 +56,7 @@
           <tbody>
           <tr v-if="hasProperties" class="tr-properties">
             <td v-for="pro in properties" class="td-properties" style="vertical-align:middle;" v-bind="selectedProduct">
- 								<span class="sl-selected" @click="selectProperty(pro.propertyId)" v-if="!isDel(pro.propertyId)">
+ 								<span class="sl-selected" @click="selectProperty(pro, pro.propertyId)" v-if="!isDel(pro.propertyId)">
  									<a class="text-num" v-text="selectedProduct['a' + pro.propertyId].value" style="color: #5078CB"></a>
 									<span><i class="fa fa-close"></i></span>
  								</span>
@@ -141,15 +141,17 @@
       },
       selectBrand (item) {
         this.selectedBrand = item
-        this.$emit('loadCmpGoodsByBrandEvent', item.id)
+        console.log(this.JSONObj)
+        this.$emit('loadCmpGoodsByBrandEvent', item.id, JSON.stringify(this.JSONObj))
       },
       delBrand () {
         this.selectedBrand = {}
-        this.$emit('loadCmpGoodsByBrandEvent', null)
+        this.$emit('loadCmpGoodsByBrandEvent', null, JSON.stringify(this.JSONObj))
       },
-      selectProperty (propertyId) {
+      selectProperty (item, propertyId) {
         this.selectedProduct['a' + propertyId] = ''
-        this.$emit('loadCmpGoodsByTypeEvent', null)
+        delete this.JSONObj[propertyId]
+        this.$emit('loadCmpGoodsByTypeEvent', JSON.stringify(this.JSONObj), this.selectedBrand.id)
         this.hasProperties = this.isempty(this.selectedProduct)
         this.list_exp_flag = true
         this.list_exp_flag = false
@@ -169,8 +171,7 @@
         this.hasProperties = true
         this.selectedProduct['a' + propertyId] = item
         this.JSONObj[propertyId] = item.value
-        this.$emit('loadCmpGoodsByTypeEvent', JSON.stringify(this.JSONObj))
-        this.list_exp_flag = false
+        this.$emit('loadCmpGoodsByTypeEvent', JSON.stringify(this.JSONObj), this.selectedBrand.id)
       },
       use_exp_list: function (pro, index) {
         this.selectedProperties = pro

+ 18 - 3
components/product/ComponentGoods.vue

@@ -119,20 +119,25 @@
 <script>
   export default {
     layout: 'mian',
+    props: ['brandid', 'propertyJSON'],
     data () {
       return {
         pageParams: {
           page: 1,
           count: 10,
           filter: {
-            kindid: this.$route.params.id
+            kindid: this.$route.params.id,
+            brandid: this.brandid,
+            propertyJSON: this.propertyJSON
           }
         }
       }
     },
     computed: {
       componentGoods () {
-        return this.$store.state.product.component.componentGoods.data
+        let goodsPage = this.$store.state.product.component.componentGoods.data
+        this.pageParams.page = goodsPage.number
+        return goodsPage
       }
     },
     methods: {
@@ -140,12 +145,19 @@
         return null
       },
       handlerCurrentNode (data, node) {
+        console.log(this.pageParams)
         this.pageParams.page = 1
         this.pageCmpGoods(this.pageParams)
       },
       async pageCmpGoods (pageParams) {
         let params = {}
-        params.filter = pageParams.filter
+        params.filter = { kindid: pageParams.filter.kindid }
+        if (pageParams.filter.brandid && pageParams.filter.brandid !== '') {
+          params.filter.brandid = pageParams.filter.brandid
+        }
+        if (pageParams.filter.propertyJSON !== null && Object.getOwnPropertyNames(pageParams.filter.propertyJSON).length > 3) {
+          params.filter.properties = pageParams.filter.propertyJSON
+        }
         params.page = pageParams.page
         params.count = pageParams.count
         let { data } = await this.$http.get('/api/product/product/getCompGoodsByKindid', { params })
@@ -153,6 +165,9 @@
       },
       handleCurrentChange (page) {
         this.pageParams.page = page
+        this.pageParams.filter.brandid = this.brandid
+        this.pageParams.filter.propertyJSON = this.propertyJSON
+        console.log(this.pageParams)
         this.pageCmpGoods(this.pageParams)
       }
     }

+ 24 - 7
pages/product/kind/_id.vue

@@ -2,7 +2,7 @@
   <div class="container">
     <categroy-nav></categroy-nav>
     <category-property  @loadCmpGoodsByBrandEvent="listemBrandFilter" @loadCmpGoodsByTypeEvent="listemProTypeFilter"></category-property>
-    <component-goods></component-goods>
+    <component-goods :brandid="brandid" :propertyJSON="propertyJSON"></component-goods>
   </div>
 </template>
 
@@ -11,6 +11,12 @@
 
   export default {
     layout: 'main',
+    data () {
+      return {
+        brandid: '',
+        propertyJSON: {}
+      }
+    },
     fetch ({store, route}) {
       return Promise.all([
         store.dispatch('product/loadKindParentsWithBothers', {id: route.params.id}),
@@ -27,18 +33,29 @@
       loadPage (id) {
         this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id, brandid: id})
       },
-      listemBrandFilter (brandid) {
+      listemBrandFilter (brandid, propertyJSON) {
+        this.brandid = brandid
+        this.propertyJSON = propertyJSON
+        console.log(this.brandid)
         if (brandid) {
-          this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id, brandid: brandid})
+          if (propertyJSON !== null && Object.getOwnPropertyNames(propertyJSON).length > 3) {
+            this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id, brandid: brandid, properties: propertyJSON})
+          } else {
+            this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id, brandid: brandid})
+          }
+        } else if (propertyJSON !== null && Object.getOwnPropertyNames(propertyJSON).length > 3) {
+          this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id, properties: propertyJSON})
         } else {
           this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id})
         }
       },
-      listemProTypeFilter (propertyJSON) {
-        if (propertyJSON !== {}) {
-          this.$store.dispatch('product/pageComGoods', propertyJSON == null ? {kindid: this.$route.params.id} : {kindid: this.$route.params.id, properties: propertyJSON})
+      listemProTypeFilter (propertyJSON, brandid) {
+        this.brandid = brandid
+        this.propertyJSON = propertyJSON
+        if (propertyJSON !== null && Object.getOwnPropertyNames(propertyJSON).length > 3) {
+          this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id, brandid: brandid, properties: propertyJSON})
         } else {
-          this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id})
+          this.$store.dispatch('product/pageComGoods', {kindid: this.$route.params.id, brandid: brandid})
         }
       }
     }