menu.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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-34 fw-600">{{item.name}}</view>
  16. <view class="menu-list flex-justify-space" v-for="(info,k) in item.list" :key="k">
  17. <image src="@/static/img/my/bg.png" mode="scaleToFill"></image>
  18. <view class="menu-list-right">
  19. <view class="mb-40 text-overflow-ellipsis fs-34 fw-600">[畅销款]奥尔1良烤肉 牛油拌饭[畅销款]奥尔1良烤肉 牛油拌饭[畅销款]奥尔1良烤肉 牛油拌饭[畅销款]奥尔1良烤肉 牛油拌饭</view>
  20. <view class="flex-justify-space align-items-flex-end">
  21. <view class="">
  22. <span class="fs-24 fw-400 fc-FB3D03">¥</span>
  23. <span class="fs-40 fw-b fc-FB3D03">3.9</span>
  24. <span class="fs-24 fc-9 fw-400 text-line-through">¥12</span>
  25. </view>
  26. <view class="display-flex align-items-center">
  27. <view v-show="info.num > 0" class="right-only-right-red fw-500 text-align-center fs-36 fc-f" @click="addred(1,i,k,item)">-</view>
  28. <view v-show="info.num > 0" class="right-only-right-2 text-align-center fs-28 fw-400">{{info.num}}</view>
  29. <view class="right-only-right-add fw-500 text-align-center fs-36 fc-f" @click="addred(2,i,k,item)">+</view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. </view>
  38. </template>
  39. <script>
  40. import tools from "@/service/tools";
  41. export default {
  42. name:'menu-box',
  43. data(){
  44. return{
  45. idMark:'',//滚动自适应参数
  46. type:1,//分类标识
  47. typeList:[],
  48. menuList:[],
  49. }
  50. },
  51. mounted() {
  52. this.getTypeList();
  53. },
  54. methods:{
  55. getTypeList(){
  56. this.typeList = [
  57. {
  58. "category_id": 1,
  59. "name": "爆品推荐",
  60. "type": 1,
  61. },
  62. {
  63. "category_id": 2,
  64. "name": "必点口味",
  65. "type": 2
  66. },
  67. ]
  68. this.type = this.typeList[0].type;
  69. this.idMark = 'scroll'+ this.type;
  70. this.typeList.forEach((v)=>{
  71. v.num = 0
  72. })
  73. this.menuList = [
  74. {
  75. name:'分类1',
  76. type:1,
  77. list:[
  78. {name:1,num:0,spec:1},{name:2,num:0},{name:3,num:0},{name:4,num:0},
  79. ]
  80. },
  81. {
  82. name:'分类2',
  83. type:2,
  84. list:[
  85. {name:1,num:0},{name:2,num:0,spec:1},{name:3,num:0},{name:4,num:0},
  86. ]
  87. },
  88. ]
  89. },
  90. selectType(item){
  91. if(this.type != item.type){
  92. this.type = item.type;
  93. this.idMark = 'scroll'+ item.type
  94. }
  95. },
  96. menuScroll(){
  97. let _this = this;
  98. let query = uni.createSelectorQuery().in(this);
  99. query.selectAll(".menu-box-only").boundingClientRect(data=>{
  100. data.forEach((v)=>{
  101. if(v.top < 329&&v.top>0){
  102. _this.idMark = v.id;
  103. let arr = v.id.split('scroll');
  104. _this.type = Number(arr[1]);
  105. }
  106. })
  107. }).exec();
  108. },
  109. addred(type,i,k,item){
  110. if(type === 1){
  111. // 减
  112. this.menuList[i].list[k].num -= 1;
  113. this.setSub(item);
  114. }else if(type === 2){
  115. // 加
  116. this.menuList[i].list[k].num += 1;
  117. this.setSub(item);
  118. }
  119. },
  120. setSub(item){
  121. let num = 0;
  122. item.list.forEach((n)=>{
  123. num += n.num
  124. })
  125. this.typeList.forEach((v)=>{
  126. if(v.type == item.type){
  127. v.num = num
  128. }
  129. })
  130. },
  131. },
  132. }
  133. </script>
  134. <style scoped lang="scss">
  135. .menu-box{
  136. height: 100%;
  137. .menu-box-left{
  138. width: 176rpx;
  139. height: 100%;
  140. background-color: #F7F8FA;
  141. border-radius: 0rpx 20rpx 0 0rpx;
  142. .menu-type-list-f{
  143. width: 176rpx;
  144. height: 100%;
  145. .menu-type-list{
  146. width: 176rpx;
  147. min-height: 10rpx;
  148. box-sizing: border-box;
  149. padding: 14rpx 32rpx;
  150. position: relative;
  151. .menu-type-num{
  152. position: absolute;
  153. top: 2rpx;
  154. right: 8rpx;
  155. padding: 0 6rpx;
  156. min-width: 20rpx;
  157. height: 32rpx;
  158. text-align: center;
  159. line-height: 32rpx;
  160. background: #FB3D03;
  161. border-radius: 50%;
  162. }
  163. }
  164. }
  165. }
  166. .menu-box-right{
  167. flex: 1;
  168. height: 100%;
  169. box-sizing: border-box;
  170. padding: 0 16rpx;
  171. .menu-list{
  172. width: 100%;
  173. height: 200rpx;
  174. margin-bottom: 40rpx;
  175. image{
  176. width: 200rpx;
  177. height: 200rpx;
  178. border-radius: 12rpx;
  179. margin-right: 16rpx;
  180. }
  181. .menu-list-right{
  182. flex: 1;
  183. .right-only-right{
  184. width: 100rpx;
  185. height: 44rpx;
  186. background: linear-gradient( 117deg, #57CAFF 0%, #41ABF5 100%);
  187. border-radius: 12rpx;
  188. line-height: 44rpx;
  189. }
  190. .right-only-right-red{
  191. width: 44rpx;
  192. height: 44rpx;
  193. line-height: 40rpx;
  194. border-radius: 12rpx;
  195. border: 1rpx solid #41ABF5;
  196. color: #41ABF5;
  197. }
  198. .right-only-right-add{
  199. width: 44rpx;
  200. height: 44rpx;
  201. line-height: 40rpx;
  202. background: linear-gradient( 117deg, #57CAFF 0%, #41ABF5 100%);
  203. border-radius: 12rpx;
  204. }
  205. .right-only-right-2{
  206. min-width: 50rpx;
  207. }
  208. }
  209. }
  210. }
  211. }
  212. </style>