menu.vue 12 KB

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