Skip to content

Commit 4ab73e5

Browse files
committed
优化shop页面,让menu能随着食品的滑动能对应
1 parent a7f2356 commit 4ab73e5

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/page/shop/shop.vue

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#arrow-left"></use>
2828
</svg>
2929
</footer>
30-
30+
3131
</section>
3232
</header>
3333
<transition name="fade">
@@ -55,19 +55,19 @@
5555
<line x1="22" y1="22" x2="38" y2="38" style="stroke:#999;stroke-width:2"/>
5656
</svg>
5757
</section>
58-
</transition>
58+
</transition>
5959
<section class="change_show_type" ref="chooseType">
6060
<div>
6161
<span :class='{activity_show: changeShowType =="food"}' @click="changeShowType='food'">商品</span>
6262
</div>
6363
<div>
64-
<span :class='{activity_show: changeShowType =="rating"}' @click="changeShowType='rating'">评价</span>
64+
<span :class='{activity_show: changeShowType =="rating"}' @click="changeShowType='rating'">评价</span>
6565
</div>
6666
</section>
6767
<transition name="fade-choose">
6868
<section v-show="changeShowType =='food'" class="food_container">
6969
<section class="menu_container">
70-
<section class="menu_left" id="wrapper_menu">
70+
<section class="menu_left" id="wrapper_menu" ref="wrapperMenu">
7171
<ul>
7272
<li v-for="(item,index) in menuList" :key="index" class="menu_left_li" :class="{activity_menu: index == menuIndex}" @click="chooseMenu(index)">
7373
<img :src="getImgPath(item.icon_url)" v-if="item.icon_url">
@@ -103,7 +103,7 @@
103103
<p :style="{color: attribute.icon_name == '新'? '#fff' : '#' + attribute.icon_color}">{{attribute.icon_name == '新'? '新品':attribute.icon_name}}</p>
104104
</li>
105105
</ul>
106-
106+
107107
</h3>
108108
<p class="food_description_content">{{foods.description}}</p>
109109
<p class="food_description_sale_rating">
@@ -195,7 +195,7 @@
195195
<section class="rating_container" id="ratingContainer" v-show="changeShowType =='rating'">
196196
<section v-load-more="loaderMoreRating" type="2">
197197
<section>
198-
198+
199199
<header class="rating_header">
200200
<section class="rating_header_left">
201201
<p>{{shopDetailData.rating}}</p>
@@ -215,7 +215,7 @@
215215
</p>
216216
<p>
217217
<span>送达时间</span>
218-
<span class="delivery_time">{{shopDetailData.order_lead_time}}分钟</span>
218+
<span class="delivery_time">{{shopDetailData.order_lead_time}}分钟</span>
219219
</p>
220220
</section>
221221
</header>
@@ -248,7 +248,7 @@
248248
</ul>
249249
</section>
250250
</li>
251-
</ul>
251+
</ul>
252252
</section>
253253
</section>
254254
</section>
@@ -288,7 +288,7 @@
288288
<transition name="fade">
289289
<p class="show_delete_tip" v-if="showDeleteTip">多规格商品只能去购物车删除哦</p>
290290
</transition>
291-
<transition
291+
<transition
292292
appear
293293
@after-appear = 'afterEnter'
294294
@before-appear="beforeEnter"
@@ -375,19 +375,19 @@
375375
...mapState([
376376
'latitude','longitude','cartList'
377377
]),
378-
promotionInfo: function (){
378+
promotionInfo: function (){
379379
return this.shopDetailData.promotion_info || '欢迎光临,用餐高峰期请提前下单,谢谢。'
380380
},
381381
//配送费
382-
deliveryFee: function () {
382+
deliveryFee: function () {
383383
if (this.shopDetailData) {
384384
return this.shopDetailData.float_delivery_fee;
385385
}else{
386386
return null;
387387
}
388388
},
389389
//还差多少元起送,为负数时显示去结算按钮
390-
minimumOrderAmount: function () {
390+
minimumOrderAmount: function () {
391391
if (this.shopDetailData) {
392392
return this.shopDetailData.float_minimum_order_amount - this.totalPrice;
393393
}else{
@@ -448,24 +448,28 @@
448448
listenScroll(element){
449449
let oldScrollTop;
450450
let requestFram;
451-
this.foodScroll = new BScroll(element, {
451+
this.foodScroll = new BScroll(element, {
452452
probeType: 3,
453453
deceleration: 0.001,
454454
bounce: false,
455455
swipeTime: 2000,
456456
click: true,
457-
});
458-
457+
});
458+
459459
this.wrapperMenu = new BScroll('#wrapper_menu', {
460460
click: true,
461461
});
462462
463463
this.foodScroll.on('scroll', (pos) => {
464-
this.shopListTop.forEach((item, index) => {
464+
this.shopListTop.forEach((item, index) => {
465465
if (this.menuIndexChange && Math.abs(Math.round(pos.y)) >= item) {
466466
this.menuIndex = index;
467467
}
468468
})
469+
let wrapMenuHeight = this.$refs.wrapperMenu.clientHeight;
470+
let menuList=this.$refs.wrapperMenu.querySelectorAll('.activity_menu');
471+
let el = menuList[0];
472+
this.wrapperMenu.scrollToElement(el, 800);
469473
})
470474
},
471475
//控制活动详情页的显示隐藏
@@ -503,7 +507,7 @@
503507
initCategoryNum(){
504508
let newArr = [];
505509
let cartFoodNum = 0;
506-
this.totalPrice = 0;
510+
this.totalPrice = 0;
507511
this.cartFoodList = [];
508512
this.menuList.forEach((item, index) => {
509513
if (this.shopCart&&this.shopCart[item.foods[0].category_id]) {
@@ -728,7 +732,7 @@
728732
left: 0;
729733
height: 100%;
730734
}
731-
735+
732736
.shop_detail_header{
733737
overflow: hidden;
734738
position: relative;
@@ -868,7 +872,7 @@
868872
@include cl;
869873
}
870874
}
871-
875+
872876
.food_container{
873877
display: flex;
874878
flex: 1;
@@ -878,6 +882,7 @@
878882
display: flex;
879883
flex: 1;
880884
overflow-y: hidden;
885+
position: relative;
881886
.menu_left{
882887
background-color: #f8f8f8;
883888
width: 3.8rem;
@@ -979,7 +984,7 @@
979984
padding: .6rem .4rem;
980985
border-bottom: 1px solid #f8f8f8;
981986
position: relative;
982-
overflow: hidden;
987+
overflow: hidden;
983988
.menu_detail_link{
984989
display:flex;
985990
.menu_food_img{
@@ -1139,7 +1144,7 @@
11391144
margin-bottom: .1rem;
11401145
}
11411146
div:nth-of-type(2){
1142-
font-size: .4rem;
1147+
font-size: .4rem;
11431148
}
11441149
}
11451150
}
@@ -1509,7 +1514,7 @@
15091514
position: fixed;
15101515
bottom: 30px;
15111516
left: 30px;
1512-
1517+
15131518
svg{
15141519
@include wh(.9rem, .9rem);
15151520
fill: #3190e8;

0 commit comments

Comments
 (0)