menu.vue 13 KB

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