Browse Source

调整 收藏相关功能逻辑

yangc 8 years ago
parent
commit
9d519e9eef

+ 1 - 1
app.html

@@ -6,7 +6,7 @@
   <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/element-ui/1.3.7/theme-default/index.css"/>
   <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_0d1jjt5tukcblnmi.css"/>
   <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.css"/>
-  <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_452262_mca1wkdhzrzoajor.css">
+  <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_452262_380hfz7t3zph9f6r.css">
   {{ HEAD }}
   <script>
     (function (w, d) {

+ 5 - 18
components/mobile/Home.vue

@@ -19,7 +19,7 @@
         <!--</ul>-->
         <div class="home-input">
           <input type="text" placeholder="请输入您要查找的型号、品牌或商家" v-model="keyword"
-                 @focus.stop.prevent="onFocus()"/>
+                 @focus.stop.prevent="onFocus()" @blur="onBlur()"/>
           <span @click="onSearch()"><i class="iconfont icon-sousuo"></i></span>
         </div>
         <!--<p style="color:#e45803;line-height:.4rem;margin-top:.1rem;width:4.2rem;margin-left:1rem;">搜品牌、搜现货 、搜好店 、搜规格书 就上优软商城</p>-->
@@ -126,13 +126,15 @@
       onFocus () {
         this.associate = true
       },
+      onBlur () {
+        this.associate = false
+      },
       onSearch () {
         if (this.keyword) {
           this.$router.push({path: '/mobile/search?w=' + encodeURIComponent(this.keyword)})
         }
       },
       matNumber (num) {
-//        let re = /(\d+)(\d{3})/
         if (num > 99999999) {
           this.isShow = true
           let str2 = num.toString()
@@ -153,13 +155,6 @@
         } else {
           num += '个'
         }
-//        let length = String(num).length
-//        this.len = length > 3 ? length + 1 : length
-//        num = (Array(7 - length).join(0) + num)
-//        while (re.test(num)) {
-//          num = num.replace(re, '$1,$2')
-//        }
-//        num = num.split('')
         return num
       },
       forNum (numbers) {
@@ -176,13 +171,6 @@
     created () {
       this.$store.dispatch('resetSearchKeywords')
     },
-    mounted () {
-      this.$nextTick(() => {
-        setInterval(() => {
-          this.loadCounts()
-        }, 30000)
-      })
-    },
     computed: {
       numbrand () {
         return this.forNum(this.counts)
@@ -252,8 +240,7 @@
              display:inline-block;
              text-align: center;
              width:1rem;
-             height:.65rem;
-             line-height: .64rem;
+             line-height: .62rem;
              font-size:.23rem;
              border-left:none;
              border-radius:   0 .05rem .05rem 0;

+ 1 - 1
components/mobile/brand/BrandDetail.vue

@@ -202,7 +202,7 @@
         }
       },
       toShowPdf: function (url) {
-        if (url !== '1') {
+        if (url && url !== '1') {
           window.location.href = url
         }
       }

+ 1 - 1
components/mobile/brand/ComponentDetail.vue

@@ -158,7 +158,7 @@
     },
     methods: {
       goAttach: function (url) {
-        if (url !== '1') {
+        if (url && url !== '1') {
           window.location.href = url
         }
       }

+ 52 - 33
pages/mobile/search/_keycode.vue

@@ -1,44 +1,42 @@
 <template>
   <div class="search-list">
-    <div class="search-item">
+    <div class="search-item" v-if="productList.expose > 0 || productList.brands">
       <span :class="activeType=='store'?'active':''" @click="clickType('store')">仅看有货</span>
       <span :class="activeType=='support'?'active':''" @click="clickType('support')">店铺自营</span>
     </div>
 
-    <div class="brand-list-content" v-if="!productList.brands && productList.expose">
+    <div class="brand-list-content" v-if="!productList.brands && productList.expose > 0 && brandList && brandList.length > 1">
       <div class="brand-list-top">
         <span>品牌墙</span>
-        <span @click="onclick()">展开<i class="iconfont icon-arrow-down"></i></span>
+        <span @click="onclick()" v-if="brandList.length > 8">{{!isShow?'收起':'展开'}}<i :class="{'iconfont icon-arrow-down':isShow,'icon-icon-shang iconfont':!isShow}"></i></span>
       </div>
-      <div class="brand-list-item" :style="isShow?'max-height:2.1rem;':'min-height:2.1rem;'" >
-        <div v-for="item in brandList">
-          <nuxt-link to="/">
+      <div class="brand-list-item" >
+        <div v-for="item in isShow?brandList.slice(0, 8):brandList">
+          <nuxt-link :to="'/mobile/brand/'+item.br_uuid">
             <img :src="item.logoUrl ||'/images/component/default.png'"/>
           </nuxt-link>
         </div>
       </div>
     </div>
 
-    <div class="detail-brand-content" v-if="productList.brands">
+    <div class="detail-brand-content" v-if="productList.brands" @click="goBrand(list.uuid)">
       <h4>主营产品</h4>
       <div class="brand-list">
         <div class="list-left">
-          <img :src="brandDetail.logoUrl || '/images/component/default.png'" :alt="brandDetail.nameEn"/>
-          <span>{{brandDetail.nameCn}}</span>
+          <img :src="list.logoUrl || '/images/component/default.png'" :alt="list.nameEn"/>
+          <span>{{list.nameCn}}</span>
         </div>
-        <p>{{brandDetail.series}}</p>
+        <p>{{list.series}}</p>
       </div>
     </div>
 
     <div class="detail-brand" v-for="(item, index) in productList.components" v-if="productList.components">
-      <nuxt-link :to="'/mobile/brand/componentDetail/'+ item.uuid">
-        <div class="brand-item">
-          <p>型号:<span>{{item.code}}</span></p>
-          <p>品牌:<span>{{item.brand.nameCn}}</span></p>
-          <p>产品描述:<span>{{item.kind.nameCn}}</span></p>
-          <i class="iconfont icon-shoucang" :style="(item.isFocus==='true')?'color:#ff7800':'color:#333'"></i>
-        </div>
-      </nuxt-link>
+      <div class="brand-item" @click="goComponent(item.uuid)">
+        <p>型号:<span>{{item.code}}</span></p>
+        <p>品牌:<span>{{item.brand.nameCn}}</span></p>
+        <p>产品描述:<span>{{item.kind.nameCn}}</span></p>
+        <i class="iconfont icon-shoucang" :style="(item.isFocus)?'color:#ff7800':'color:#333'" @click="collect(item, $event)"></i>
+      </div>
     </div>
 
     <div class="none-state" v-if="!productList.expose">
@@ -59,34 +57,32 @@
         sorting: {},
         isShow: true,
         isMove: '',
-        isFocus: false
+        isFocus: false,
+        isClickCollect: false
       }
     },
     fetch ({store, route}) {
       return Promise.all([
-        store.dispatch('searchData/searchForList', {count: 15, filter: {}, keyword: route.query.w, page: 1, sorting: {'GO_RESERVE': 'DESC', 'GO_SEARCH': 'DESC'}}),
+        store.dispatch('searchData/searchForListInMobile', {count: 15, filter: {}, keyword: route.query.w, page: 1, sorting: {'GO_RESERVE': 'DESC', 'GO_SEARCH': 'DESC'}}),
         store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: route.query.w, paramJSON: {}})
       ])
     },
     computed: {
       productList () {
-//        const listData = this.$store.state.provider.stores.storeList.data
-//        for (let i = 0; i < listData.components.length; i++) {
-//          this.$http.get('/trade/storeFocus/ifFocus?storeid=' + listData.components[i].id)
-//            .then(
-//              function (response) {
-//                listData.components[i].isFocus = response.data
-//              }
-//            )
-//        }
-//        return listData
-        return this.$store.state.provider.stores.storeList.data
+        return this.$store.state.searchData.searchList.lists.data
       },
       brandList () {
         return this.$store.state.searchData.searchBrands.brands.data
       },
       brandDetail () {
-        return this.$store.state.searchData.searchDetail.detail.data
+        return this.$store.state.searchData.searchList.lists.data.brands
+      },
+      list () {
+        let list = this.$store.state.searchData.searchDetail.detail.data
+        if (list.application && list.application !== '') {
+          this.applications = list.application.split(',')
+        }
+        return list
       }
     },
     methods: {
@@ -102,6 +98,29 @@
           this.activeType = 'support'
           this.$store.dispatch('searchData/searchForList', {count: 15, filter: {'goods_store_type': ['ORIGINAL_FACTORY', 'AGENCY', 'DISTRIBUTION']}, keyword: this.$route.query.w, page: 1, sorting: {'GO_RESERVE': 'DESC', 'GO_SEARCH': 'DESC'}})
         }
+      },
+      goBrand: function (uuid) {
+        this.$router.push('/mobile/brand/' + uuid)
+      },
+      collect: function (item, $event) {
+        this.isClickCollect = true
+        if (!item.isFocus) {
+          this.$http.post('/trade/collection/save', {componentid: item.cmpId, kind: 2})
+            .then(response => {
+              item.isFocus = true
+            })
+        } else {
+          this.$http.delete('/trade/collection/' + item.cmpId).then(response => {
+            item.isFocus = false
+          })
+        }
+      },
+      goComponent: function (uuid) {
+        if (!this.isClickCollect) {
+          this.$router.push('/mobile/brand/componentDetail/' + uuid)
+        } else {
+          this.isClickCollect = false
+        }
       }
     }
   }
@@ -246,7 +265,7 @@
         i{
           display:block;
           position:absolute;
-          top:.2rem;
+          top:.55rem;
           right:.1rem;
           font-size:.4rem;
           color:#ff7800;

+ 19 - 15
pages/mobile/shop/index.vue

@@ -4,10 +4,10 @@
       <p><i class="iconfont icon-dianpu1"></i><span>{{list.totalElements}}</span>家店铺</p>
       <span @click="onClick()">{{downName}} <i class="iconfont icon-arrow-down"></i></span>
       <ul class="supdown" v-if="down">
+        <li @click="onDown('ORIGINAL_FACTORY-DISTRIBUTION-AGENCY' )">全部</li>
         <li @click="onDown('ORIGINAL_FACTORY')">原厂</li>
         <li @click="onDown('AGENCY')">代理</li>
         <li @click="onDown('DISTRIBUTION')">经销</li>
-        <li @click="onDown('ORIGINAL_FACTORY-DISTRIBUTION-AGENCY' )">全部</li>
       </ul>
     </div>
     <div class="shop-list" v-for="item in list.content">
@@ -21,7 +21,7 @@
           <p>电话:<span>{{item.enterprise.enTel}}</span></p>
           <p>传真:<span>{{item.enterprise.enFax}}</span></p>
           <p>商家介绍: <nuxt-link :to="'/mobile/merchantDescription/'+item.uuid">点击查看</nuxt-link></p>
-          <i class="iconfont icon-shoucang" :style="(item.isFocus==='false')?'color:#ff7800':'color:#333'"></i>
+          <i class="iconfont icon-shoucang" :style="item.isFocus=='true'?'color:#ff7800':'color:#333'" @click="focusStore(item)"></i>
         </div>
       </div>
     </div>
@@ -43,22 +43,12 @@
     },
     fetch ({ store }) {
       return Promise.all([
-        store.dispatch('provider/findStoreList', { page: 1, count: 10, types: 'ORIGINAL_FACTORY-DISTRIBUTION-AGENCY' })
+        store.dispatch('provider/findStoreListInMobil', { page: 1, count: 10, types: 'ORIGINAL_FACTORY-DISTRIBUTION-AGENCY' })
       ])
     },
     computed: {
       list () {
-        const listData = this.$store.state.provider.stores.storeList.data
-        for (let i = 0; i < listData.content.length; i++) {
-          this.$http.get('/trade/storeFocus/ifFocus?storeid=' + listData.content[i].id)
-            .then(
-              function (response) {
-                listData.content[i].isFocus = response.data
-                console.log(listData.content[i])
-              }
-            )
-        }
-        return listData
+        return this.$store.state.provider.stores.storeList.data
       }
     },
     methods: {
@@ -79,7 +69,7 @@
         this.down = !this.down
       },
       onDown (type) {
-        this.$store.dispatch('provider/findStoreList', { page: 1, count: 10, types: type })
+        this.$store.dispatch('provider/findStoreListInMobil', { page: 1, count: 10, types: type })
         this.down = !this.down
         if (type === 'ORIGINAL_FACTORY') {
           this.downName = '原厂'
@@ -93,6 +83,20 @@
         if (type === 'ORIGINAL_FACTORY-DISTRIBUTION-AGENCY') {
           this.downName = '全部'
         }
+      },
+      focusStore: function (item) {
+//        item.isFocus = item.isFocus === 'false' ? 'true' : 'false'
+        if (item.isFocus === 'false') {
+          this.$http.post('/trade/storeFocus/save', {storeName: item.storeName, storeid: item.id})
+            .then(response => {
+              item.isFocus = 'true'
+            })
+        } else {
+          this.$http.post('/trade/storeFocus/delete/storeId', [item.id])
+            .then(response => {
+              item.isFocus = 'false'
+            })
+        }
       }
     }
   }

+ 32 - 8
pages/mobile/user/_uuid.vue → pages/mobile/user/index.vue

@@ -10,35 +10,32 @@
         <li @click="onDown('1')">全部收藏</li>
       </ul>
     </div>
-
     <div class="shop-list" v-if="isShop" v-for="item in focusPage.content">
       <h3>{{item.storeName}}</h3>
       <div class="list-item">
         <div class="item-img">
-          <i></i>
+          <i :style="getBackground(item.storeInfo.type)"></i>
           <img :src="item.storeInfo.logoUrl || '/images/component/default.png'">
         </div>
         <div class="list-item-phone">
           <p>电话:<span>{{item.storeInfo.enterprise.enTel}}</span></p>
           <p>传真:<span>{{item.storeInfo.enterprise.enFax}}</span></p>
           <p>商家介绍: <nuxt-link :to="'/mobile/merchantDescription/'+item.storeInfo.uuid">点击查看</nuxt-link></p>
-          <i class="iconfont icon-shoucang"></i>
+          <i class="iconfont icon-shoucang" @click="cancelFocus('store', item)"></i>
         </div>
       </div>
     </div>
-
     <div class="detail-brand" v-for="(item, index) in collectSave.content" v-if="isDevice">
       <nuxt-link :to="'/mobile/brand/componentDetail/'+ item.componentinfo.uuid">
         <div class="brand-item">
           <p>型号:<span>{{item.componentinfo.code}}</span></p>
           <p>品牌:<span>{{item.componentinfo.brand.nameCn}}</span></p>
           <p>产品描述:<span>{{item.componentinfo.kind.nameCn}}</span></p>
-          <i class="iconfont icon-shoucang"></i>
+          <i class="iconfont icon-shoucang" @click="cancelFocus('product', item)"></i>
         </div>
       </nuxt-link>
     </div>
-
-    <div class="none-state" v-if="!(collectSave.content && focusPage.content)">
+    <div class="none-state" v-if="!(collectSave.content&&collectSave.content.length>0 || focusPage.content&&focusPage.content.length > 0)">
       <img src="/images/mobile/@2x/shoucangkongzhuangtai@2x.png">
     </div>
   </div>
@@ -89,6 +86,33 @@
           this.isShop = true
           this.down = false
         }
+      },
+      cancelFocus: function (type, item) {
+        console.log(item)
+        if (type === 'store') {
+          this.$http.post('/trade/storeFocus/delete/storeId', [item.storeid])
+            .then(response => {
+              window.location.reload()
+            })
+        } else {
+          // /trade/collection/
+          this.$http.delete('/trade/collection/' + item.id)
+            .then(response => {
+              window.location.reload()
+            })
+        }
+      },
+      getBackground: function (type) {
+        let style = 'background: url('
+        if (type === 'AGENCY') {
+          style += '/images/mobile/@2x/shop/daili@2x.png'
+        } else if (type === 'DISTRIBUTION') {
+          style += '/images/mobile/@2x/shop/jingxiao@2x.png'
+        } else if (type === 'ORIGINAL_FACTORY') {
+          style += '/images/mobile/@2x/shop/yuanchang@2x.png'
+        }
+        style += ')no-repeat; background-size: .65rem .33rem;'
+        return style
       }
     },
     computed: {
@@ -190,7 +214,7 @@
             position:absolute;
             width:.65rem;
             height:.33rem;
-            background: url(/imgs/shop/daili@2x.png)no-repeat;
+            background: url(/images/mobile/@2x/shop/daili@2x.png)no-repeat;
             background-size: .65rem .33rem;
           }
           img{

+ 29 - 1
store/provider.js

@@ -8,7 +8,9 @@ import axios from '~plugins/axios'
 function countStoreOrderCount (store) {
   return axios.get('/api/provider/order/storeid/' + store.uuid + '/count')
 }
-
+function findStoreFocusInMobil (store) {
+  return axios.get('/trade/storeFocus/ifFocus?storeid=' + store.id)
+}
 export const actions = {
   // 获取销售排行榜信息
   loadSalesStore ({ commit }, params = {isOriginal: false}) {
@@ -102,5 +104,31 @@ export const actions = {
       }, err => {
         commit('stores/GET_STORE_LIST_FAILURE', err)
       })
+  },
+  findStoreListInMobil ({ commit }, params = {}) {
+    params.op = 'pageByType'
+    commit('stores/REQUEST_STORE_LIST')
+    return axios.get('/api/store-service/stores', { params })
+      .then(response => {
+        let listData = response.data
+        let focusData = []
+        for (let i = 0; i < listData.content.length; i++) {
+          focusData.push(findStoreFocusInMobil({id: listData.content[i].id}))
+        }
+        // 合并请求,获取店铺关注信息
+        return Promise.all(focusData)
+          .then(result => {
+            if (result) {
+              for (let i = 0; i < result.length; i++) {
+                listData.content[i].isFocus = result[i].data
+              }
+            }
+            commit('stores/GET_STORE_LIST_SUCCESS', listData)
+          }, err => {
+            commit('stores/GET_STORE_LIST_FAILURE', err)
+          })
+      }, err => {
+        commit('stores/GET_STORE_LIST_FAILURE', err)
+      })
   }
 }

+ 37 - 0
store/searchData.js

@@ -1,5 +1,20 @@
 import axios from '~plugins/axios'
 
+function reloadListData ({ commit }, listData) {
+  axios.get('/trade/collection/list').then(response => {
+    let focusData = response.data
+    for (let i = 0; i < listData.components.length; i++) {
+      for (let j = 0; j < focusData.length; j++) {
+        if (listData.components[i].cmpId === focusData[j].componentid) {
+          listData.components[i].isFocus = true
+        } else {
+          listData.components[i].isFocus = false
+        }
+      }
+    }
+    commit('searchList/GET_LIST_SUCCESS', listData)
+  })
+}
 export const actions = {
   // 获取搜索kind
   searchForKinds ({ commit }, params = {}) {
@@ -50,6 +65,28 @@ export const actions = {
         commit('searchList/GET_LIST_FAILURE', err)
       })
   },
+  // 获取手机端搜索list
+  searchForListInMobile ({ commit }, params = {}) {
+    commit('searchList/REQUEST_LIST', params)
+    return axios.get(`/api/product/component/search/compGoods`, {params})
+      .then(response => {
+        let listData = response.data
+        if (response.data.brands && response.data.brands.uuid) {
+          commit('searchDetail/REQUEST_DETAIL', params)
+          return axios.get(`/api/product/brand/${response.data.brands.uuid}`)
+            .then(response => {
+              reloadListData({ commit }, listData)
+              commit('searchDetail/GET_DETAIL_SUCCESS', response.data)
+            }, err => {
+              commit('searchDetail/GET_DETAIL_FAILURE', err)
+            })
+        } else {
+          reloadListData({ commit }, listData)
+        }
+      }, err => {
+        commit('searchList/GET_LIST_FAILURE', err)
+      })
+  },
   // 获取搜索货源
   searchForStoreType ({ commit }, params = {}) {
     commit('searchStoreType/REQUEST_STORETYPE', params)