menu.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view class="menu-box flex-justify-space">
  3. <scroll-view scroll-y="true" class="menu-box-left" :scroll-into-view="idMark" :scroll-with-animation='true'>
  4. <view class="menu-type-list-f">
  5. <view class="menu-type-list fs-28 fc-6 text-align-center" v-for="(item,i) in typeList" :key="i" @click="selectType(item)"
  6. :class="type === item.type?'bgc-BCEAFF':''" :id="'scroll'+ item.type">
  7. {{item.name}}
  8. <view class="menu-type-num fc-f" v-show="item.num > 0">{{item.num > 99?'99+':item.num}}</view>
  9. </view>
  10. </view>
  11. </scroll-view>
  12. <scroll-view scroll-y="true" :scroll-with-animation='true' :scroll-into-view="idMark" @scroll="menuScroll">
  13. <view class="menu-box-right">
  14. <view class="menu-box-only" v-for="(item,i) in menuList" :key="i" :id="'scroll'+ item.type">
  15. <view class="mb-18 fs-24">{{item.name}}</view>
  16. <view class="menu-list" v-for="(info,k) in item.list" :key="k">
  17. {{info.name}}
  18. </view>
  19. </view>
  20. </view>
  21. </scroll-view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. name:'menu-box',
  27. data(){
  28. return{
  29. idMark:'',//滚动自适应参数
  30. type:1,//分类标识
  31. typeList:[],
  32. menuList:[
  33. {
  34. name:'分类1',
  35. type:1,
  36. list:[
  37. {name:1,},{name:2,},{name:3,},{name:4,},
  38. ]
  39. },
  40. {
  41. name:'分类2',
  42. type:2,
  43. list:[
  44. {name:1,},{name:2,},{name:3,},{name:4,},
  45. ]
  46. },
  47. {
  48. name:'分类3',
  49. type:3,
  50. list:[
  51. {name:1,},{name:2,},{name:3,},{name:4,},
  52. ]
  53. },
  54. {
  55. name:'分类4',
  56. type:4,
  57. list:[
  58. {name:1,},{name:2,},{name:3,},{name:4,},
  59. ]
  60. },
  61. {
  62. name:'分类5',
  63. type:5,
  64. list:[
  65. {name:1,},{name:2,},{name:3,},{name:4,},
  66. ]
  67. },
  68. ],
  69. }
  70. },
  71. mounted() {
  72. this.getTypeList();
  73. },
  74. methods:{
  75. getTypeList(){
  76. this.typeList = [
  77. {
  78. "category_id": 1,
  79. "name": "爆品推荐爆爆品推荐爆爆品推荐爆",
  80. "type": 1,
  81. },
  82. {
  83. "category_id": 2,
  84. "name": "必点口味必点口味必点口味必点口味必点口味",
  85. "type": 2
  86. },
  87. {
  88. "category_id": 3,
  89. "name": "爆品推荐爆爆品推荐爆爆品推荐爆",
  90. "type": 3,
  91. },
  92. {
  93. "category_id": 4,
  94. "name": "必点口味必点口味必点口味必点口味必点口味",
  95. "type": 4
  96. },
  97. {
  98. "category_id": 5,
  99. "name": "必点口味必点口味必点口味必点口味必点口味",
  100. "type": 5
  101. },
  102. ]
  103. this.type = this.typeList[0].type;
  104. this.idMark = 'scroll'+ this.type;
  105. this.typeList.forEach((v)=>{
  106. v.num = 0
  107. })
  108. },
  109. selectType(item){
  110. if(this.type != item.type){
  111. this.type = item.type;
  112. this.idMark = 'scroll'+ item.type
  113. }
  114. },
  115. menuScroll(){
  116. let _this = this;
  117. let query = uni.createSelectorQuery().in(this);
  118. query.selectAll(".menu-box-only").boundingClientRect(data=>{
  119. data.forEach((v)=>{
  120. if(v.top < 297&&v.top>0){
  121. _this.idMark = v.id;
  122. let arr = v.id.split('scroll');
  123. _this.type = Number(arr[1]);
  124. }
  125. })
  126. }).exec();
  127. },
  128. },
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. .menu-box{
  133. height: 100%;
  134. .menu-box-left{
  135. width: 176rpx;
  136. height: 100%;
  137. background-color: #F7F8FA;
  138. border-radius: 0rpx 20rpx 0 0rpx;
  139. .menu-type-list-f{
  140. width: 176rpx;
  141. height: 100%;
  142. .menu-type-list{
  143. width: 176rpx;
  144. min-height: 10rpx;
  145. box-sizing: border-box;
  146. padding: 14rpx 32rpx;
  147. position: relative;
  148. .menu-type-num{
  149. position: absolute;
  150. top: 2rpx;
  151. right: 8rpx;
  152. padding: 0 6rpx;
  153. min-width: 20rpx;
  154. height: 32rpx;
  155. text-align: center;
  156. line-height: 32rpx;
  157. background: #FB3D03;
  158. border-radius: 50%;
  159. }
  160. }
  161. }
  162. }
  163. .menu-box-right{
  164. flex: 1;
  165. height: 100%;
  166. box-sizing: border-box;
  167. padding: 0 16rpx;
  168. .menu-list{
  169. width: 100%;
  170. height: 200rpx;
  171. margin-bottom: 40rpx;
  172. background-color: skyblue;
  173. }
  174. }
  175. }
  176. </style>