Browse Source

Merge branch 'master' of ssh://10.10.101.21/source/mall-web-ssr into HEAD

yangc 8 years ago
parent
commit
004bebe9d9

+ 1 - 0
components/default/Header.vue

@@ -170,6 +170,7 @@
               border: $border;
               border-top: none;
               padding: 1em;
+              margin:0;
 
               .menu-item-first {
                 margin-bottom: 10px;

+ 199 - 8
components/default/RightBar.vue

@@ -2,10 +2,10 @@
   <div class="right-bar">
     <ul class="right-bar-center">
       <li class="right-bar-item">
-        <nuxt-link to="/user/cart" class="title">
+        <a href="user#/cart" class="title" target="_blank">
           <i class="iconfont icon-shopping-cart icon-xlg"></i>
-        </nuxt-link>
-        <div class="sidebar-menu"><a href="" title="我的购物车" target="_blank">我的购物车<em><span>(<span>10</span>)</span></em></a></div>
+        </a>
+        <div class="sidebar-menu"><a href="user#/cart" title="我的购物车" target="_blank">我的购物车<em><span>(<span v-text="cartCount.count || 0"></span>)</span></em></a></div>
       </li>
       <li class="right-bar-item">
         <a @click="onLeaveMessageClick()" class="title">
@@ -28,10 +28,25 @@
     </ul>
     <ul class="right-bar-bottom">
       <li class="right-bar-item">
-        <nuxt-link to="/user/browsingHistory" class="title">
+        <a href="http://www.usoftmall.com/user#/browsingHistory" class="title" target="_blank">
           <i class="iconfont icon-zuji icon-xlg"></i>
-        </nuxt-link>
-        <div class="sidebar-menu"><a href="" title="浏览记录" target="_blank">浏览记录</a></div>
+        </a>
+        <div class="sidebar-menu" v-if="!user.logged"><a href="user#/browsingHistory" title="浏览记录" target="_blank">浏览记录</a></div>
+        <div class="sidebar-menu" v-if="user.logged && listMe(history).length == 0"><a href="user#/browsingHistory" title="浏览记录" target="_blank">浏览记录</a></div>
+        <div class="foot-record sidebar-menu" v-if="user.logged && listMe(history).length > 0">
+          <h3><a href="">浏览历史</a></h3>
+          <dl>
+            <dd v-for="item in listMe(history)">
+                <a :href="'/store/' + item.storeid + '/' + item.batchCode" :title="item.code" v-text="item.code" v-if="item.status== 1"></a>
+                <a :title="item.code" v-text="item.code" v-if="item.status== 0" disabled="disabled"></a>
+                <div class="hover-shows">
+                    <em :class="{ 'off' : item.status== 0}"></em>
+                    <span :class="{ 'off' : item.status== 0}">失效</span>
+                    <a @click="deleteHistory(item,item.id)">&times;</a>
+                </div>
+            </dd>
+          </dl>
+        </div>
       </li>
       <li class="right-bar-item">
         <a @click="toTop()" class="title">
@@ -47,7 +62,41 @@
 
   export default {
     name: 'right-bar',
+    data () {
+      return {
+        historyLength: []
+      }
+    },
+    computed: {
+      user () {
+        return this.$store.state.option.user
+      },
+      cartCount () {
+        return this.$store.state.user.history.cartCount.data
+      },
+      history () {
+        let arr = this.$store.state.user.history.historyList.data.slice(0, 8)
+        return arr
+      }
+    },
+    mounted () {
+      this.$nextTick(() => {
+        this.loadHistorys()
+        this.loadCarCount()
+      })
+    },
     methods: {
+      listMe: function (list) {
+        return list.filter(function (item) {
+          return item.isDelete === 1
+        })
+      },
+      loadHistorys () {
+        this.$store.dispatch('user/loadHistory')
+      },
+      loadCarCount () {
+        this.$store.dispatch('user/CarCount')
+      },
       toTop () {
         scrollTo('body', 300)
       },
@@ -56,11 +105,18 @@
       },
       // 打开留言板
       onLeaveMessageClick () {
+      },
+      deleteHistory (item, id) {
+        this.$store.dispatch('user/deleteHistory', {id: id})
+        this.loadHistorys()
       }
     }
   }
 </script>
 <style lang="scss" scoped>
+  a[disabled] {
+    cursor: not-allowed;
+  }
   em,i{
     font-style: inherit;
   }
@@ -104,6 +160,141 @@
     -o-transform: translateX(-72px);
     transform: translateX(-72px);
   }
+  /*浏览记录*/
+  .right-bar ul li .foot-record{
+    /* display: none; */
+    width: 210px !important;
+    max-height: 230px;
+    line-height: 30px;
+   /* right: 200px;*/
+    top: inherit;
+    bottom: -100%;
+    height: inherit;
+    /*padding-bottom: 10px;*/
+  }
+  .right-bar ul li .foot-record h3{
+    line-height: 39px;
+    border-bottom: #767575 1px solid;
+    text-align: left;
+    padding-left: 10px;
+    width: 96%;
+    display: inline-block;
+    margin: 0 auto;
+    font-size: 12px;
+    height: 39px;
+  }
+  .right-bar ul li .foot-record h3:hover a{
+    color: #fbb029;
+  }
+  .right-bar ul li .foot-record h3 a{
+    color: #fff;
+    background-color: inherit;
+    line-height: 39px;
+    text-align: left;
+  }
+  .right-bar ul li .foot-record dl{
+    padding-top: 5px;
+    display: inline-block;
+    background: #555;
+  }
+  .right-bar ul li .foot-record dl,.right-bar ul li .foot-record dl dd{
+    width: 100%;
+    margin: 0 auto;
+    background: #555;
+  }
+  .right-bar ul li .foot-record dl dd{
+    line-height: 22px;
+    width: 100%;
+    display: inline-block;
+    float: left;
+    height: 22px;
+    position: relative;
+  }
+  .right-bar ul li .foot-record dl dd a{
+    display: inline-block;
+    height: 22px;
+    padding: 0 10px;
+    width: 91%;
+    font-size: 12px;
+    color: #fff;
+    line-height: 22px;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    background: none;
+    text-align: left;
+    padding-right: 44px;
+  }
+  .right-bar ul li li a:hover div.foot-record{
+    display: inline-block !important;
+  }
+  .right-bar ul li .foot-record dl dd:hover{
+    background: #fff;
+  }
+  .right-bar ul li .foot-record dl dd:hover a{
+    color: #333;
+  }
+  .right-bar ul li .foot-record dl dd:hover div.hover-shows{
+    display: inline-block;
+  }
+  .right-bar ul li .foot-record dl dd div.hover-shows{
+    position: absolute;
+    top: 0;
+    right: 2px;
+    max-width: 55px;
+    line-height: 20px;
+    padding-right: 0;
+    z-index: 100;
+    display: none;
+  }
+  .right-bar ul li .foot-record dl dd div.hover-shows span{
+    display: inline-block;
+    width: 30px;
+    height: 20px;
+    text-align: center;
+    line-height: 20px;
+    background: #e04b38;
+    color: #fff;
+    border-radius: 5px;
+    opacity: 0;
+    margin-top: 1px;
+  }
+  .right-bar ul li .foot-record dl dd:first-child{
+   /* margin-top: 5px;*/
+  }
+  .right-bar ul li .foot-record dl dd:last-child{
+   /* margin-bottom: 10px;*/
+  }
+  .right-bar ul li .foot-record dl dd div.hover-shows a{
+    font-size: 23px;
+    float: right;
+    width: 20px;
+    padding: 0;
+    text-align: center;
+    color: #999;
+    top: -2px;
+  }
+  .right-bar ul li .foot-record dl dd div.hover-shows a:hover{
+    color: #fbb029;
+  }
+  .right-bar ul li .foot-record dl dd div.hover-shows em{
+    display: inline-block;
+    position: absolute;
+    width: 0;
+    height: 0;
+    border-top: 8px solid transparent;
+    border-left: 7px solid #fbb029;
+    border-bottom: 8px solid transparent;
+    left: -158px;
+    top: 4px;
+  }
+  .right-bar ul li .foot-record dl dd div.hover-shows em.off{
+    border-left: 8px solid #b2b0b0;
+  }
+  .right-bar ul li .foot-record dl dd div.hover-shows span.off{
+    opacity: 1;
+  }
+  /*浏览记录结束*/
   .right-bar ul li .contact-us{
     /*right: 200px;*/
     height: 180px;
@@ -133,7 +324,7 @@
   }
   .right-bar-item{
     width: 36px;
-    height: 38px;
+   /* height: 38px;*/
   }
   .right-bar .right-bar-item a.title{
     display: inline-block;
@@ -162,7 +353,7 @@
     .right-bar-bottom {
       position: absolute;
       right: 0;
-      bottom: 20px;
+      bottom: 0;
       width: 36px;
     }
 

+ 8 - 0
components/store/CommodityInfo.vue

@@ -177,7 +177,15 @@ export default {
       return Math.ceil(this.fragment.total * Math.pow(10, 2)) / Math.pow(10, 2)
     }
   },
+  mounted () {
+    this.$nextTick(() => {
+      this.loadSaveHistory()
+    })
+  },
   methods: {
+    loadSaveHistory () {
+      this.$store.dispatch('shop/saveHistory', {id: this.commodity.batchCode})
+    },
     changeCurrency () {
       if (this.fragment.currency === 'RMB') {
         this.fragment.price = this.fragment.prices.rMBPrice

+ 10 - 0
store/shop.js

@@ -49,5 +49,15 @@ export const actions = {
       }, err => {
         commit('storeInfo/GET_STORE_COMMODITY_FAILURE', err)
       })
+  },
+  // 获取保存浏览记录
+  saveHistory ({ commit }, params = {}) {
+    commit('storeInfo/REQUEST_SAVEHISOTRY')
+    return axios.post(`/trade/history/goods/save?batchCode=${params.id}`, {})
+      .then(response => {
+        commit('storeInfo/GET_SAVEHISOTRY_SUCCESS', response.data)
+      }, err => {
+        commit('storeInfo/GET_SAVEHISOTRY_FAILURE', err)
+      })
   }
 }

+ 14 - 0
store/shop/storeInfo.js

@@ -17,6 +17,10 @@ export const state = () => ({
   storeCommodity: {
     fetching: false,
     data: {}
+  },
+  saveHistory: {
+    fetching: false,
+    data: {}
   }
 })
 
@@ -60,5 +64,15 @@ export const mutations = {
   GET_STORE_COMMODITY_SUCCESS (state, result = {}) {
     state.storeCommodity.fetching = false
     state.storeCommodity.data = result
+  },
+  REQUEST_SAVEHISOTRY (state) {
+    state.saveHistory.fetching = true
+  },
+  GET_SAVEHISOTRY_FAILURE (state) {
+    state.saveHistory.fetching = false
+  },
+  GET_SAVEHISOTRY_SUCCESS (state, result) {
+    state.saveHistory.fetching = false
+    state.saveHistory.data = result
   }
 }

+ 34 - 0
store/user.js

@@ -0,0 +1,34 @@
+import axios from '~/plugins/axios'
+
+export const actions = {
+  // 获取浏览记录
+  loadHistory ({ commit }, params = {}) {
+    commit('history/REQUEST_HISTORY')
+    return axios.get('/trade/history/goods/list', {params})
+      .then(response => {
+        commit('history/GET_HISTORY_SUCCESS', response.data)
+      }, err => {
+        commit('history/GET_HISTORY_FAILURE', err)
+      })
+  },
+  // 删除一条历史记录
+  deleteHistory ({ commit }, params = {}) {
+    commit('history/REQUEST_DELETE')
+    return axios.post(`/trade/history/goods/setDelete?id=${params.id}`, {})
+      .then(response => {
+        commit('history/GET_DELETE_SUCCESS', response.data)
+      }, err => {
+        commit('history/GET_DELETE_FAILURE', err)
+      })
+  },
+  // 获取购物车数量
+  CarCount ({ commit }, params = {}) {
+    commit('history/REQUEST_CARTCOUNT')
+    return axios.get(`/trade/cart/count`, {params})
+      .then(response => {
+        commit('history/GET_CARTCOUNT_SUCCESS', response.data)
+      }, err => {
+        commit('history/GET_CARTCOUNT_FAILURE', err)
+      })
+  }
+}

+ 47 - 0
store/user/history.js

@@ -0,0 +1,47 @@
+export const state = () => ({
+  historyList: {
+    fetching: false,
+    data: []
+  },
+  deleteHistory: {
+    fetching: false,
+    data: []
+  },
+  cartCount: {
+    fetching: false,
+    data: []
+  }
+})
+
+export const mutations = {
+  REQUEST_HISTORY (state) {
+    state.historyList.fetching = true
+  },
+  GET_HISTORY_FAILURE (state) {
+    state.historyList.fetching = false
+  },
+  GET_HISTORY_SUCCESS (state, result) {
+    state.historyList.fetching = false
+    state.historyList.data = result
+  },
+  REQUEST_DELETE (state) {
+    state.deleteHistory.fetching = true
+  },
+  GET_DELETE_FAILURE (state) {
+    state.deleteHistory.fetching = false
+  },
+  GET_DELETE_SUCCESS (state, result) {
+    state.deleteHistory.fetching = false
+    state.deleteHistory.data = result
+  },
+  REQUEST_CARTCOUNT (state) {
+    state.cartCount.fetching = true
+  },
+  GET_CARTCOUNT_FAILURE (state) {
+    state.cartCount.fetching = false
+  },
+  GET_CARTCOUNT_SUCCESS (state, result) {
+    state.cartCount.fetching = false
+    state.cartCount.data = result
+  }
+}