Selaa lähdekoodia

解决器件详情页收藏问题和店铺首页关注问题。

yangc 8 vuotta sitten
vanhempi
commit
3cc6821e1c

+ 17 - 22
components/product/component/ComponentDetail.vue

@@ -40,8 +40,8 @@
               <div class="message-body"><a :href="list.attach" v-if="list.attach">规格书</a><span v-if="!list.attach">暂无规格书</span></div>
             </div>
             <div class="form-group">
-               <button type="text" v-if="!isShow && collectList" @click="collect(list.id)" class="btn btn-default btn-stroe" style="line-height: 26px;">加入收藏</button>
-               <button class="btn btn-default btn-stroe" v-if="isShow && collectList" disabled="disabled">已收藏</button>
+               <button type="text" v-if="!collectList" @click="collect(list.id)" class="btn btn-default btn-stroe" style="line-height: 26px;">加入收藏</button>
+               <button class="btn btn-default btn-stroe" v-if="collectList" disabled="disabled">已收藏</button>
             </div>
           </div>
         </div>
@@ -68,13 +68,14 @@
     name: 'ComponentDetail',
     data () {
       return {
-        dialogVisible: false,
-        isShow: false
+        dialogVisible: false
       }
     },
+    mounted () {
+      this.collectList()
+    },
     computed: {
       lists () {
-       // console.log(this.$store.state.componentDetail.detail)
         return this.$store.state.componentDetail.detail
       },
       list () {
@@ -83,43 +84,37 @@
       user () {
         return this.$store.state.option.user
       },
+      colList () {
+        return this.$store.state.product.common.collectList.data
+      },
       collectList () {
-        if (this.lists.data.properties && this.lists.data.properties > 0) {
+   //     let _this = this
+        if (this.lists.data.properties && this.lists.data.properties.length > 0) {
           let id = this.lists.data.properties[0].componentId
-          // console.log(this.lists.data)
-          let store = this.$store.state.product.common.collectList.data
-          let _this = this
+          let store = this.colList
           if (store) {
             for (let i = 0; i < store.length; i++) {
               if (store[i].componentid === id) {
-                _this.isShow = true
+         //       _this.isShow = true
+                return true
               }
             }
           }
         }
-        return true
+   //     _this.isShow = false
+        return false
       }
     },
-    mounted () {
-      this.$nextTick(() => {
-        this.loadCollectList()
-      })
-    },
     components: {
       ComponentMenu
     },
     methods: {
-      loadCollectList () {
-        if (this.user.logged) {
-          this.$store.dispatch('product/saveStores')
-        }
-      },
       collect (id) {
         if (this.user.logged) {
           this.dialogVisible = true
           let kind = 2
           this.$store.dispatch('product/saveEntity', {componentid: id, kind: kind})
-          this.isShow = true
+          this.collectList = true
         } else {
           this.$http.get('/login/page').then(response => {
             if (response.data) {

+ 3 - 14
components/store/common/StoreHeader.vue

@@ -15,8 +15,8 @@
                 </div>
                 <div class="icon-style">
                   <!--<button class="btn btn-xs btn-danger btn-nav" v-if="!isFocus"><span class="watch">关注</span></button>-->
-                  <span v-if="!isFocus"><button type="text" @click="focus(storeInfo.id, storeInfo.storeName)" class="btn btn-xs btn-danger btn-nav"><span class="watch">关注</span></button></span>
-                  <span v-if="isFocus" ><button class="btn btn-xs btn-default btn-nav" style="width:50px"><span>已关注</span></button></span>
+                  <span v-if="isFocus == 'false' || typeof isFocus == 'object'"><button type="text" @click="focus(storeInfo.id, storeInfo.storeName)" class="btn btn-xs btn-danger btn-nav"><span class="watch">关注</span></button></span>
+                  <span v-if="isFocus == 'true'" ><button class="btn btn-xs btn-default btn-nav" style="width:50px"><span>已关注</span></button></span>
                   <span v-if="storeInfo.type == 'ORIGINAL_FACTORY'">&nbsp;<img src="/images/store/icon/icon-factory.png"/></span>
                   <span v-else-if="storeInfo.type == 'AGENCY'">&nbsp;<img src="/images/store/icon/icon-agent.png"/></span>
                   <span v-else-if="storeInfo.type == 'DISTRIBUTION'">&nbsp;<img src="/images/store/icon/icon-distribution.png"/></span>
@@ -86,21 +86,10 @@ export default {
       return this.$store.state.option.user
     },
     isFocus () {
-      const foucusList = this.$store.state.shop.storeInfo.focusList.data
-      return foucusList === 'true'
+      return this.$store.state.shop.storeInfo.focusList.data
     }
   },
-  mounted () {
-    this.$nextTick(() => {
-      this.loadFocusList()
-    })
-  },
   methods: {
-    loadFocusList () {
-      if (this.user.logged) {
-        this.$store.dispatch('shop/StoreFocusList', {id: this.storeInfo.id})
-      }
-    },
     closeDropDown () {
       this.isOpen = false
     },

+ 2 - 1
pages/product/component/_uuid.vue

@@ -29,7 +29,8 @@
               ignoreStore: false,
               storeIds: ''
             }}),
-        store.dispatch('getUmallStoreId')
+        store.dispatch('getUmallStoreId'),
+        store.dispatch('product/saveStores')
       ])
     },
     created () {

+ 14 - 0
store/product.js

@@ -1,5 +1,16 @@
 import axios from '~/plugins/axios'
 
+// 保存一列收藏记录, 此方法仅限于在登陆界面使用
+function saveStores ({ commit }, params = {}) {
+  commit('common/REQUEST_COLLECTLIST')
+  return axios.get(`trade/collection/list`, { params })
+    .then(response => {
+      commit('common/GET_COLLECTLIST_SUCCESS', response.data)
+    }, err => {
+      commit('common/GET_COLLECTLIST_FAILURE', err)
+    })
+}
+
 export const actions = {
   // 全局服务初始化
   nuxtServerInit (store, { params, route, isServer, req }) {
@@ -106,6 +117,9 @@ export const actions = {
         commit('common/GET_COLLECTSAVA_SUCCESS', response.data)
         if (response.data === 'success') {
           commit('common/GET_COLLECTLIST_SUCCESS')
+          return Promise.all([
+            saveStores({ commit })
+          ])
         }
       }, err => {
         commit('common/GET_COLLECTSAVA_FAILURE', err)

+ 15 - 1
store/shop.js

@@ -1,5 +1,16 @@
 import axios from '~plugins/axios'
 
+// 载入历史记录
+function StoreFocusList ({ commit }, params = {}) {
+  commit('storeInfo/REQUEST_FOCUSLIST')
+  return axios.get(`/trade/storeFocus/ifFocus?storeid=${params.id}`)
+    .then(response => {
+      commit('storeInfo/GET_FOCUSLIST_SUCCESS', response.data)
+    }, err => {
+      commit('storeInfo/GET_FOCUSLIST_FAILURE', err)
+    })
+}
+
 export const actions = {
   // 根据UUID获取某店铺信息
   findStoreInfoFromUuid ({ commit }, params = {}) {
@@ -7,6 +18,9 @@ export const actions = {
     return axios.get('/api/store-service/stores', { params })
       .then(response => {
         commit('storeInfo/GET_STORE_INFO_SUCCESS', response.data)
+        return Promise.all([
+          StoreFocusList({ commit }, {id: response.data.id})
+        ])
       }, err => {
         commit('storeInfo/GET_STORE_INFO_FAILURE', err)
       })
@@ -65,6 +79,7 @@ export const actions = {
     commit('storeInfo/REQUEST_FOCUSLIST')
     return axios.get(`/trade/storeFocus/ifFocus?storeid=${params.id}`)
       .then(response => {
+        console.log(response.data)
         commit('storeInfo/GET_FOCUSLIST_SUCCESS', response.data)
       }, err => {
         commit('storeInfo/GET_FOCUSLIST_FAILURE', err)
@@ -75,7 +90,6 @@ export const actions = {
     return axios.post(`/trade/storeFocus/save`, storeName)
       .then(response => {
         commit('storeInfo/GET_FOCUS_SUCCESS', response.data)
-        console.log(response.data)
         if (response.data === 'success') {
           commit('storeInfo/GET_FOCUSLIST_SUCCESS', 'true')
         }