Skip to content

Commit

Permalink
购物车模块完成
Browse files Browse the repository at this point in the history
  • Loading branch information
jmh65535 committed Oct 14, 2018
1 parent f56b82c commit 9f9b725
Show file tree
Hide file tree
Showing 16 changed files with 541 additions and 48 deletions.
15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "vue-cli-service build"
},
"dependencies": {
"better-scroll": "^1.13.2",
"fastclick": "^1.0.6",
"mint-ui": "^2.2.13",
"register-service-worker": "^1.0.0",
Expand Down
25 changes: 12 additions & 13 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--header-->
<mt-header fixed :title="title" v-if="show">
<a href="" slot="left" @click.prevent="$router.go(-1)">
<mt-button icon="back" v-if="showBackBtn">返回</mt-button>
<mt-button icon="back" v-if="showBackBtn"></mt-button>
</a>
</mt-header>

Expand Down Expand Up @@ -69,40 +69,39 @@
this.show = true
this.showBackBtn = false
this.showFooterTab = true
this.title = ''
// 路由个性设定
switch (nVal) {
case '/index':
case 'index':
this.title = '社区广场'
break
case '/service':
case 'service':
this.title = '社区服务'
break
case '/service/takeoutList':
case 'takeoutList':
this.title = '外卖'
this.showBackBtn = true
this.showFooterTab = false
break
case '/service/takeoutList/takeoutShop':
case 'takeoutShop':
this.show = false
this.showFooterTab = false
break
case '/home':
case 'home':
this.title = '我家'
break
case '/user':
case 'user':
this.show = false
this.title = '用户中心'
break
case '/user/login':
case 'login':
this.show = false
break
case '/user/stCenter':
case 'stCenter':
this.title = '设置'
this.showBackBtn = true
this.showFooterTab = false
break
case '/todo':
case 'todo':
this.title += '-'+this.$route.params.subTitle
this.showBackBtn = true
this.showFooterTab = false
Expand Down Expand Up @@ -132,14 +131,14 @@
this.flag.p24 = this.flag.love = this.flag.home = false
}
},
'$route.path' (nVal, oVal) {
'$route.name' (nVal, oVal) {
this.routerWatch(nVal, oVal)
}
},
created() {
// this.$router.push('/')
this.$router.push(this.$route.path)
this.routerWatch(this.$route.path) // 手动触发路由检测path变化函数
this.routerWatch(this.$route.name) // 手动触发路由检测path变化函数
},
mounted() {
this.selected = '首页'
Expand Down
200 changes: 200 additions & 0 deletions src/components/cart/Cart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<template>
<div class="cart-wrap">
<div class="ct-cates-wrap">
<ul class="ct-cates">
<li class="ct-cate active" @tap="showProducts('all')" data-a="all">全部</li>
<li class="ct-cate" v-for="cate in list.cate" @tap="showProducts(cate.cate_id)" :data-a="cate.cate_id" >{{cate.cate_name}}</li>
</ul>
</div>
<div class="ct-products-scroll-wrap">
<div class="ct-products-wrap" id="all">
<!--v-for="cate in this.list.cates" :key="cate.cate_id"-->
<div class="ct-products-box" v-for="cate2 in list.cate" cate :id="cate2.cate_id">
<div class="ct-products-cate">{{cate2.cate_name}}</div>
<div class="ct-products">
<div class="ct-product van-hairline--bottom" v-for="product in list.product" v-if="cate2.cate_id == product.cate_id">
<div class="photo-box"><img class="photo" :src="root+product.photo" alt=""></div>
<div class="detail">
<span class="name van-ellipsis">{{product.product_name}}</span>
<span class="star">★★★★☆</span>
<span class="month-sell">月售{{product.month_num}}单</span>
<span class="price">&yen;{{product.price}}</span>
<div class="num-box">
<span class="jian" @tap="removeFromCart(product)">-</span>
<span class="num">{{$store.getters.getCount[product.product_id] || 0}}</span>
<span class="jia" @tap="addToCart(product)">+</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div>
</template>

<script>
import { mapGetters } from 'vuex'
import BScroll from 'better-scroll'
export default {
name: 'Cart',
props: ['list'],
data () {
return {
scroll: {},
}
},
methods: {
showProducts(cateId) {
// 对应分类 添加类 .active
document.querySelectorAll('.ct-cate').forEach(cate => {
cate.className = 'ct-cate'
if(cate.dataset.a == cateId){
cate.classList.add('active')
}
})
// 右侧产品跳转对应栏目
setTimeout(() => {
this.scroll.scrollToElement(`#${cateId}`, 1000)
}, 100)
},
addToCart(p) {
setTimeout(() => {
this.$store.commit('addToCart', p)
},10)
},
removeFromCart(p){
setTimeout(() => {
this.$store.commit('removeFromCart', p)
},10)
},
},
mounted() {
new BScroll('.ct-cates-wrap')
this.scroll = new BScroll('.ct-products-scroll-wrap')
}
}
</script>

<style lang="scss" scoped>
.cart-wrap{
display: flex;
justify-content: space-between;
position: fixed;
width: 100%;
top: 157px;
left: 0;
height: 100%;
font-size: 16px;
background-color: #fff;
/*cates*/
.ct-cates-wrap{
flex: 1;
height: 100%;
overflow-y: hidden;
.ct-cates{
letter-spacing: 2px;
padding-bottom: 210px;
.ct-cate{
height: 50px;
line-height: 50px;
text-align: center;
border-bottom: 1px solid #fff;
background-color: #fbfbfb;
&.active{
color: #ff8200;
border-left: 2px solid $c1;
background-color: #fff;
}
}
}
}
/*products*/
.ct-products-scroll-wrap{
flex: 2;
/*height: 500px;*/
overflow-y: hidden;
}
.ct-products-wrap{
padding-bottom: 210px;
.ct-products-cate{
line-height: 20px;
font-size: 12px;
color: #333;
padding-left: 10px;
border-left: 2px solid $c1;
background-color: rgba(240,240,240,0.2);
}
.ct-product{
display: flex;
justify-content: flex-start;
height: 100px;
padding: 8px;
.photo-box{
width: 80px;
.photo{
display: block;
width: 80px;
height: 80px;
margin: 0 auto;
}
}
.detail{
position: relative;
display: flex;
flex-direction: column;
font-size: 14px;
margin-left: 5px;
/*overflow-x: hidden;*/
.name{
display: block;
overflow: hidden;
}
.star{
color: $c1;
}
.month-sell{
color: #bbb;
}
.price{
color: #ff8200;
}
.num-box{
display: flex;
justify-content: center;
/*align-items: center;*/
position: absolute;
bottom: 4px;
left: 48px;
.num{
padding: 0 3px;
}
.jia,.jian{
display: flex;
justify-content: center;
align-items:center;
width: 20px;
height: 20px;
font-size: 16px;
line-height: 20px;
font-weight: 600;
border-radius: 50%;
border: 2px solid $c1;
}
.jian{
color: $c1;
background-color: #fff;
}
.jia{
color: #fff;
background-color: $c1;
}
}
}
}
}
}
</style>
18 changes: 18 additions & 0 deletions src/components/cart/CartProduct.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>

</template>

<script>
export default {
name: 'CartProduct',
data () {
return {
list: []
}
}
}
</script>

<style lang="scss" scoped>
</style>
28 changes: 28 additions & 0 deletions src/components/subcomponents/FullMask.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div class="full-mask" @click="$emit('hideCartMask')">

</div>
</template>

<script>
export default {
name: 'FullMask',
data () {
return {
list: []
}
},
}
</script>

<style lang="scss" scoped>
.full-mask{
position: fixed;
top: 0;
left: 0;
z-index: 10000;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,.4);
}
</style>
8 changes: 6 additions & 2 deletions src/components/tabbar/IndexContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<van-tab title="最新">
<List :type="'new'" :key="2"></List>
</van-tab>
<van-tab title="社圈">内容 3</van-tab>
<van-tab title="能值">内容 4</van-tab>
<!--<van-tab title="社圈">内容 3</van-tab>-->
<!--<van-tab title="能值">内容 4</van-tab>-->
</van-tabs>


Expand Down Expand Up @@ -95,6 +95,10 @@
color: #9b9b9b;
padding: 0;
background-color: transparent;
&.van-tab--active{
font-weight: 600;
color: $c1;
}
}
}
Expand Down
Loading

0 comments on commit 9f9b725

Please sign in to comment.