menu.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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, setShopIngAdd, setShopIngDel, setShopIngNumber} 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:[],
  123. },
  124. isAjax:false,
  125. operate_id: '',
  126. popData: {
  127. spec_name: '',
  128. spec_ids: '',
  129. spec_list: [],
  130. specList: [{
  131. specName: '口味',
  132. specType: 1,
  133. list: [{
  134. name: '辣1',
  135. id: 1,
  136. isSelect: false
  137. }, {
  138. name: '辣2',
  139. id: 2,
  140. isSelect: false
  141. }, {
  142. name: '辣3',
  143. id: 3,
  144. isSelect: false
  145. }, {
  146. name: '辣4',
  147. id: 4,
  148. isSelect: false
  149. }, ]
  150. },
  151. {
  152. specName: '大小',
  153. specType: 2,
  154. list: [{
  155. name: '大1',
  156. id: 5,
  157. isSelect: false
  158. }, {
  159. name: '大2',
  160. id: 6,
  161. isSelect: false
  162. }, {
  163. name: '大3',
  164. id: 7,
  165. isSelect: false
  166. }, {
  167. name: '大4',
  168. id: 8,
  169. isSelect: false
  170. }, ]
  171. },
  172. {
  173. specName: '加料',
  174. specType: 3,
  175. list: [{
  176. name: '加1',
  177. id: 9,
  178. isSelect: false
  179. }, {
  180. name: '加2',
  181. id: 10,
  182. isSelect: false
  183. }, {
  184. name: '加3',
  185. id: 11,
  186. isSelect: false
  187. }, {
  188. name: '加4',
  189. id: 12,
  190. isSelect: false
  191. }, ]
  192. },
  193. ]
  194. },
  195. }
  196. },
  197. watch:{
  198. 'shop_id':function () {
  199. this.getShopGoods();
  200. }
  201. },
  202. mounted() {
  203. this.operate_id = uni.getStorageSync('operate_id')
  204. this.getShopGoods();
  205. this.getShopIngList(true);
  206. },
  207. methods: {
  208. setShopIngList(cartData){
  209. this.cartData=cartData
  210. this.setGoodsNum()
  211. },
  212. getShopIngList(isStart){
  213. getShopIngList({
  214. 'shop_id':this.shop_id,
  215. }).then(res=>{
  216. if(res.code===1){
  217. this.cartData=res.data
  218. this.$emit('setCartData',this.cartData)
  219. if(isStart) this.setGoodsNum()
  220. }
  221. })
  222. },
  223. setGoodsNum(){
  224. this.cartData.goods_list.forEach(item=>{
  225. this.categoryData.forEach(categoryItem=>{
  226. if(categoryItem.type===item.category_id){
  227. categoryItem.list.forEach(goodsItem=>{
  228. console.log(item.goods_id,goodsItem.goods_id)
  229. if(item.goods_id===goodsItem.goods_id){
  230. goodsItem.num=item.goods_number*1
  231. }
  232. })
  233. }
  234. })
  235. })
  236. },
  237. getShopGoods(){
  238. if(this.shop_id<0 || !this.operate_id){
  239. return;
  240. }
  241. shopGoods({'shop_id':this.shop_id, operate_id: this.operate_id,}).then(res=>{
  242. if(res.code===1){
  243. this.categoryData=res.data
  244. if(this.categoryData.length>0){
  245. this.selectType(this.categoryData[0])
  246. }
  247. this.categoryData.forEach(categoryItem=>{
  248. categoryItem.list.forEach(goodsItem=>{
  249. goodsItem.payNum=0
  250. goodsItem.spec=[]
  251. })
  252. })
  253. // console.log(res)
  254. }
  255. })
  256. },
  257. selectType(item) {
  258. if (this.type != item.type) {
  259. this.type = item.type;
  260. this.idMark = 'scroll' + item.type
  261. }
  262. },
  263. menuScroll() {
  264. let _this = this;
  265. let query = uni.createSelectorQuery().in(this);
  266. query.selectAll(".menu-box-only").boundingClientRect(data => {
  267. data.forEach((v) => {
  268. if (v.top < 329 && v.top > 0) {
  269. _this.idMark = v.id;
  270. let arr = v.id.split('scroll');
  271. _this.type = Number(arr[1]);
  272. }
  273. })
  274. }).exec();
  275. },
  276. addred(type, i, k, item) {
  277. if(this.isAjax){
  278. return
  279. }
  280. this.isAjax=true
  281. if (type === 1) {
  282. // 减
  283. if(item.num>0){
  284. --item.num;
  285. this.setSub(item,type);
  286. }else {
  287. this.isAjax=false
  288. }
  289. } else if (type === 2) {
  290. // 加
  291. if(item.is_infinite===1 || item.stock>item.num){
  292. ++item.num;
  293. this.setSub(item,type);
  294. }else {
  295. this.isAjax=false
  296. }
  297. // this.menuList[i].list[k].num += 1;
  298. // this.setSub(item);
  299. } else if (type === 3) {
  300. // 选规格
  301. this.$refs.popupGG.open();
  302. } else {
  303. this.$refs.popupGG.close();
  304. }
  305. },
  306. setSub(item,type) {
  307. console.log(item)
  308. console.log(this.cartData.goods_list)
  309. let cartKey=this.cartData.goods_list.findIndex(row=>row.goods_id===item.goods_id)
  310. console.log(cartKey)
  311. console.log(type, cartKey)
  312. console.log(type===2 && cartKey<0)
  313. if(type===2 && cartKey<0){
  314. this.setShopIngAdd(item.goods_id,item.category_id,'')
  315. }else {
  316. this.setShopIngNumber(item.goods_id,item.category_id,type,'')
  317. }
  318. },
  319. setShopIngAdd(goodsId,categoryId,goodsSpecId){
  320. setShopIngAdd({
  321. 'type':1,
  322. 'goods_id':goodsId,
  323. 'shop_id':this.shop_id,
  324. 'category_id':categoryId,
  325. 'goods_spec_id':goodsSpecId,
  326. }).then(res=>{
  327. this.isAjax=false
  328. this.getShopIngList()
  329. }).catch(()=>{
  330. this.isAjax=false
  331. })
  332. },
  333. setShopIngNumber(goodsId,categoryId,operation,goodsSpecId){
  334. setShopIngNumber({
  335. 'type':1,
  336. 'goods_id':goodsId,
  337. 'shop_id':this.shop_id,
  338. 'category_id':categoryId,
  339. 'goods_spec_id':goodsSpecId,
  340. 'operation':operation===2?1:2,
  341. }).then(res=>{
  342. this.isAjax=false
  343. this.getShopIngList()
  344. }).catch(()=>{
  345. this.isAjax=false
  346. })
  347. },
  348. setShopIngDel(){
  349. },
  350. // -------弹窗选择规格-----------
  351. select(i, k, item, info) {
  352. if (!info.isSelect) {
  353. item.list.forEach((v) => {
  354. v.isSelect = false;
  355. })
  356. info.isSelect = true;
  357. item.list.forEach(v => {
  358. this.popData.spec_list.forEach((n, i) => {
  359. if (v.id == n) {
  360. this.popData.spec_list.splice(i, 1)
  361. }
  362. })
  363. })
  364. this.popData.spec_list.push(info.id);
  365. } else {
  366. info.isSelect = false;
  367. let index = this.popData.spec_list.indexOf(info.id)
  368. this.popData.spec_list.splice(index, 1)
  369. }
  370. this.spec_ids = this.popData.spec_list.join('_')
  371. },
  372. },
  373. }
  374. </script>
  375. <style scoped lang="scss">
  376. .menu-box {
  377. height: 100%;
  378. .menu-box-left {
  379. width: 160rpx;
  380. height: 100%;
  381. background-color: #F7F8FA;
  382. // border-radius: 0rpx 20rpx 0 0rpx;
  383. .menu-type-list-f {
  384. width: 160rpx;
  385. height: 100%;
  386. .menu-type-list {
  387. width: 160rpx;
  388. min-height: 108rpx;
  389. padding: 18rpx 28rpx;
  390. position: relative;
  391. .menu-type-num {
  392. position: absolute;
  393. top: 2rpx;
  394. right: 8rpx;
  395. padding: 0 6rpx;
  396. min-width: 20rpx;
  397. height: 32rpx;
  398. text-align: center;
  399. line-height: 32rpx;
  400. background: #FB3D03;
  401. border-radius: 50%;
  402. }
  403. }
  404. }
  405. }
  406. .menu-box-right {
  407. // flex: 1;
  408. width: 100%;
  409. height: 100%;
  410. padding: 16rpx;
  411. box-sizing: border-box;
  412. .menu-list {
  413. width: 100%;
  414. // height: 200rpx;
  415. margin-bottom: 40rpx;
  416. image {
  417. width: 200rpx;
  418. height: 200rpx;
  419. border-radius: 12rpx;
  420. margin-right: 16rpx;
  421. }
  422. .menu-list-right {
  423. flex: 1;
  424. .right-only-right {
  425. width: 100rpx;
  426. height: 44rpx;
  427. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  428. border-radius: 12rpx;
  429. line-height: 44rpx;
  430. }
  431. .right-only-right-red {
  432. width: 44rpx;
  433. height: 44rpx;
  434. line-height: 40rpx;
  435. border-radius: 12rpx;
  436. border: 1rpx solid #41ABF5;
  437. color: #41ABF5;
  438. }
  439. .right-only-right-add {
  440. width: 44rpx;
  441. height: 44rpx;
  442. line-height: 40rpx;
  443. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  444. border-radius: 12rpx;
  445. }
  446. .right-only-right-2 {
  447. min-width: 50rpx;
  448. }
  449. }
  450. }
  451. }
  452. .gg-box {
  453. width: 750rpx;
  454. height: 1208rpx;
  455. background: #FFFFFF;
  456. border-radius: 24rpx 24rpx 0rpx 0rpx;
  457. .goods-info {
  458. border-bottom: 1rpx solid #EEEEEE;
  459. image {
  460. width: 170rpx;
  461. height: 160rpx;
  462. border-radius: 8rpx;
  463. margin-right: 22rpx;
  464. margin-bottom: 32rpx;
  465. }
  466. }
  467. .pop-buttom {
  468. width: 100%;
  469. height: 250rpx;
  470. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(51, 51, 51, 0.1);
  471. .pop-buttom-left {
  472. padding-top: 12rpx;
  473. }
  474. .pop-buttom-2 {
  475. width: 100%;
  476. height: 96rpx;
  477. line-height: 96rpx;
  478. background: #41ABF5;
  479. border-radius: 200rpx
  480. }
  481. .right-only-right-red {
  482. width: 44rpx;
  483. height: 44rpx;
  484. line-height: 40rpx;
  485. border-radius: 12rpx;
  486. border: 1rpx solid #41ABF5;
  487. color: #41ABF5;
  488. }
  489. .right-only-right-add {
  490. width: 44rpx;
  491. height: 44rpx;
  492. line-height: 40rpx;
  493. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  494. border-radius: 12rpx;
  495. }
  496. .right-only-right-2 {
  497. min-width: 50rpx;
  498. }
  499. }
  500. .spec-item {
  501. width: 210rpx;
  502. height: 66rpx;
  503. line-height: 66rpx;
  504. box-sizing: border-box;
  505. border-radius: 12rpx;
  506. margin: 0 26rpx 26rpx 0;
  507. }
  508. .spec-item:nth-child(3) {
  509. margin-right: 0rpx !important;
  510. }
  511. .s-item {
  512. background-color: #ECF7FE;
  513. border: 2rpx solid #41ABF5;
  514. color: #41ABF5;
  515. }
  516. .n-item {
  517. border: 2rpx solid #EEEEEE;
  518. color: #000;
  519. }
  520. }
  521. }
  522. .goods-name{
  523. max-width: 310rpx;
  524. }
  525. </style>