menu.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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-4 text-overflow-ellipsis fs-34 fw-600">[畅销款]奥尔1良烤肉 牛油拌饭[畅销款]奥尔1良烤肉 牛油拌饭[畅销款]奥尔1良烤肉 牛油拌饭[畅销款]奥尔1良烤肉 牛油拌饭</view>
  20. <view class="mb-20 fw-400 fc-9 fs-24">月销196</view>
  21. <view class="flex-justify-space align-items-flex-end">
  22. <view class="">
  23. <span class="fs-24 fw-400 fc-FB3D03">¥</span>
  24. <span class="fs-40 fw-b fc-FB3D03">3.9</span>
  25. <span class="fs-24 fc-9 fw-400 text-line-through">¥12</span>
  26. </view>
  27. <view class="display-flex align-items-center" v-if="info.spec != 1">
  28. <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>
  29. <view v-show="info.num > 0" class="right-only-right-2 text-align-center fs-28 fw-400">{{info.num}}</view>
  30. <view class="right-only-right-add fw-500 text-align-center fs-36 fc-f" @click="addred(2,i,k,item)">+</view>
  31. </view>
  32. <view v-else class="right-only-right text-align-center fw-600 fs-28 fc-f" @click="addred(3,i,k,item)">选规格</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. <uni-popup ref="popupGG" type="bottom">
  40. <view class="gg-box flex-index-css">
  41. <view class="flex-justify-space box-border-box p-32">
  42. <view class="fs-32 fw-500 fc-0">商品详情规格</view>
  43. <view class="" @click="addred(4)">
  44. <uni-icons type="closeempty" size="20" ></uni-icons>
  45. </view>
  46. </view>
  47. <view class="goods-info flex-justify-space mb-32 box-border-box plr-32">
  48. <image src="@/static/img/my/bg.png" mode="scaleToFill"></image>
  49. <view class="flex-1">
  50. <view style="width: 446rpx;" class="fw-600 fs-34 text-overflow-ellipsis-one">[畅销款]奥尔1良烤肉牛油拌饭</view>
  51. <view class="fw-400 fc-9 fs-24">月销196</view>
  52. </view>
  53. </view>
  54. <view class="scroll-view-css box-border-box plr-32">
  55. <view class="" v-for="(item,i) in popData.specList" :key="i">
  56. <view class="fs-32 fw-500 fc-0 mb-32">{{item.specName}}</view>
  57. <view class="flex-wrap-wrap">
  58. <view class="spec-item text-align-center fs-28"
  59. :class="info.isSelect?'s-item':'n-item'"
  60. v-for="(info,k) in item.list" :key="k" @click="select(i,k,item,info)">
  61. {{info.name}}
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="pop-buttom box-border-box plr-32">
  67. <view class="flex-justify-space mb-28">
  68. <view class="pop-buttom-left">
  69. <view class="">
  70. <span class="fw-600 fs-32 fc-ED301D">¥</span>
  71. <span class="fw-600 fs-48 fc-ED301D">19.26</span>
  72. </view>
  73. <view class="">
  74. <span class="fw-400 fs-24 fc-9">已选规格:</span>
  75. <span class="fw-400 fs-24">不辣</span>
  76. </view>
  77. </view>
  78. <view class="display-flex align-items-center">
  79. <view class="right-only-right-red fw-500 text-align-center fs-36 fc-f">-</view>
  80. <view class="right-only-right-2 text-align-center fs-28 fw-400">1</view>
  81. <view class="right-only-right-add fw-500 text-align-center fs-36 fc-f">+</view>
  82. </view>
  83. </view>
  84. <view class="pop-buttom-2 text-align-center fs-32 fw-600 fc-f">选好了</view>
  85. </view>
  86. </view>
  87. </uni-popup>
  88. </view>
  89. </template>
  90. <script>
  91. import tools from "@/service/tools";
  92. export default {
  93. name:'menu-box',
  94. data(){
  95. return{
  96. idMark:'',//滚动自适应参数
  97. type:1,//分类标识
  98. typeList:[],
  99. menuList:[],
  100. popData:{
  101. spec_name:'',
  102. spec_ids:'',
  103. spec_list:[],
  104. specList:[
  105. {
  106. specName:'口味',
  107. specType:1,
  108. list:[
  109. {name:'辣1',id:1,isSelect:false},{name:'辣2',id:2,isSelect:false},{name:'辣3',id:3,isSelect:false},{name:'辣4',id:4,isSelect:false},
  110. ]
  111. },
  112. {
  113. specName:'大小',
  114. specType:2,
  115. list:[
  116. {name:'大1',id:5,isSelect:false},{name:'大2',id:6,isSelect:false},{name:'大3',id:7,isSelect:false},{name:'大4',id:8,isSelect:false},
  117. ]
  118. },
  119. {
  120. specName:'加料',
  121. specType:3,
  122. list:[
  123. {name:'加1',id:9,isSelect:false},{name:'加2',id:10,isSelect:false},{name:'加3',id:11,isSelect:false},{name:'加4',id:12,isSelect:false},
  124. ]
  125. },
  126. ]
  127. },
  128. }
  129. },
  130. mounted() {
  131. this.getTypeList();
  132. },
  133. methods:{
  134. getTypeList(){
  135. this.typeList = [
  136. {
  137. "category_id": 1,
  138. "name": "爆品推荐",
  139. "type": 1,
  140. },
  141. {
  142. "category_id": 2,
  143. "name": "必点口味",
  144. "type": 2
  145. },
  146. ]
  147. this.type = this.typeList[0].type;
  148. this.idMark = 'scroll'+ this.type;
  149. this.typeList.forEach((v)=>{
  150. v.num = 0
  151. })
  152. this.menuList = [
  153. {
  154. name:'分类1',
  155. type:1,
  156. list:[
  157. {name:1,num:0,spec:1},{name:2,num:0},{name:3,num:0},{name:4,num:0},
  158. ]
  159. },
  160. {
  161. name:'分类2',
  162. type:2,
  163. list:[
  164. {name:1,num:0},{name:2,num:0,spec:1},{name:3,num:0},{name:4,num:0},
  165. ]
  166. },
  167. ]
  168. },
  169. selectType(item){
  170. if(this.type != item.type){
  171. this.type = item.type;
  172. this.idMark = 'scroll'+ item.type
  173. }
  174. },
  175. menuScroll(){
  176. let _this = this;
  177. let query = uni.createSelectorQuery().in(this);
  178. query.selectAll(".menu-box-only").boundingClientRect(data=>{
  179. data.forEach((v)=>{
  180. if(v.top < 329&&v.top>0){
  181. _this.idMark = v.id;
  182. let arr = v.id.split('scroll');
  183. _this.type = Number(arr[1]);
  184. }
  185. })
  186. }).exec();
  187. },
  188. addred(type,i,k,item){
  189. if(type === 1){
  190. // 减
  191. this.menuList[i].list[k].num -= 1;
  192. this.setSub(item);
  193. }else if(type === 2){
  194. // 加
  195. this.menuList[i].list[k].num += 1;
  196. this.setSub(item);
  197. }else if(type === 3){
  198. // 选规格
  199. this.$refs.popupGG.open();
  200. }else{
  201. this.$refs.popupGG.close();
  202. }
  203. },
  204. setSub(item){
  205. let num = 0;
  206. item.list.forEach((n)=>{
  207. num += n.num
  208. })
  209. this.typeList.forEach((v)=>{
  210. if(v.type == item.type){
  211. v.num = num
  212. }
  213. })
  214. },
  215. // -------弹窗选择规格-----------
  216. select(i,k,item,info){
  217. if(!info.isSelect){
  218. item.list.forEach((v)=>{
  219. v.isSelect = false;
  220. })
  221. info.isSelect = true;
  222. item.list.forEach(v=>{
  223. this.popData.spec_list.forEach((n,i)=>{
  224. if(v.id == n){
  225. this.popData.spec_list.splice(i, 1)
  226. }
  227. })
  228. })
  229. this.popData.spec_list.push(info.id);
  230. }else{
  231. info.isSelect = false;
  232. let index = this.popData.spec_list.indexOf(info.id)
  233. this.popData.spec_list.splice(index, 1)
  234. }
  235. this.spec_ids = this.popData.spec_list.join('_')
  236. },
  237. },
  238. }
  239. </script>
  240. <style scoped lang="scss">
  241. .menu-box{
  242. height: 100%;
  243. .menu-box-left{
  244. width: 176rpx;
  245. height: 100%;
  246. background-color: #F7F8FA;
  247. border-radius: 0rpx 20rpx 0 0rpx;
  248. .menu-type-list-f{
  249. width: 176rpx;
  250. height: 100%;
  251. .menu-type-list{
  252. width: 176rpx;
  253. min-height: 10rpx;
  254. box-sizing: border-box;
  255. padding: 14rpx 32rpx;
  256. position: relative;
  257. .menu-type-num{
  258. position: absolute;
  259. top: 2rpx;
  260. right: 8rpx;
  261. padding: 0 6rpx;
  262. min-width: 20rpx;
  263. height: 32rpx;
  264. text-align: center;
  265. line-height: 32rpx;
  266. background: #FB3D03;
  267. border-radius: 50%;
  268. }
  269. }
  270. }
  271. }
  272. .menu-box-right{
  273. flex: 1;
  274. height: 100%;
  275. box-sizing: border-box;
  276. padding: 0 16rpx;
  277. .menu-list{
  278. width: 100%;
  279. height: 200rpx;
  280. margin-bottom: 40rpx;
  281. image{
  282. width: 200rpx;
  283. height: 200rpx;
  284. border-radius: 12rpx;
  285. margin-right: 16rpx;
  286. }
  287. .menu-list-right{
  288. flex: 1;
  289. .right-only-right{
  290. width: 100rpx;
  291. height: 44rpx;
  292. background: linear-gradient( 117deg, #57CAFF 0%, #41ABF5 100%);
  293. border-radius: 12rpx;
  294. line-height: 44rpx;
  295. }
  296. .right-only-right-red{
  297. width: 44rpx;
  298. height: 44rpx;
  299. line-height: 40rpx;
  300. border-radius: 12rpx;
  301. border: 1rpx solid #41ABF5;
  302. color: #41ABF5;
  303. }
  304. .right-only-right-add{
  305. width: 44rpx;
  306. height: 44rpx;
  307. line-height: 40rpx;
  308. background: linear-gradient( 117deg, #57CAFF 0%, #41ABF5 100%);
  309. border-radius: 12rpx;
  310. }
  311. .right-only-right-2{
  312. min-width: 50rpx;
  313. }
  314. }
  315. }
  316. }
  317. .gg-box{
  318. width: 750rpx;
  319. height: 1208rpx;
  320. background: #FFFFFF;
  321. border-radius: 24rpx 24rpx 0rpx 0rpx;
  322. .goods-info{
  323. border-bottom: 1rpx solid #EEEEEE;
  324. image{
  325. width: 170rpx;
  326. height: 160rpx;
  327. border-radius: 8rpx;
  328. margin-right: 22rpx;
  329. margin-bottom: 32rpx;
  330. }
  331. }
  332. .pop-buttom{
  333. width: 100%;
  334. height: 250rpx;
  335. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(51,51,51,0.1);
  336. .pop-buttom-left{
  337. padding-top: 12rpx;
  338. }
  339. .pop-buttom-2{
  340. width: 100%;
  341. height: 96rpx;
  342. line-height: 96rpx;
  343. background: #41ABF5;
  344. border-radius: 200rpx
  345. }
  346. .right-only-right-red{
  347. width: 44rpx;
  348. height: 44rpx;
  349. line-height: 40rpx;
  350. border-radius: 12rpx;
  351. border: 1rpx solid #41ABF5;
  352. color: #41ABF5;
  353. }
  354. .right-only-right-add{
  355. width: 44rpx;
  356. height: 44rpx;
  357. line-height: 40rpx;
  358. background: linear-gradient( 117deg, #57CAFF 0%, #41ABF5 100%);
  359. border-radius: 12rpx;
  360. }
  361. .right-only-right-2{
  362. min-width: 50rpx;
  363. }
  364. }
  365. .spec-item{
  366. width: 210rpx;
  367. height: 66rpx;
  368. line-height: 66rpx;
  369. box-sizing: border-box;
  370. border-radius: 12rpx;
  371. margin: 0 26rpx 26rpx 0;
  372. }
  373. .spec-item:nth-child(3){
  374. margin-right: 0rpx !important;
  375. }
  376. .s-item{
  377. background-color: #ECF7FE;
  378. border: 2rpx solid #41ABF5;
  379. color: #41ABF5;
  380. }
  381. .n-item{
  382. border: 2rpx solid #EEEEEE;
  383. color: #000;
  384. }
  385. }
  386. }
  387. </style>